es-grid-template 1.8.56 → 1.8.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/es/grid-component/type.d.ts +8 -0
  2. package/es/table-component/TableContainer.js +6 -0
  3. package/es/table-component/TableContainerEdit.js +4 -2
  4. package/es/table-component/body/TableBodyCell.js +6 -49
  5. package/es/table-component/body/TableBodyRow.js +7 -12
  6. package/es/table-component/footer/TableFooterRow.js +6 -3
  7. package/es/table-component/header/TableHead.js +4 -1
  8. package/es/table-component/header/TableHeadCell2.js +7 -48
  9. package/es/table-component/header/TableHeadGroupCell.js +13 -225
  10. package/es/table-component/header/TableHeadRow.js +7 -19
  11. package/es/table-component/hook/useColumns.js +17 -3
  12. package/es/table-component/hook/utils.js +0 -17
  13. package/es/table-component/style.scss +6 -5
  14. package/es/table-component/type.d.ts +7 -1
  15. package/es/table-component/useContext.d.ts +4 -1
  16. package/lib/grid-component/type.d.ts +8 -0
  17. package/lib/table-component/TableContainer.js +6 -0
  18. package/lib/table-component/TableContainerEdit.js +4 -2
  19. package/lib/table-component/body/TableBodyCell.js +6 -49
  20. package/lib/table-component/body/TableBodyRow.js +7 -12
  21. package/lib/table-component/footer/TableFooterRow.js +6 -3
  22. package/lib/table-component/header/TableHead.js +4 -1
  23. package/lib/table-component/header/TableHeadCell2.js +7 -48
  24. package/lib/table-component/header/TableHeadGroupCell.js +11 -223
  25. package/lib/table-component/header/TableHeadRow.js +7 -20
  26. package/lib/table-component/hook/useColumns.js +17 -3
  27. package/lib/table-component/hook/utils.js +0 -17
  28. package/lib/table-component/style.scss +6 -5
  29. package/lib/table-component/type.d.ts +7 -1
  30. package/lib/table-component/useContext.d.ts +4 -1
  31. package/package.json +1 -1
@@ -9,6 +9,7 @@ import type { FieldNames, FilterFunc } from "rc-select/es/Select";
9
9
  import type { ColorPickerProps } from "antd";
10
10
  import type { FixedType } from "rc-base-table/lib/interface";
11
11
  import type { TableLocale } from "rc-master-ui/lib/table/interface";
12
+ import type { Cell, Header, Row } from '@tanstack/react-table';
12
13
  export type IColumnType = "number" | "time" | "date" | "week" | "month" | "file" | "quarter" | "year" | "datetime" | "string" | "boolean" | "checkbox" | "color" | null | undefined;
13
14
  export type AnyObject = Record<PropertyKey, any>;
14
15
  export type SelectMode = 'checkbox' | 'radio' | undefined;
@@ -135,6 +136,9 @@ export type ColumnTable<RecordType = AnyObject> = Omit<RcColumnType<RecordType>,
135
136
  editFromSettings?: IEditFromSettings;
136
137
  fixedType?: FixedType;
137
138
  headerTextWrap?: boolean;
139
+ onCellStyles?: Omit<React.CSSProperties, 'display' | 'width' | 'minWidth' | 'left' | 'right' | 'position'> | ((cellValue: any, cell: Cell<RecordType, unknown>) => Omit<React.CSSProperties, 'display' | 'width' | 'minWidth' | 'left' | 'right' | 'position'>);
140
+ onCellHeaderStyles?: Omit<React.CSSProperties, 'display' | 'width' | 'minWidth' | 'left' | 'right' | 'position'> | ((cell: Header<RecordType, unknown>) => Omit<React.CSSProperties, 'display' | 'width' | 'minWidth' | 'left' | 'right' | 'position'>);
141
+ onCellFooterStyles?: Omit<React.CSSProperties, 'display' | 'width' | 'minWidth' | 'left' | 'right' | 'position'> | ((cellValue: any, cell: Header<RecordType, unknown>) => Omit<React.CSSProperties, 'display' | 'width' | 'minWidth' | 'left' | 'right' | 'position'>);
138
142
  };
139
143
  export type IFormOpen = {
140
144
  value?: any;
@@ -193,6 +197,7 @@ export type Sort = {
193
197
  export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<RecordType>, 'columns' | 'rowSelection' | 'loading' | 'dataSource' | 'summary' | 'pagination' | 'locale'> {
194
198
  editAble?: boolean;
195
199
  infiniteScroll?: boolean;
200
+ theme?: 'dark' | 'light';
196
201
  next?: () => void;
197
202
  locale?: Locale;
198
203
  groupAble?: boolean;
@@ -266,6 +271,9 @@ export interface TableProps<RecordType = AnyObject> extends Omit<RcTableProps<Re
266
271
  wrapSettings?: IWrapSettings;
267
272
  actionTemplate?: ReactNode | ReactElement | (() => ReactNode | ReactElement);
268
273
  fullScreen?: boolean;
274
+ onRowStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | ((data: RecordType, row: Row<RecordType>) => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
275
+ onRowHeaderStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | (() => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
276
+ onRowFooterStyles?: Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'> | (() => Omit<React.CSSProperties, 'display' | 'transform' | 'gridTemplateColumns' | 'height' | 'minHeight'>);
269
277
  }
270
278
  export type PaginationConfig = TablePaginationConfig & {
271
279
  currentPage?: number;
@@ -76,6 +76,9 @@ const TableContainer = props => {
76
76
  columnSizing,
77
77
  columnSizingInfo,
78
78
  rowClassName,
79
+ onRowStyles,
80
+ onRowFooterStyles,
81
+ onRowHeaderStyles,
79
82
  title
80
83
  } = props;
81
84
  const tableContainerRef = React.useRef(null);
@@ -270,6 +273,9 @@ const TableContainer = props => {
270
273
  focusedCell,
271
274
  setFocusedCell,
272
275
  rowClassName,
276
+ onRowStyles,
277
+ onRowFooterStyles,
278
+ onRowHeaderStyles,
273
279
  table,
274
280
  pagination
275
281
  }
@@ -125,7 +125,8 @@ const TableContainerEdit = props => {
125
125
  setColumns,
126
126
  columnSizing,
127
127
  columnSizingInfo,
128
- rowClassName
128
+ rowClassName,
129
+ onRowStyles
129
130
  } = props;
130
131
  const containerRef = React.useRef(null);
131
132
  const bottomToolbarRef = React.useRef(null);
@@ -1895,7 +1896,8 @@ const TableContainerEdit = props => {
1895
1896
  handleCellClick,
1896
1897
  pagination,
1897
1898
  rowClassName,
1898
- rowEditable
1899
+ rowEditable,
1900
+ onRowStyles
1899
1901
  }
1900
1902
  }, /*#__PURE__*/React.createElement(TableWrapper, {
1901
1903
  contextMenuItems: contextMenuItems,
@@ -168,6 +168,7 @@ const TableBodyCell = props => {
168
168
  const [isOpenTooltip, setIsOpenTooltip] = React.useState(false);
169
169
  const record = cell.row.original;
170
170
  const columnMeta = cell.column.columnDef.meta ?? {};
171
+ const cellStyles = typeof columnMeta.onCellStyles === 'function' ? columnMeta.onCellStyles(cell.getValue(), cell) : columnMeta.onCellStyles;
171
172
 
172
173
  // const tooltipContent = (isOpenTooltip === false || columnMeta.type === 'checkbox') ? '' : flexRender(cell.column.columnDef.cell, cell.getContext());
173
174
  const tooltipContent = isOpenTooltip === false ? '' : columnMeta?.tooltipDescription ? typeof columnMeta.tooltipDescription === 'function' ? columnMeta.tooltipDescription({
@@ -197,18 +198,13 @@ const TableBodyCell = props => {
197
198
  [`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
198
199
  [`${prefix}-grid-cell-text-center`]: columnMeta?.textAlign === 'center',
199
200
  [`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right'
200
- // [`${prefix}-grid-cell-index-selected`]: rowRange?.includes(cell.row.id),
201
- // [`${prefix}-grid-cell-index-selected`]: selectRowIds?.includes(cell.row.id),
202
201
  }),
203
202
  style: {
203
+ ...cellStyles,
204
204
  display: 'flex',
205
- // height: '36px',
206
205
  userSelect: 'none',
207
206
  width: cell.column.getSize(),
208
- // flexBasis: cell.column.getSize(),
209
207
  minWidth: cell.column.getSize(),
210
- // flex: 1,
211
- // maxWidth: cell.column.getSize(),
212
208
  ...getCommonPinningStyles(cell.column)
213
209
  },
214
210
  onClick: e => {
@@ -272,12 +268,10 @@ const TableBodyCell = props => {
272
268
  [`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right'
273
269
  }),
274
270
  style: {
271
+ ...cellStyles,
275
272
  display: 'flex',
276
- // height: '36px',
277
273
  width: cell.column.getSize(),
278
274
  minWidth: cell.column.getSize(),
279
- // flex: 1,
280
- // maxWidth: cell.column.getSize(),
281
275
  ...getCommonPinningStyles(cell.column)
282
276
  }
283
277
  }, renderCommand({
@@ -298,51 +292,16 @@ const TableBodyCell = props => {
298
292
  [`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right'
299
293
  }),
300
294
  style: {
295
+ ...cellStyles,
301
296
  display: 'flex',
302
- // height: '36px',
303
297
  minHeight: 36,
304
298
  width: cell.column.getSize(),
305
299
  minWidth: cell.column.getSize(),
306
- // flex: 1,
307
- // maxWidth: cell.column.getSize(),
308
300
  ...getCommonPinningStyles(cell.column)
309
301
  }
310
302
  }, /*#__PURE__*/React.createElement("div", {
311
303
  className: classNames('ui-rc_cell-content', {})
312
- }, cell.column.getIndex() === expandIconColumnIndex && isDataTree && /*#__PURE__*/React.createElement("div", {
313
- className: "ui-rc-table-row-expand-trigger",
314
- style: {
315
- paddingLeft: `${cell.row.depth * 25}px`
316
- }
317
- }, /*#__PURE__*/React.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/React.createElement("button", {
318
- // onClick: row.getToggleExpandedHandler(),
319
- onClick: () => {
320
- const keys = Object.keys(expanded);
321
- // @ts-ignore
322
- const tmp = {
323
- ...expanded
324
- };
325
- if (keys.includes(cell.row.id)) {
326
- delete tmp[cell.row.id];
327
- setExpanded(tmp);
328
- } else {
329
- setExpanded(old => ({
330
- ...old,
331
- [cell.row.id]: true
332
- }));
333
- }
334
- },
335
- style: {
336
- cursor: "pointer"
337
- },
338
- className: "ui-rc-table-row-expand"
339
- }, cell.row.getIsExpanded() ? /*#__PURE__*/React.createElement("span", {
340
- className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-expanded"
341
- }) : /*#__PURE__*/React.createElement("span", {
342
- className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed"
343
- })) : /*#__PURE__*/React.createElement("span", {
344
- className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced"
345
- }))), cell.column.id === "selection_column" && renderSelection({
304
+ }, cell.column.id === "selection_column" && renderSelection({
346
305
  cell,
347
306
  table,
348
307
  selectionSettings,
@@ -385,13 +344,11 @@ const TableBodyCell = props => {
385
344
  [`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right' || columnMeta.type === 'number'
386
345
  }),
387
346
  style: {
347
+ ...cellStyles,
388
348
  display: 'flex',
389
349
  width: cell.column.getSize(),
390
350
  minWidth: cell.column.getSize(),
391
351
  minHeight: 36,
392
- // flex: 1,
393
- // maxWidth: cell.column.getSize(),
394
- // height: '36px',
395
352
  ...getCommonPinningStyles(cell.column)
396
353
  },
397
354
  onMouseEnter: e => {
@@ -27,7 +27,8 @@ const TableBodyRow = ({
27
27
  recordDoubleClick,
28
28
  focusedCell,
29
29
  rowClassName,
30
- rowEditable
30
+ rowEditable,
31
+ onRowStyles
31
32
  } = React.useContext(TableContext);
32
33
  const visibleCells = row.getVisibleCells();
33
34
  const virtualColumns = columnVirtualizer.getVirtualItems();
@@ -39,23 +40,18 @@ const TableBodyRow = ({
39
40
  const virtualRight = virtualPaddingRight ? [virtualPaddingRight] : [];
40
41
  const templateColumns = [...leftTemplate, ...virtualLeft, ...centerTemplate, ...virtualRight, ...rightTemplate];
41
42
  const rowClass = typeof rowClassName === 'function' ? rowClassName(row.original, row.index, row.depth) : rowClassName;
43
+ const rowStyles = typeof onRowStyles === 'function' ? onRowStyles(row.original, row) : onRowStyles;
42
44
  const isRowEditable = rowEditable ? rowEditable(row.original) : true;
43
45
  return /*#__PURE__*/React.createElement("div", {
44
46
  "data-index": virtualRow.index //needed for dynamic row height measurement
45
47
  ,
46
48
  ref: node => rowVirtualizer.measureElement(node) //measure dynamic row height
47
49
  ,
48
- key: row.id
49
- // data-row-key={cell.row.id}
50
- ,
51
- "data-row-key": row.id
52
-
53
- // className={} ui-rc-table-row-selected
54
- ,
50
+ key: row.id,
51
+ "data-row-key": row.id,
55
52
  className: classNames(`${prefix}-grid-row ${rowClass ?? ''}`, {
56
53
  [`${prefix}-grid-row-selected`]: row.getIsSelected(),
57
54
  [`${prefix}-grid-row-focus`]: row.id === focusedCell?.rowId && !editAble
58
- // [`${prefix}-grid-row-focus`]: true,
59
55
  }),
60
56
  style: {
61
57
  // display: 'flex',
@@ -63,12 +59,11 @@ const TableBodyRow = ({
63
59
  // position: 'absolute',
64
60
  transform: `translateY(${virtualRow.start}px)`,
65
61
  //this should always be a `style` as it changes on scroll
66
- // width: '100%',
67
62
  // height: isEditing ? '36px' : undefined,
68
63
  gridTemplateColumns: `${templateColumns.map(n => `${n}fr`).join(" ")}`,
69
- // gridTemplateColumns: `repeat(${centerCOlumns.length + fixedLeftColumns.length + fixedRightColumns.length}, minmax(0, 1fr))`,
70
64
  height: isEditing ? virtualRow.size : undefined,
71
- minHeight: isEditing ? undefined : virtualRow.size
65
+ minHeight: isEditing ? undefined : virtualRow.size,
66
+ ...rowStyles
72
67
  },
73
68
  onDoubleClick: e => {
74
69
  recordDoubleClick?.({
@@ -2,6 +2,7 @@
2
2
  // import type { Person } from "../makeData";
3
3
  import TableFooterCell from "./TableFooterCell";
4
4
  import React from "react";
5
+ import { TableContext } from "../useContext";
5
6
  // import type { Person } from "../../tanstack-table/makeData";
6
7
  // import TableHeadCell from "./TableHeadCell";
7
8
 
@@ -20,17 +21,19 @@ const TableFooterRow = ({
20
21
 
21
22
  // const a = table.getVisibleFlatColumns()
22
23
  const visibleColumns = table.getVisibleLeafColumns();
24
+ const {
25
+ onRowFooterStyles
26
+ } = React.useContext(TableContext);
27
+ const rowStyles = typeof onRowFooterStyles === 'function' ? onRowFooterStyles() : onRowFooterStyles;
23
28
 
24
29
  // const
25
30
 
26
31
  return /*#__PURE__*/React.createElement("div", {
27
- // data-index={headerGroup.id}
28
32
  key: headerGroup.id,
29
33
  style: {
34
+ ...rowStyles,
30
35
  display: "grid",
31
36
  width: "100%",
32
- // borderBottom: "1px solid #e0e0e0",
33
- // borderTop: "1px solid #e0e0e0",
34
37
  height: 37,
35
38
  gridTemplateColumns: `${table.getVisibleLeafColumns().map(n => `${n.getSize()}fr`).join(" ")}`
36
39
  },
@@ -24,15 +24,18 @@ const TableHead = ({
24
24
  // fixedRightColumns
25
25
  }) => {
26
26
  const {
27
- prefix
27
+ prefix,
28
+ onRowHeaderStyles
28
29
  } = useContext(TableContext);
29
30
  const headerGroups = table.getFlatHeaders();
30
31
  const leafColumns = table.getVisibleFlatColumns();
31
32
  // const leafColumns11 = table.getIsAllColumnsVisible();
32
33
  const headerDepth = table.getHeaderGroups().length;
34
+ const rowStyles = typeof onRowHeaderStyles === 'function' ? onRowHeaderStyles() : onRowHeaderStyles;
33
35
  return /*#__PURE__*/React.createElement("div", {
34
36
  className: `${prefix}-grid-thead`,
35
37
  style: {
38
+ ...rowStyles,
36
39
  display: 'grid',
37
40
  position: 'sticky',
38
41
  top: 0,
@@ -1,9 +1,5 @@
1
- // import { useSortable } from "@dnd-kit/sortable"
2
-
3
1
  import { flexRender } from '@tanstack/react-table';
4
2
  import React, { useContext } from 'react';
5
- // import { CSS } from '@dnd-kit/utilities'
6
- // import type { Virtualizer } from '@tanstack/react-virtual'
7
3
  import { Button, Space } from 'antd';
8
4
  import { ArrowDown, ArrowUp, FilterFill, SortCancel } from 'becoxy-icons';
9
5
  import classNames from 'classnames';
@@ -13,11 +9,6 @@ import { excludeItems, extendsObject, getCommonPinningStyles, getDefaultOperator
13
9
  import { TableContext } from "../useContext";
14
10
  import { renderFilter } from "./renderFilter";
15
11
  import ReactDOMServer from 'react-dom/server';
16
-
17
- // import { ColumnTable } from "../type";
18
-
19
- // import { Tooltip } from 'react-tooltip'
20
-
21
12
  const TableHeadCell2 = props => {
22
13
  const {
23
14
  column,
@@ -25,9 +16,6 @@ const TableHeadCell2 = props => {
25
16
  getPopupContainer,
26
17
  table,
27
18
  depth,
28
- // t,
29
- // columnVirtualizer,
30
- // rowHeaderVirtualizer,
31
19
  colSpan,
32
20
  rowSpan
33
21
  } = props;
@@ -52,33 +40,16 @@ const TableHeadCell2 = props => {
52
40
  const {
53
41
  filterIcon
54
42
  } = column.columnDef.meta ?? {};
55
-
56
- // const column = (column.columnDef ?? {}) as ColumnTable
57
- // const column = column.columnDef
58
-
59
43
  const originalColumn = column.columnDef.meta ?? {};
44
+ const cellStyles = typeof originalColumn.onCellHeaderStyles === 'function' ? originalColumn.onCellHeaderStyles(header) : originalColumn.onCellHeaderStyles;
60
45
  const filtered = (column.getFilterValue() ?? []).length > 0;
61
46
  const cellContent = flexRender(column.columnDef.header, header.getContext());
62
- // const cellContent = 'aaaa'
63
-
64
47
  const html = ReactDOMServer.renderToStaticMarkup( /*#__PURE__*/React.createElement(React.Fragment, null, cellContent));
65
48
  const hasValue = html.trim().length > 0;
66
-
67
- // const filtered = column.getIsFiltered()
68
-
69
- // const { attributes, isDragging, listeners, setNodeRef, transform } =
70
- // useSortable({
71
- // id: column.id,
72
- // })
73
-
74
49
  const style = {
75
- // opacity: isDragging ? 0.8 : 1,
76
- // position: 'relative',
77
- // transform: CSS.Translate.toString(transform), // translate instead of transform to avoid squishing
78
50
  transition: 'width transform 0.2s ease-in-out',
79
- whiteSpace: 'nowrap'
80
- // width: column.getSize(),
81
- // zIndex: isDragging ? 1 : 0,
51
+ whiteSpace: 'nowrap',
52
+ ...cellStyles
82
53
  };
83
54
  const getDropdownTrigger = () => {
84
55
  let iconFilter;
@@ -232,25 +203,15 @@ const TableHeadCell2 = props => {
232
203
  [`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
233
204
  [`${prefix}-grid-cell-text-center`]: (originalColumn?.headerTextAlign ?? originalColumn?.textAlign) === 'center',
234
205
  [`${prefix}-grid-cell-text-right`]: (originalColumn?.headerTextAlign ?? originalColumn.textAlign) === 'right'
235
- })
236
- // colSpan={colSpan}
237
- // rowSpan={rowSpan}
238
- ,
239
-
206
+ }),
240
207
  key: column.id,
241
208
  style: {
242
- // display: 'flex',
243
- // width: column.getSize(),
209
+ ...style,
244
210
  minWidth: column.getSize(),
245
- // flex: 1,
246
- // flexGrow: column.getSize(),
247
-
248
211
  gridRow: `${depth + 1} / span ${rowSpan}`,
249
212
  gridColumn: `span ${colSpan}`,
250
- // maxWidth: header.getSize(),
251
213
  ...getCommonPinningStyles(column),
252
- width: 'auto',
253
- ...style
214
+ width: 'auto'
254
215
  },
255
216
  "data-tooltip-id": `${id}-tooltip-content`,
256
217
  "data-tooltip-delay-show": 500,
@@ -261,9 +222,7 @@ const TableHeadCell2 = props => {
261
222
  [`${prefix}-grid-selection-column`]: column.id === 'selection_column'
262
223
  })
263
224
  }, column.id === 'selection_column' && selectionSettings && selectionSettings.hideSelectAll !== true && selectionSettings.type !== 'single' && selectionSettings.mode !== 'radio' && /*#__PURE__*/React.createElement(Checkbox, {
264
- checked: table.getIsAllRowsSelected()
265
- // indeterminate={table.getIsSomeRowsSelected()}
266
- ,
225
+ checked: table.getIsAllRowsSelected(),
267
226
  indeterminate: table.getIsSomePageRowsSelected(),
268
227
  onChange: e => {
269
228
  table.getToggleAllRowsSelectedHandler()(e);