material-react-table 2.8.0 → 2.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. package/dist/index.d.ts +17 -9
  2. package/dist/index.esm.js +260 -218
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +259 -216
  5. package/dist/index.js.map +1 -1
  6. package/locales/ja/index.esm.js +4 -4
  7. package/locales/ja/index.js +4 -4
  8. package/package.json +6 -4
  9. package/src/components/body/MRT_TableBody.tsx +2 -3
  10. package/src/components/body/MRT_TableBodyCell.tsx +10 -3
  11. package/src/components/body/MRT_TableBodyRow.tsx +77 -57
  12. package/src/components/footer/MRT_TableFooterCell.tsx +10 -1
  13. package/src/components/footer/MRT_TableFooterRow.tsx +19 -8
  14. package/src/components/head/MRT_TableHeadCell.tsx +10 -0
  15. package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +4 -2
  16. package/src/components/head/MRT_TableHeadRow.tsx +19 -8
  17. package/src/components/inputs/MRT_EditCellTextField.tsx +4 -3
  18. package/src/components/inputs/MRT_SelectCheckbox.tsx +4 -6
  19. package/src/components/table/MRT_Table.tsx +4 -0
  20. package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +1 -1
  21. package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +1 -0
  22. package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +1 -0
  23. package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +4 -2
  24. package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +1 -0
  25. package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +1 -0
  26. package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +2 -1
  27. package/src/hooks/useMRT_ColumnVirtualizer.ts +77 -76
  28. package/src/hooks/useMRT_RowVirtualizer.ts +30 -32
  29. package/src/hooks/useMRT_TableInstance.ts +1 -42
  30. package/src/hooks/useMRT_TableOptions.ts +60 -17
  31. package/src/locales/ja.ts +4 -4
  32. package/src/types.ts +3 -0
  33. package/src/utils/displayColumn.utils.ts +2 -2
  34. package/src/utils/row.utils.ts +25 -1
  35. package/src/utils/style.utils.ts +70 -30
  36. package/src/utils.ts +0 -0
@@ -42,6 +42,49 @@ export const getMRTTheme = <TData extends MRT_RowData>(
42
42
  };
43
43
  };
44
44
 
45
+ export const pinnedBeforeAfterStyles = {
46
+ content: '""',
47
+ height: '100%',
48
+ left: 0,
49
+ position: 'absolute',
50
+ top: 0,
51
+ width: '100%',
52
+ zIndex: -1,
53
+ };
54
+
55
+ export const getCommonPinnedCellStyles = <TData extends MRT_RowData>({
56
+ column,
57
+ table,
58
+ theme,
59
+ }: {
60
+ column?: MRT_Column<TData>;
61
+ table: MRT_TableInstance<TData>;
62
+ theme: Theme;
63
+ }) => {
64
+ const { baseBackgroundColor } = getMRTTheme(table, theme);
65
+ return {
66
+ '&[data-pinned="true"]': {
67
+ '&:before': {
68
+ backgroundColor: alpha(
69
+ darken(
70
+ baseBackgroundColor,
71
+ theme.palette.mode === 'dark' ? 0.05 : 0.01,
72
+ ),
73
+ 0.97,
74
+ ),
75
+ boxShadow: column
76
+ ? getIsLastLeftPinnedColumn(table, column)
77
+ ? `-4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset`
78
+ : getIsFirstRightPinnedColumn(column)
79
+ ? `4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset`
80
+ : undefined
81
+ : undefined,
82
+ ...pinnedBeforeAfterStyles,
83
+ },
84
+ },
85
+ };
86
+ };
87
+
45
88
  export const getCommonMRTCellStyles = <TData extends MRT_RowData>({
46
89
  column,
47
90
  header,
@@ -56,17 +99,20 @@ export const getCommonMRTCellStyles = <TData extends MRT_RowData>({
56
99
  theme: Theme;
57
100
  }) => {
58
101
  const {
59
- options: { layoutMode },
102
+ options: { enableColumnVirtualization, layoutMode },
60
103
  } = table;
61
104
  const { columnDef } = column;
62
105
 
106
+ const isColumnPinned =
107
+ columnDef.columnDefType !== 'group' && column.getIsPinned();
108
+
63
109
  const widthStyles: CSSProperties = {
64
110
  minWidth: `max(calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId(
65
111
  header?.id ?? column.id,
66
112
  )}-size) * 1px), ${columnDef.minSize ?? 30}px)`,
67
113
  width: `calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId(
68
114
  header?.id ?? column.id,
69
- )}-size) * 1px${header && layoutMode === 'grid-no-grow' ? ` + ${header?.subHeaders?.length ?? 0}rem` : ''})`,
115
+ )}-size) * 1px)`,
70
116
  };
71
117
 
72
118
  if (layoutMode === 'grid') {
@@ -81,44 +127,38 @@ export const getCommonMRTCellStyles = <TData extends MRT_RowData>({
81
127
  widthStyles.flex = `${+(columnDef.grow || 0)} 0 auto`;
82
128
  }
83
129
 
130
+ const pinnedStyles = isColumnPinned
131
+ ? {
132
+ ...getCommonPinnedCellStyles({ column, table, theme }),
133
+ left:
134
+ isColumnPinned === 'left'
135
+ ? `${column.getStart('left')}px`
136
+ : undefined,
137
+ opacity: 0.97,
138
+ position: 'sticky',
139
+ right:
140
+ isColumnPinned === 'right'
141
+ ? `${getTotalRight(table, column)}px`
142
+ : undefined,
143
+ zIndex: 1,
144
+ }
145
+ : {};
146
+
84
147
  return {
85
- backgroundColor:
86
- column.getIsPinned() && columnDef.columnDefType !== 'group'
87
- ? alpha(
88
- darken(
89
- getMRTTheme(table, theme).baseBackgroundColor,
90
- theme.palette.mode === 'dark' ? 0.05 : 0.01,
91
- ),
92
- 0.97,
93
- )
94
- : 'inherit',
148
+ backgroundColor: 'inherit',
95
149
  backgroundImage: 'inherit',
96
- boxShadow: getIsLastLeftPinnedColumn(table, column)
97
- ? `-4px 0 8px -6px ${alpha(theme.palette.grey[700], 0.5)} inset`
98
- : getIsFirstRightPinnedColumn(column)
99
- ? `4px 0 8px -6px ${alpha(theme.palette.grey[700], 0.5)} inset`
100
- : undefined,
101
150
  display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
102
- left:
103
- column.getIsPinned() === 'left'
104
- ? `${column.getStart('left')}px`
105
- : undefined,
106
151
  opacity:
107
152
  table.getState().draggingColumn?.id === column.id ||
108
153
  table.getState().hoveredColumn?.id === column.id
109
154
  ? 0.5
110
155
  : 1,
111
- position:
112
- column.getIsPinned() && columnDef.columnDefType !== 'group'
113
- ? 'sticky'
114
- : undefined,
115
- right:
116
- column.getIsPinned() === 'right'
117
- ? `${getTotalRight(table, column)}px`
118
- : undefined,
119
- transition: table.options.enableColumnVirtualization
156
+ position: 'relative',
157
+ transition: enableColumnVirtualization
120
158
  ? 'none'
121
159
  : `padding 150ms ease-in-out`,
160
+ zIndex: 0,
161
+ ...pinnedStyles,
122
162
  ...widthStyles,
123
163
  ...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as any),
124
164
  };
package/src/utils.ts DELETED
File without changes