buster/web/src/components/ui/list/BusterList/BusterListHeader.tsx

76 lines
2.2 KiB
TypeScript
Raw Normal View History

2025-01-11 04:31:08 +08:00
import React from 'react';
import { BusterListColumn } from './interfaces';
import { CheckboxColumn } from './CheckboxColumn';
2025-02-20 11:05:30 +08:00
import { Text } from '@/components/ui';
import { cn } from '@/lib/classMerge';
2025-01-11 04:31:08 +08:00
import { HEIGHT_OF_HEADER } from './config';
export const BusterListHeader: React.FC<{
columns: BusterListColumn[];
onGlobalSelectChange?: (v: boolean) => void;
globalCheckStatus?: 'checked' | 'unchecked' | 'indeterminate';
showSelectAll?: boolean;
rowsLength: number;
rowClassName: string;
2025-01-11 04:31:08 +08:00
}> = React.memo(
({
columns,
rowClassName,
showSelectAll = true,
onGlobalSelectChange,
globalCheckStatus,
rowsLength
}) => {
2025-01-11 04:31:08 +08:00
const showCheckboxColumn = !!onGlobalSelectChange;
const showGlobalCheckbox =
globalCheckStatus === 'indeterminate' || globalCheckStatus === 'checked';
return (
<div
className={cn(
'group border-border flex items-center justify-start border-b pr-6',
{
'pl-3.5': !onGlobalSelectChange
},
rowClassName
)}
style={{
height: `${HEIGHT_OF_HEADER}px`,
minHeight: `${HEIGHT_OF_HEADER}px`
}}>
2025-01-11 04:31:08 +08:00
{showCheckboxColumn && (
<CheckboxColumn
checkStatus={globalCheckStatus}
onChange={onGlobalSelectChange}
className={cn({
2025-01-11 04:31:08 +08:00
'opacity-100': showGlobalCheckbox,
2025-02-19 04:23:44 +08:00
'invisible!': rowsLength === 0,
'pointer-events-none invisible!': !showSelectAll
2025-01-11 04:31:08 +08:00
})}
/>
)}
{columns.map((column, index) => (
<div
className="header-cell flex h-full items-center p-0"
2025-01-11 04:31:08 +08:00
key={column.dataIndex}
style={{
width: column.width || '100%',
2025-02-19 11:34:00 +08:00
flex: column.width ? 'none' : 1,
paddingLeft: showCheckboxColumn ? undefined : '0px'
2025-01-11 04:31:08 +08:00
}}>
{column.headerRender ? (
column.headerRender(column.title)
) : (
<Text size="sm" type="secondary" ellipsis>
{column.title}
</Text>
)}
</div>
))}
</div>
);
}
);
BusterListHeader.displayName = 'BusterListHeader';