@trail-ui/react
Version:
68 lines (65 loc) • 2.67 kB
TypeScript
import * as react_jsx_runtime from 'react/jsx-runtime';
import react__default from 'react';
import { SortDirection } from '@tanstack/react-table';
interface HeadersData<DataType> {
id: string;
accessorKey: keyof DataType | '';
label: string;
isSortable?: boolean;
width?: number | string;
columnType?: 'th' | 'td';
headerRenderFn?: () => react__default.ReactNode;
cellRenderFn?: (data: DataType) => react__default.ReactNode;
}
type NormalRow<DataType> = DataType;
type GroupedRow<DataType> = {
groupId: string;
groupName: string;
items: NormalRow<DataType>[];
};
interface BaseProps<DataType, IdType> {
tableName: string;
isLoading: boolean;
headers: HeadersData<DataType>[];
maxHeight?: string;
selection?: {
selectedIds: Set<IdType>;
retainSelectionAccrossPages: boolean;
setSelectedIds: react__default.Dispatch<react__default.SetStateAction<Set<IdType>>>;
idSelector: (data: DataType) => IdType;
checkBoxLabel?: (data: DataType) => string;
hideSelectAll?: boolean;
isRowSelectionDisabled?: (data: DataType) => boolean;
onSelectAll?: () => void;
};
sort?: {
sortBy: string;
sortDirection: false | SortDirection;
onSortClick: (sortby: string, sortDirection: false | SortDirection) => void;
};
}
interface NormalTableProps<DataType, IdType> extends BaseProps<DataType, IdType> {
tableType: 'normal';
data: NormalRow<DataType>[];
}
interface GroupedTableProps<DataType, IdType> extends BaseProps<DataType, IdType> {
tableType: 'grouped';
data: GroupedRow<DataType>[];
}
declare const sortOptions: {
asc: react_jsx_runtime.JSX.Element;
desc: react_jsx_runtime.JSX.Element;
};
declare const sortOrder: readonly [false, "asc", "desc"];
interface SelectAllCheckboxProps<DataType, IdType> {
tableName: string;
data: DataType[];
selectedIds: Set<IdType>;
onToggle: (select: boolean) => void;
idSelector: (data: DataType) => IdType;
selectionCheckFn?: (data: DataType) => boolean;
}
declare const SelectAllCheckbox: <DataType, IdType>(props: SelectAllCheckboxProps<DataType, IdType>) => react__default.ReactElement;
type TableProps<DataType, IdType extends string | number = string> = NormalTableProps<DataType, IdType> | GroupedTableProps<DataType, IdType>;
declare function CustomTable<DataType, IdType extends string | number = string>(props: TableProps<DataType, IdType>): react_jsx_runtime.JSX.Element;
export { GroupedRow, GroupedTableProps, HeadersData, NormalRow, NormalTableProps, SelectAllCheckbox, CustomTable as default, sortOptions, sortOrder };