types.d.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /// <reference types="react" />
  2. import { Alignment, Direction, Media } from './constants';
  3. import { CSSObject } from 'styled-components';
  4. export declare enum SortOrder {
  5. ASC = "asc",
  6. DESC = "desc"
  7. }
  8. export type Primitive = string | number | boolean | bigint;
  9. export type ColumnSortFunction<T> = (a: T, b: T) => number;
  10. export type ExpandRowToggled<T> = (expanded: boolean, row: T) => void;
  11. export type Format<T> = (row: T, rowIndex: number) => React.ReactNode;
  12. export type RowState<T> = ((row: T) => boolean) | null;
  13. export type Selector<T> = (row: T, rowIndex?: number) => Primitive;
  14. export type SortFunction<T> = (rows: T[], field: Selector<T>, sortDirection: SortOrder) => T[];
  15. export type TableRow = Record<string, unknown>;
  16. export type ComponentProps = Record<string, unknown>;
  17. export type ExpanderComponentProps<T> = {
  18. data: T;
  19. };
  20. export type ExpandableRowsComponent<T> = React.ComponentType<ExpanderComponentProps<T>>;
  21. export type PaginationChangePage = (page: number, totalRows: number) => void;
  22. export type PaginationChangeRowsPerPage = (currentRowsPerPage: number, currentPage: number) => void;
  23. export type PaginationComponentProps = {
  24. rowsPerPage: number;
  25. rowCount: number;
  26. currentPage: number;
  27. onChangePage: PaginationChangePage;
  28. onChangeRowsPerPage: PaginationChangeRowsPerPage;
  29. };
  30. export type PaginationComponent = React.ComponentType<PaginationComponentProps>;
  31. export type TableProps<T> = {
  32. actions?: React.ReactNode | React.ReactNode[];
  33. className?: string;
  34. clearSelectedRows?: boolean;
  35. columns: TableColumn<T>[];
  36. conditionalRowStyles?: ConditionalStyles<T>[];
  37. contextActions?: React.ReactNode | React.ReactNode[];
  38. contextComponent?: React.ReactNode;
  39. contextMessage?: ContextMessage;
  40. customStyles?: TableStyles;
  41. data: T[];
  42. defaultSortAsc?: boolean;
  43. defaultSortFieldId?: string | number | null | undefined;
  44. dense?: boolean;
  45. direction?: Direction;
  46. disabled?: boolean;
  47. expandableIcon?: ExpandableIcon;
  48. expandableInheritConditionalStyles?: boolean;
  49. expandableRowDisabled?: RowState<T>;
  50. expandableRowExpanded?: RowState<T>;
  51. expandableRows?: boolean;
  52. expandableRowsComponent?: ExpandableRowsComponent<T>;
  53. expandableRowsComponentProps?: ComponentProps;
  54. expandableRowsHideExpander?: boolean;
  55. expandOnRowClicked?: boolean;
  56. expandOnRowDoubleClicked?: boolean;
  57. fixedHeader?: boolean;
  58. fixedHeaderScrollHeight?: string;
  59. highlightOnHover?: boolean;
  60. keyField?: string;
  61. noContextMenu?: boolean;
  62. noDataComponent?: React.ReactNode;
  63. noHeader?: boolean;
  64. noTableHead?: boolean;
  65. onChangePage?: PaginationChangePage;
  66. onChangeRowsPerPage?: PaginationChangeRowsPerPage;
  67. onRowClicked?: (row: T, e: React.MouseEvent) => void;
  68. onRowDoubleClicked?: (row: T, e: React.MouseEvent) => void;
  69. onRowMouseEnter?: (row: T, e: React.MouseEvent) => void;
  70. onRowMouseLeave?: (row: T, e: React.MouseEvent) => void;
  71. onRowExpandToggled?: ExpandRowToggled<T>;
  72. onSelectedRowsChange?: (selected: {
  73. allSelected: boolean;
  74. selectedCount: number;
  75. selectedRows: T[];
  76. }) => void;
  77. onSort?: (selectedColumn: TableColumn<T>, sortDirection: SortOrder, sortedRows: T[]) => void;
  78. onColumnOrderChange?: (nextOrder: TableColumn<T>[]) => void;
  79. pagination?: boolean;
  80. paginationComponent?: PaginationComponent;
  81. paginationComponentOptions?: PaginationOptions;
  82. paginationDefaultPage?: number;
  83. paginationIconFirstPage?: React.ReactNode;
  84. paginationIconLastPage?: React.ReactNode;
  85. paginationIconNext?: React.ReactNode;
  86. paginationIconPrevious?: React.ReactNode;
  87. paginationPerPage?: number;
  88. paginationResetDefaultPage?: boolean;
  89. paginationRowsPerPageOptions?: number[];
  90. paginationServer?: boolean;
  91. paginationServerOptions?: PaginationServerOptions;
  92. paginationTotalRows?: number;
  93. persistTableHead?: boolean;
  94. pointerOnHover?: boolean;
  95. progressComponent?: React.ReactNode;
  96. progressPending?: boolean;
  97. responsive?: boolean;
  98. selectableRowDisabled?: RowState<T>;
  99. selectableRows?: boolean;
  100. selectableRowsComponent?: 'input' | React.ReactNode;
  101. selectableRowsComponentProps?: ComponentProps;
  102. selectableRowSelected?: RowState<T>;
  103. selectableRowsHighlight?: boolean;
  104. selectableRowsNoSelectAll?: boolean;
  105. selectableRowsVisibleOnly?: boolean;
  106. selectableRowsSingle?: boolean;
  107. sortFunction?: SortFunction<T> | null;
  108. sortIcon?: React.ReactNode;
  109. sortServer?: boolean;
  110. striped?: boolean;
  111. style?: CSSObject;
  112. subHeader?: React.ReactNode | React.ReactNode[];
  113. subHeaderAlign?: Alignment;
  114. subHeaderComponent?: React.ReactNode | React.ReactNode[];
  115. subHeaderWrap?: boolean;
  116. theme?: Themes;
  117. /**
  118. * Shows and displays a header with a title
  119. * */
  120. title?: string | React.ReactNode;
  121. };
  122. export type TableColumnBase = {
  123. allowOverflow?: boolean;
  124. button?: boolean;
  125. center?: boolean;
  126. compact?: boolean;
  127. reorder?: boolean;
  128. grow?: number;
  129. hide?: number | ((value: number) => CSSObject) | Media;
  130. id?: string | number;
  131. ignoreRowClick?: boolean;
  132. maxWidth?: string;
  133. minWidth?: string;
  134. name?: string | number | React.ReactNode;
  135. omit?: boolean;
  136. right?: boolean;
  137. sortable?: boolean;
  138. style?: CSSObject;
  139. width?: string;
  140. wrap?: boolean;
  141. };
  142. export interface TableColumn<T> extends TableColumnBase {
  143. name?: string | number | React.ReactNode;
  144. sortField?: string;
  145. cell?: (row: T, rowIndex: number, column: TableColumn<T>, id: string | number) => React.ReactNode;
  146. conditionalCellStyles?: ConditionalStyles<T>[];
  147. format?: Format<T> | undefined;
  148. selector?: Selector<T>;
  149. sortFunction?: ColumnSortFunction<T>;
  150. }
  151. export interface ConditionalStyles<T> {
  152. when: (row: T) => boolean;
  153. style?: CSSObject | ((row: T) => CSSObject);
  154. classNames?: string[];
  155. }
  156. export interface TableStyles {
  157. table?: {
  158. style: CSSObject;
  159. };
  160. tableWrapper?: {
  161. style: CSSObject;
  162. };
  163. responsiveWrapper?: {
  164. style: CSSObject;
  165. };
  166. header?: {
  167. style: CSSObject;
  168. };
  169. subHeader?: {
  170. style: CSSObject;
  171. };
  172. head?: {
  173. style: CSSObject;
  174. };
  175. headRow?: {
  176. style?: CSSObject;
  177. denseStyle?: CSSObject;
  178. };
  179. headCells?: {
  180. style?: CSSObject;
  181. draggingStyle?: CSSObject;
  182. };
  183. contextMenu?: {
  184. style?: CSSObject;
  185. activeStyle?: CSSObject;
  186. };
  187. cells?: {
  188. style: CSSObject;
  189. draggingStyle?: CSSObject;
  190. };
  191. rows?: {
  192. style?: CSSObject;
  193. selectedHighlightStyle?: CSSObject;
  194. denseStyle?: CSSObject;
  195. highlightOnHoverStyle?: CSSObject;
  196. stripedStyle?: CSSObject;
  197. };
  198. expanderRow?: {
  199. style: CSSObject;
  200. };
  201. expanderCell?: {
  202. style: CSSObject;
  203. };
  204. expanderButton?: {
  205. style: CSSObject;
  206. };
  207. pagination?: {
  208. style?: CSSObject;
  209. pageButtonsStyle?: CSSObject;
  210. };
  211. noData?: {
  212. style: CSSObject;
  213. };
  214. progress?: {
  215. style: CSSObject;
  216. };
  217. }
  218. export interface PaginationOptions {
  219. noRowsPerPage?: boolean;
  220. rowsPerPageText?: string;
  221. rangeSeparatorText?: string;
  222. selectAllRowsItem?: boolean;
  223. selectAllRowsItemText?: string;
  224. }
  225. export interface PaginationServerOptions {
  226. persistSelectedOnSort?: boolean;
  227. persistSelectedOnPageChange?: boolean;
  228. }
  229. export interface ExpandableIcon {
  230. collapsed: React.ReactNode;
  231. expanded: React.ReactNode;
  232. }
  233. export interface ContextMessage {
  234. singular: string;
  235. plural: string;
  236. message?: string;
  237. }
  238. export type TableState<T> = {
  239. allSelected: boolean;
  240. contextMessage: ContextMessage;
  241. selectedCount: number;
  242. selectedRows: T[];
  243. selectedColumn: TableColumn<T>;
  244. sortDirection: SortOrder;
  245. currentPage: number;
  246. rowsPerPage: number;
  247. selectedRowsFlag: boolean;
  248. toggleOnSelectedRowsChange: boolean;
  249. };
  250. type ThemeText = {
  251. primary: string;
  252. secondary: string;
  253. disabled: string;
  254. };
  255. type ThemeBackground = {
  256. default: string;
  257. };
  258. type ThemeContext = {
  259. background: string;
  260. text: string;
  261. };
  262. type ThemeDivider = {
  263. default: string;
  264. };
  265. type ThemeButton = {
  266. default: string;
  267. focus: string;
  268. hover: string;
  269. disabled: string;
  270. };
  271. type ThemeSelected = {
  272. default: string;
  273. text: string;
  274. };
  275. type ThemeHighlightOnHover = {
  276. default: string;
  277. text: string;
  278. };
  279. type ThemeStriped = {
  280. default: string;
  281. text: string;
  282. };
  283. export type Themes = string;
  284. export interface Theme {
  285. text: ThemeText;
  286. background: ThemeBackground;
  287. context: ThemeContext;
  288. divider: ThemeDivider;
  289. button: ThemeButton;
  290. selected: ThemeSelected;
  291. highlightOnHover: ThemeHighlightOnHover;
  292. striped: ThemeStriped;
  293. }
  294. export interface AllRowsAction<T> {
  295. type: 'SELECT_ALL_ROWS';
  296. keyField: string;
  297. rows: T[];
  298. rowCount: number;
  299. mergeSelections: boolean;
  300. }
  301. export interface SingleRowAction<T> {
  302. type: 'SELECT_SINGLE_ROW';
  303. keyField: string;
  304. row: T;
  305. isSelected: boolean;
  306. rowCount: number;
  307. singleSelect: boolean;
  308. }
  309. export interface MultiRowAction<T> {
  310. type: 'SELECT_MULTIPLE_ROWS';
  311. keyField: string;
  312. selectedRows: T[];
  313. totalRows: number;
  314. mergeSelections: boolean;
  315. }
  316. export interface SortAction<T> {
  317. type: 'SORT_CHANGE';
  318. sortDirection: SortOrder;
  319. selectedColumn: TableColumn<T>;
  320. clearSelectedOnSort: boolean;
  321. }
  322. export interface PaginationPageAction {
  323. type: 'CHANGE_PAGE';
  324. page: number;
  325. paginationServer: boolean;
  326. visibleOnly: boolean;
  327. persistSelectedOnPageChange: boolean;
  328. }
  329. export interface PaginationRowsPerPageAction {
  330. type: 'CHANGE_ROWS_PER_PAGE';
  331. rowsPerPage: number;
  332. page: number;
  333. }
  334. export interface ClearSelectedRowsAction {
  335. type: 'CLEAR_SELECTED_ROWS';
  336. selectedRowsFlag: boolean;
  337. }
  338. export interface ColumnsAction<T> {
  339. type: 'UPDATE_COLUMNS';
  340. cols: TableColumn<T>[];
  341. }
  342. export type Action<T> = AllRowsAction<T> | SingleRowAction<T> | MultiRowAction<T> | SortAction<T> | PaginationPageAction | PaginationRowsPerPageAction | ClearSelectedRowsAction;
  343. export {};