@snack-uikit/table 0.25.13-preview-03091779.0 → 0.25.13

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 (39) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +0 -6
  3. package/dist/cjs/components/Table/Table.d.ts +2 -2
  4. package/dist/cjs/components/Table/Table.js +23 -44
  5. package/dist/cjs/components/Table/styles.module.css +0 -3
  6. package/dist/cjs/components/Table/utils.d.ts +0 -10
  7. package/dist/cjs/components/Table/utils.js +0 -19
  8. package/dist/cjs/components/types.d.ts +1 -5
  9. package/dist/cjs/helperComponents/Rows/BodyRow.d.ts +2 -3
  10. package/dist/cjs/helperComponents/Rows/BodyRow.js +9 -20
  11. package/dist/cjs/helperComponents/Rows/Row.d.ts +5 -4
  12. package/dist/cjs/helperComponents/Rows/Row.js +3 -5
  13. package/dist/esm/components/Table/Table.d.ts +2 -2
  14. package/dist/esm/components/Table/Table.js +10 -24
  15. package/dist/esm/components/Table/styles.module.css +0 -3
  16. package/dist/esm/components/Table/utils.d.ts +0 -10
  17. package/dist/esm/components/Table/utils.js +0 -14
  18. package/dist/esm/components/types.d.ts +1 -5
  19. package/dist/esm/helperComponents/Rows/BodyRow.d.ts +2 -3
  20. package/dist/esm/helperComponents/Rows/BodyRow.js +4 -17
  21. package/dist/esm/helperComponents/Rows/Row.d.ts +5 -4
  22. package/dist/esm/helperComponents/Rows/Row.js +3 -4
  23. package/package.json +5 -7
  24. package/src/components/Table/Table.tsx +14 -44
  25. package/src/components/Table/styles.module.scss +0 -5
  26. package/src/components/Table/{utils.tsx → utils.ts} +0 -18
  27. package/src/components/types.ts +1 -9
  28. package/src/helperComponents/Rows/BodyRow.tsx +47 -53
  29. package/src/helperComponents/Rows/Row.tsx +9 -8
  30. package/dist/cjs/components/Table/hooks/useRowVirtualizer.d.ts +0 -2
  31. package/dist/cjs/components/Table/hooks/useRowVirtualizer.js +0 -45
  32. package/dist/cjs/helperComponents/Rows/VirtualRow.d.ts +0 -7
  33. package/dist/cjs/helperComponents/Rows/VirtualRow.js +0 -40
  34. package/dist/esm/components/Table/hooks/useRowVirtualizer.d.ts +0 -2
  35. package/dist/esm/components/Table/hooks/useRowVirtualizer.js +0 -29
  36. package/dist/esm/helperComponents/Rows/VirtualRow.d.ts +0 -7
  37. package/dist/esm/helperComponents/Rows/VirtualRow.js +0 -28
  38. package/src/components/Table/hooks/useRowVirtualizer.ts +0 -51
  39. package/src/helperComponents/Rows/VirtualRow.tsx +0 -31
@@ -1,6 +1,5 @@
1
1
  import { PaginationState, Row, RowPinningState, RowSelectionOptions, RowSelectionState, SortingState } from '@tanstack/react-table';
2
- import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
3
- import { MutableRefObject, ReactNode, RefObject } from 'react';
2
+ import { ReactNode, RefObject } from 'react';
4
3
  import { ToolbarProps } from '@snack-uikit/toolbar';
5
4
  import { WithSupportProps } from '@snack-uikit/utils';
6
5
  import { EmptyStateProps, ExportButtonProps, RowClickHandler } from '../helperComponents';
@@ -130,9 +129,6 @@ export type TableProps<TData extends object> = WithSupportProps<{
130
129
  id: string;
131
130
  resize?: boolean;
132
131
  };
133
- enableRowVirtualization?: boolean;
134
- rowVirtualizerOptions?: Parameters<typeof useVirtualizer>[0];
135
- rowVirtualizerInstanceRef?: MutableRefObject<Virtualizer<Element, Element> | null>;
136
132
  }>;
137
133
  export type ServerTableProps<TData extends object> = Omit<TableProps<TData>, 'pageSize' | 'pageCount' | 'pagination' | 'search' | 'data'> & {
138
134
  /** Данные для отрисовки */
@@ -1,5 +1,5 @@
1
1
  import { Row as TableRow } from '@tanstack/react-table';
2
- import { CSSProperties, MouseEvent } from 'react';
2
+ import { MouseEvent } from 'react';
3
3
  export type RowInfo<TData> = {
4
4
  id: string;
5
5
  data: TData;
@@ -10,7 +10,6 @@ export type RowClickHandler<TData> = (e: MouseEvent<HTMLDivElement>, row: RowInf
10
10
  type BodyRowProps<TData> = {
11
11
  row: TableRow<TData>;
12
12
  onRowClick?: RowClickHandler<TData>;
13
- style?: CSSProperties;
14
13
  };
15
- export declare const BodyRow: import("react").ForwardRefExoticComponent<BodyRowProps<any> & import("react").RefAttributes<HTMLDivElement>>;
14
+ export declare function BodyRow<TData>({ row, onRowClick }: BodyRowProps<TData>): import("react/jsx-runtime").JSX.Element;
16
15
  export {};
@@ -1,16 +1,5 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { forwardRef, useState } from 'react';
2
+ import { useState } from 'react';
14
3
  import { COLUMN_PIN_POSITION, TEST_IDS } from '../../constants';
15
4
  import { BodyCell } from '../Cells';
16
5
  import { RowContext } from '../contexts';
@@ -18,9 +7,7 @@ import { useRowCells } from '../hooks';
18
7
  import { PinnedCells } from './PinnedCells';
19
8
  import { Row } from './Row';
20
9
  import styles from './styles.module.css';
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- export const BodyRow = forwardRef((_a, ref) => {
23
- var { row, onRowClick } = _a, attributes = __rest(_a, ["row", "onRowClick"]);
10
+ export function BodyRow({ row, onRowClick }) {
24
11
  const { pinnedLeft, pinnedRight, unpinned } = useRowCells(row);
25
12
  const [dropListOpened, setDropListOpen] = useState(false);
26
13
  const disabled = !row.getCanSelect();
@@ -34,5 +21,5 @@ export const BodyRow = forwardRef((_a, ref) => {
34
21
  toggleSelected: row.toggleSelected,
35
22
  });
36
23
  };
37
- return (_jsx(RowContext.Provider, { value: { dropListOpened, setDropListOpen }, children: _jsxs(Row, Object.assign({}, attributes, { ref: ref, onClick: handleRowClick, "data-clickable": Boolean(onRowClick) || undefined, "data-disabled": disabled || undefined, "data-selected": row.getIsSelected() || undefined, "data-actions-opened": dropListOpened || undefined, "data-test-id": TEST_IDS.bodyRow, "data-row-id": row.id, className: styles.bodyRow, children: [pinnedLeft && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Left, children: pinnedLeft.map(cell => (_jsx(BodyCell, { cell: cell }, cell.id))) })), unpinned.map(cell => (_jsx(BodyCell, { cell: cell }, cell.id))), pinnedRight && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Right, children: pinnedRight.map(cell => (_jsx(BodyCell, { cell: cell }, cell.id))) }))] })) }));
38
- });
24
+ return (_jsx(RowContext.Provider, { value: { dropListOpened, setDropListOpen }, children: _jsxs(Row, { onClick: handleRowClick, "data-clickable": Boolean(onRowClick) || undefined, "data-disabled": disabled || undefined, "data-selected": row.getIsSelected() || undefined, "data-actions-opened": dropListOpened || undefined, "data-test-id": TEST_IDS.bodyRow, "data-row-id": row.id, className: styles.bodyRow, children: [pinnedLeft && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Left, children: pinnedLeft.map(cell => (_jsx(BodyCell, { cell: cell }, cell.id))) })), unpinned.map(cell => (_jsx(BodyCell, { cell: cell }, cell.id))), pinnedRight && (_jsx(PinnedCells, { position: COLUMN_PIN_POSITION.Right, children: pinnedRight.map(cell => (_jsx(BodyCell, { cell: cell }, cell.id))) }))] }) }));
25
+ }
@@ -1,8 +1,9 @@
1
- import { CSSProperties, MouseEvent, ReactNode } from 'react';
1
+ import { MouseEvent, ReactNode } from 'react';
2
2
  import { DataAttributes } from '../types';
3
- export declare const Row: import("react").ForwardRefExoticComponent<{
3
+ type RowProps = {
4
4
  children: ReactNode;
5
5
  onClick?(e: MouseEvent<HTMLDivElement>): void;
6
6
  className?: string;
7
- style?: CSSProperties;
8
- } & DataAttributes & import("react").RefAttributes<HTMLDivElement>>;
7
+ } & DataAttributes;
8
+ export declare function Row({ onClick, children, className, ...attributes }: RowProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -11,11 +11,10 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import cn from 'classnames';
14
- import { forwardRef } from 'react';
15
14
  import styles from './styles.module.css';
16
- export const Row = forwardRef((_a, ref) => {
15
+ export function Row(_a) {
17
16
  var { onClick, children, className } = _a, attributes = __rest(_a, ["onClick", "children", "className"]);
18
17
  return (
19
18
  // eslint-disable-next-line jsx-a11y/interactive-supports-focus
20
- _jsx("div", Object.assign({ ref: ref, onClick: onClick, className: cn(styles.tableRow, className), role: 'row' }, attributes, { children: children })));
21
- });
19
+ _jsx("div", Object.assign({ onClick: onClick, className: cn(styles.tableRow, className), role: 'row' }, attributes, { children: children })));
20
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Table",
7
- "version": "0.25.13-preview-03091779.0",
7
+ "version": "0.25.13",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -37,31 +37,29 @@
37
37
  "scripts": {},
38
38
  "dependencies": {
39
39
  "@snack-uikit/button": "0.19.3",
40
- "@snack-uikit/chips": "0.22.1",
40
+ "@snack-uikit/chips": "0.22.2",
41
41
  "@snack-uikit/icon-predefined": "0.7.1",
42
42
  "@snack-uikit/icons": "0.24.0",
43
43
  "@snack-uikit/info-block": "0.6.4",
44
- "@snack-uikit/list": "0.21.8",
44
+ "@snack-uikit/list": "0.21.9",
45
45
  "@snack-uikit/pagination": "0.9.3",
46
46
  "@snack-uikit/scroll": "0.9.1",
47
47
  "@snack-uikit/skeleton": "0.6.0",
48
48
  "@snack-uikit/toggles": "0.13.1",
49
- "@snack-uikit/toolbar": "0.9.10",
49
+ "@snack-uikit/toolbar": "0.9.11",
50
50
  "@snack-uikit/truncate-string": "0.6.1",
51
51
  "@snack-uikit/typography": "0.8.2",
52
52
  "@snack-uikit/utils": "3.5.0",
53
53
  "@tanstack/match-sorter-utils": "8.11.8",
54
54
  "@tanstack/react-table": "8.12.0",
55
- "@tanstack/react-virtual": "3.10.9",
56
55
  "classnames": "2.5.1",
57
56
  "copy-to-clipboard": "3.3.3",
58
57
  "lodash.debounce": "4.0.8",
59
- "merge-refs": "1.3.0",
60
58
  "uncontrollable": "8.0.4",
61
59
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
62
60
  },
63
61
  "peerDependencies": {
64
62
  "@snack-uikit/locale": "*"
65
63
  },
66
- "gitHead": "cc2cae7b5e9b5d2e270688ae616269cd5b718123"
64
+ "gitHead": "597e832c119abc6347b5e4212268eca03d067d18"
67
65
  }
@@ -1,4 +1,5 @@
1
1
  import {
2
+ CellContext,
2
3
  ColumnPinningState,
3
4
  getCoreRowModel,
4
5
  getFilteredRowModel,
@@ -10,13 +11,13 @@ import {
10
11
  useReactTable,
11
12
  } from '@tanstack/react-table';
12
13
  import cn from 'classnames';
13
- import mergeRefs from 'merge-refs';
14
14
  import { RefObject, useCallback, useEffect, useMemo, useRef } from 'react';
15
15
 
16
16
  import { useLocale } from '@snack-uikit/locale';
17
17
  import { Scroll } from '@snack-uikit/scroll';
18
18
  import { SkeletonContextProvider } from '@snack-uikit/skeleton';
19
19
  import { Toolbar } from '@snack-uikit/toolbar';
20
+ import { TruncateString } from '@snack-uikit/truncate-string';
20
21
  import { extractSupportProps } from '@snack-uikit/utils';
21
22
 
22
23
  import { DEFAULT_PAGE_SIZE } from '../../constants';
@@ -34,21 +35,17 @@ import {
34
35
  TablePagination,
35
36
  useEmptyState,
36
37
  } from '../../helperComponents';
37
- import { VirtualRow } from '../../helperComponents/Rows/VirtualRow';
38
38
  import { ColumnDefinition } from '../../types';
39
39
  import { fuzzyFilter } from '../../utils';
40
40
  import { TableProps } from '../types';
41
41
  import { useLoadingTable, useStateControl } from './hooks';
42
42
  import { usePageReset } from './hooks/usePageReset';
43
- import { useRowVirtualizer } from './hooks/useRowVirtualizer';
44
43
  import styles from './styles.module.scss';
45
44
  import {
46
45
  getColumnStyleVars,
47
46
  getCurrentlyConfiguredHeaderWidth,
48
47
  getInitColumnSizeFromLocalStorage,
49
- isVirtualRow,
50
48
  saveStateToLocalStorage,
51
- truncateCell,
52
49
  } from './utils';
53
50
 
54
51
  /** Компонент таблицы */
@@ -95,10 +92,6 @@ export function Table<TData extends object>({
95
92
  enableFuzzySearch,
96
93
  savedState,
97
94
 
98
- enableRowVirtualization,
99
- rowVirtualizerOptions,
100
- rowVirtualizerInstanceRef,
101
-
102
95
  ...rest
103
96
  }: TableProps<TData>) {
104
97
  const { state: globalFilter, onStateChange: onGlobalFilterChange } = useStateControl<string>(search, '');
@@ -121,7 +114,6 @@ export function Table<TData extends object>({
121
114
  defaultPaginationState,
122
115
  );
123
116
  const enableSelection = Boolean(rowSelectionProp?.enable);
124
- const tableContainerRef = useRef<HTMLElement>(null);
125
117
 
126
118
  const tableColumns: ColumnDefinition<TData>[] = useMemo(() => {
127
119
  let cols: ColumnDefinition<TData>[] = columnDefinitions;
@@ -145,7 +137,6 @@ export function Table<TData extends object>({
145
137
  const table = useReactTable<TData>({
146
138
  data,
147
139
  columns: tableColumns,
148
-
149
140
  state: {
150
141
  columnPinning,
151
142
  globalFilter,
@@ -159,7 +150,7 @@ export function Table<TData extends object>({
159
150
  enableSorting: false,
160
151
  enableResizing: false,
161
152
  minSize: 40,
162
- cell: truncateCell,
153
+ cell: (cell: CellContext<TData, unknown>) => <TruncateString text={String(cell.getValue())} maxLines={1} />,
163
154
  },
164
155
 
165
156
  manualSorting,
@@ -186,12 +177,6 @@ export function Table<TData extends object>({
186
177
  getCoreRowModel: getCoreRowModel(),
187
178
  columnResizeMode: 'onEnd',
188
179
  keepPinnedRows,
189
-
190
- meta: {
191
- tableContainerRef,
192
- rowVirtualizerInstanceRef,
193
- rowVirtualizerOptions,
194
- },
195
180
  });
196
181
 
197
182
  const { loadingTable } = useLoadingTable({
@@ -239,11 +224,9 @@ export function Table<TData extends object>({
239
224
  const columnSizeVarsRef = useRef<Record<string, string>>();
240
225
  const headers = table.getFlatHeaders();
241
226
 
242
- const rowVirtualizer = useRowVirtualizer(table, Boolean(enableRowVirtualization));
243
-
244
- const cssSizeVars = useMemo(() => {
227
+ const columnSizeVars = useMemo(() => {
245
228
  const originalColumnDefs = table._getColumnDefs();
246
- const colSizes: Record<string, string> = rowVirtualizer ? { height: `${rowVirtualizer.getTotalSize()}px` } : {};
229
+ const colSizes: Record<string, string> = {};
247
230
 
248
231
  for (let i = 0; i < headers.length; i++) {
249
232
  const header = headers[i];
@@ -308,8 +291,8 @@ export function Table<TData extends object>({
308
291
  }, [table.getState().columnSizingInfo.isResizingColumn, headers, table.getTotalSize()]);
309
292
 
310
293
  useEffect(() => {
311
- columnSizeVarsRef.current = cssSizeVars;
312
- }, [cssSizeVars]);
294
+ columnSizeVarsRef.current = columnSizeVars;
295
+ }, [columnSizeVars]);
313
296
 
314
297
  const tableRows = table.getRowModel().rows;
315
298
  const tableCenterRows = table.getCenterRows();
@@ -333,8 +316,6 @@ export function Table<TData extends object>({
333
316
  return !tableRows.length ? Math.min(Math.max(tempPageSize, 5), DEFAULT_PAGE_SIZE) : tempPageSize;
334
317
  }, [filteredTopRows.length, pageSize, suppressPagination, tablePagination?.pageSize, tableRows.length]);
335
318
 
336
- const tableCtx = useMemo(() => ({ table }), [table]);
337
-
338
319
  usePageReset({
339
320
  manualPagination,
340
321
  maximumAvailablePage: pageCount || data.length / pagination.pageSize,
@@ -394,9 +375,9 @@ export function Table<TData extends object>({
394
375
  )}
395
376
 
396
377
  <div className={styles.scrollWrapper} data-outline={outline || undefined}>
397
- <Scroll size='s' className={styles.table} ref={mergeRefs(tableContainerRef, scrollContainerRef)}>
398
- <div className={styles.tableContent} style={cssSizeVars}>
399
- <TableContext.Provider value={tableCtx}>
378
+ <Scroll size='s' className={styles.table} ref={scrollContainerRef}>
379
+ <div className={styles.tableContent} style={columnSizeVars}>
380
+ <TableContext.Provider value={{ table }}>
400
381
  {loading ? (
401
382
  <SkeletonContextProvider loading>
402
383
  <HeaderRow />
@@ -415,20 +396,9 @@ export function Table<TData extends object>({
415
396
  </div>
416
397
  ) : null}
417
398
 
418
- {(rowVirtualizer?.getVirtualItems() ?? centerRows).map((rowOrVirtualRow, index) => {
419
- const row = isVirtualRow(rowOrVirtualRow) ? centerRows[rowOrVirtualRow.index] : centerRows[index];
420
-
421
- return (
422
- <VirtualRow
423
- key={row.id}
424
- ref={rowVirtualizer?.measureElement}
425
- data-index={row.index}
426
- virtualRow={isVirtualRow(rowOrVirtualRow) ? rowOrVirtualRow : undefined}
427
- >
428
- <BodyRow row={row} onRowClick={onRowClick} />
429
- </VirtualRow>
430
- );
431
- })}
399
+ {centerRows.map(row => (
400
+ <BodyRow key={row.id} row={row} onRowClick={onRowClick} />
401
+ ))}
432
402
 
433
403
  <TableEmptyState
434
404
  emptyStates={emptyStates}
@@ -459,5 +429,5 @@ export function Table<TData extends object>({
459
429
  }
460
430
 
461
431
  Table.getStatusColumnDef = getStatusColumnDef;
462
- Table.getRowActionsColumnDef = getRowActionsColumnDef;
463
432
  Table.statusAppearances = STATUS_APPEARANCE;
433
+ Table.getRowActionsColumnDef = getRowActionsColumnDef;
@@ -2,15 +2,11 @@
2
2
 
3
3
  .table {
4
4
  @include styles-tokens-table.composite-var(styles-tokens-table.$table-table-container);
5
-
6
- will-change: transform;
7
5
 
8
6
  position: relative;
9
7
  /* stylelint-disable-next-line declaration-property-value-allowed-list */
10
8
  z-index: 0;
11
9
 
12
- contain: paint;
13
-
14
10
  /* stylelint-disable-next-line declaration-no-important */
15
11
  overflow: hidden !important;
16
12
  display: flex;
@@ -43,7 +39,6 @@
43
39
  }
44
40
 
45
41
  .tableContent {
46
- content-visibility: auto;
47
42
  min-width: max-content;
48
43
  }
49
44
 
@@ -1,7 +1,3 @@
1
- import { CellContext } from '@tanstack/react-table';
2
- import { VirtualItem } from '@tanstack/react-virtual';
3
-
4
- import { TruncateString } from '@snack-uikit/truncate-string';
5
1
  import { isBrowser } from '@snack-uikit/utils';
6
2
 
7
3
  export function getCurrentlyConfiguredHeaderWidth(id: string): number {
@@ -62,17 +58,3 @@ export function saveStateToLocalStorage({ id, columnId, size }: SaveStateToLocal
62
58
 
63
59
  localStorage.setItem(id, JSON.stringify({ ...(savedStateFromStorage || {}), resizeState: newResizeState }));
64
60
  }
65
-
66
- /**
67
- * check the key, because index is contained in a common table row
68
- */
69
- export function isVirtualRow(row: unknown): row is VirtualItem {
70
- return typeof row === 'object' && row != null && 'key' in row;
71
- }
72
-
73
- /**
74
- * @description prevent permanent recreation of the function on rerender
75
- */
76
- export function truncateCell<TData>(cell: CellContext<TData, unknown>) {
77
- return <TruncateString text={String(cell.getValue())} maxLines={1} />;
78
- }
@@ -6,8 +6,7 @@ import {
6
6
  RowSelectionState,
7
7
  SortingState,
8
8
  } from '@tanstack/react-table';
9
- import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
10
- import { MutableRefObject, ReactNode, RefObject } from 'react';
9
+ import { ReactNode, RefObject } from 'react';
11
10
 
12
11
  import { ToolbarProps } from '@snack-uikit/toolbar';
13
12
  import { WithSupportProps } from '@snack-uikit/utils';
@@ -162,13 +161,6 @@ export type TableProps<TData extends object> = WithSupportProps<{
162
161
  id: string;
163
162
  resize?: boolean;
164
163
  };
165
-
166
- // Включение виртуализации для строк
167
- enableRowVirtualization?: boolean;
168
- // Кастомные параметры для виртуализации строк
169
- rowVirtualizerOptions?: Parameters<typeof useVirtualizer>[0];
170
- // Ссылка на экземпляр виртуализатора строк.
171
- rowVirtualizerInstanceRef?: MutableRefObject<Virtualizer<Element, Element> | null>;
172
164
  }>;
173
165
 
174
166
  export type ServerTableProps<TData extends object> = Omit<
@@ -1,5 +1,5 @@
1
1
  import { Row as TableRow } from '@tanstack/react-table';
2
- import { CSSProperties, forwardRef, MouseEvent, Ref, useState } from 'react';
2
+ import { MouseEvent, useState } from 'react';
3
3
 
4
4
  import { COLUMN_PIN_POSITION, TEST_IDS } from '../../constants';
5
5
  import { BodyCell } from '../Cells';
@@ -21,64 +21,58 @@ export type RowClickHandler<TData> = (e: MouseEvent<HTMLDivElement>, row: RowInf
21
21
  type BodyRowProps<TData> = {
22
22
  row: TableRow<TData>;
23
23
  onRowClick?: RowClickHandler<TData>;
24
- style?: CSSProperties;
25
24
  };
26
25
 
27
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
- export const BodyRow = forwardRef<HTMLDivElement, BodyRowProps<any>>(
29
- <TData,>({ row, onRowClick, ...attributes }: BodyRowProps<TData>, ref: Ref<HTMLDivElement>) => {
30
- const { pinnedLeft, pinnedRight, unpinned } = useRowCells(row);
26
+ export function BodyRow<TData>({ row, onRowClick }: BodyRowProps<TData>) {
27
+ const { pinnedLeft, pinnedRight, unpinned } = useRowCells(row);
31
28
 
32
- const [dropListOpened, setDropListOpen] = useState(false);
29
+ const [dropListOpened, setDropListOpen] = useState(false);
33
30
 
34
- const disabled = !row.getCanSelect();
31
+ const disabled = !row.getCanSelect();
35
32
 
36
- const handleRowClick = (e: MouseEvent<HTMLDivElement>) => {
37
- if (disabled) return;
33
+ const handleRowClick = (e: MouseEvent<HTMLDivElement>) => {
34
+ if (disabled) return;
38
35
 
39
- onRowClick?.(e, {
40
- id: row.id,
41
- data: row.original,
42
- selected: row.getIsSelected(),
43
- toggleSelected: row.toggleSelected,
44
- });
45
- };
36
+ onRowClick?.(e, {
37
+ id: row.id,
38
+ data: row.original,
39
+ selected: row.getIsSelected(),
40
+ toggleSelected: row.toggleSelected,
41
+ });
42
+ };
46
43
 
47
- return (
48
- <RowContext.Provider value={{ dropListOpened, setDropListOpen }}>
49
- <Row
50
- {...attributes}
51
- ref={ref}
52
- onClick={handleRowClick}
53
- data-clickable={Boolean(onRowClick) || undefined}
54
- data-disabled={disabled || undefined}
55
- data-selected={row.getIsSelected() || undefined}
56
- data-actions-opened={dropListOpened || undefined}
57
- data-test-id={TEST_IDS.bodyRow}
58
- data-row-id={row.id}
59
- className={styles.bodyRow}
60
- >
61
- {pinnedLeft && (
62
- <PinnedCells position={COLUMN_PIN_POSITION.Left}>
63
- {pinnedLeft.map(cell => (
64
- <BodyCell key={cell.id} cell={cell} />
65
- ))}
66
- </PinnedCells>
67
- )}
44
+ return (
45
+ <RowContext.Provider value={{ dropListOpened, setDropListOpen }}>
46
+ <Row
47
+ onClick={handleRowClick}
48
+ data-clickable={Boolean(onRowClick) || undefined}
49
+ data-disabled={disabled || undefined}
50
+ data-selected={row.getIsSelected() || undefined}
51
+ data-actions-opened={dropListOpened || undefined}
52
+ data-test-id={TEST_IDS.bodyRow}
53
+ data-row-id={row.id}
54
+ className={styles.bodyRow}
55
+ >
56
+ {pinnedLeft && (
57
+ <PinnedCells position={COLUMN_PIN_POSITION.Left}>
58
+ {pinnedLeft.map(cell => (
59
+ <BodyCell key={cell.id} cell={cell} />
60
+ ))}
61
+ </PinnedCells>
62
+ )}
68
63
 
69
- {unpinned.map(cell => (
70
- <BodyCell key={cell.id} cell={cell} />
71
- ))}
64
+ {unpinned.map(cell => (
65
+ <BodyCell key={cell.id} cell={cell} />
66
+ ))}
72
67
 
73
- {pinnedRight && (
74
- <PinnedCells position={COLUMN_PIN_POSITION.Right}>
75
- {pinnedRight.map(cell => (
76
- <BodyCell key={cell.id} cell={cell} />
77
- ))}
78
- </PinnedCells>
79
- )}
80
- </Row>
81
- </RowContext.Provider>
82
- );
83
- },
84
- );
68
+ {pinnedRight && (
69
+ <PinnedCells position={COLUMN_PIN_POSITION.Right}>
70
+ {pinnedRight.map(cell => (
71
+ <BodyCell key={cell.id} cell={cell} />
72
+ ))}
73
+ </PinnedCells>
74
+ )}
75
+ </Row>
76
+ </RowContext.Provider>
77
+ );
78
+ }
@@ -1,5 +1,5 @@
1
1
  import cn from 'classnames';
2
- import { CSSProperties, forwardRef, MouseEvent, ReactNode } from 'react';
2
+ import { MouseEvent, ReactNode } from 'react';
3
3
 
4
4
  import { DataAttributes } from '../types';
5
5
  import styles from './styles.module.scss';
@@ -8,12 +8,13 @@ type RowProps = {
8
8
  children: ReactNode;
9
9
  onClick?(e: MouseEvent<HTMLDivElement>): void;
10
10
  className?: string;
11
- style?: CSSProperties;
12
11
  } & DataAttributes;
13
12
 
14
- export const Row = forwardRef<HTMLDivElement, RowProps>(({ onClick, children, className, ...attributes }, ref) => (
15
- // eslint-disable-next-line jsx-a11y/interactive-supports-focus
16
- <div ref={ref} onClick={onClick} className={cn(styles.tableRow, className)} role='row' {...attributes}>
17
- {children}
18
- </div>
19
- ));
13
+ export function Row({ onClick, children, className, ...attributes }: RowProps) {
14
+ return (
15
+ // eslint-disable-next-line jsx-a11y/interactive-supports-focus
16
+ <div onClick={onClick} className={cn(styles.tableRow, className)} role='row' {...attributes}>
17
+ {children}
18
+ </div>
19
+ );
20
+ }
@@ -1,2 +0,0 @@
1
- import { Table } from '@tanstack/react-table';
2
- export declare function useRowVirtualizer(table: Table<any>, enabled: boolean): import("@tanstack/virtual-core").Virtualizer<Element, Element> | undefined;
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useRowVirtualizer = useRowVirtualizer;
7
- const react_virtual_1 = require("@tanstack/react-virtual");
8
- const react_1 = require("react");
9
- const utils_1 = require("@snack-uikit/utils");
10
- /**
11
- * If virtualization is disabled
12
- */
13
- const useNoopVirtualizerFn = () => undefined;
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- function useRowVirtualizer(table, enabled) {
16
- var _a;
17
- const {
18
- getRowModel,
19
- options
20
- } = table;
21
- const {
22
- rowVirtualizerInstanceRef,
23
- rowVirtualizerOptions,
24
- tableContainerRef
25
- } = (_a = options.meta) !== null && _a !== void 0 ? _a : {};
26
- // TODO
27
- const [_, forceUpdate] = (0, react_1.useReducer)(x => x + 1, 0);
28
- const useVirtualizerFn = enabled ? react_virtual_1.useVirtualizer : useNoopVirtualizerFn;
29
- const normalRowHeight = 40;
30
- const rowVirtualizer = useVirtualizerFn(Object.assign({
31
- count: getRowModel().rows.length,
32
- estimateSize: () => normalRowHeight,
33
- getScrollElement: () => tableContainerRef.current,
34
- measureElement: typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1 ? element => element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height : undefined,
35
- overscan: 28
36
- }, rowVirtualizerOptions));
37
- // TODO
38
- (0, utils_1.useLayoutEffect)(() => {
39
- if (enabled) forceUpdate();
40
- }, [enabled]);
41
- if ((rowVirtualizerInstanceRef === null || rowVirtualizerInstanceRef === void 0 ? void 0 : rowVirtualizerInstanceRef.current) && rowVirtualizer) {
42
- rowVirtualizerInstanceRef.current = rowVirtualizer;
43
- }
44
- return rowVirtualizer;
45
- }
@@ -1,7 +0,0 @@
1
- import { VirtualItem } from '@tanstack/react-virtual';
2
- import { HTMLAttributes } from 'react';
3
- export declare const VirtualRow: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & {
4
- virtualRow?: VirtualItem;
5
- } & {
6
- children?: import("react").ReactNode | undefined;
7
- } & import("react").RefAttributes<HTMLDivElement>>;
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- var __rest = void 0 && (void 0).__rest || function (s, e) {
4
- var t = {};
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
8
- }
9
- return t;
10
- };
11
- Object.defineProperty(exports, "__esModule", {
12
- value: true
13
- });
14
- exports.VirtualRow = void 0;
15
- const jsx_runtime_1 = require("react/jsx-runtime");
16
- const react_1 = require("react");
17
- exports.VirtualRow = (0, react_1.forwardRef)((_a, ref) => {
18
- var {
19
- virtualRow,
20
- children
21
- } = _a,
22
- attributes = __rest(_a, ["virtualRow", "children"]);
23
- if (!virtualRow) {
24
- return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {
25
- children: children
26
- });
27
- }
28
- return (0, jsx_runtime_1.jsx)("div", Object.assign({
29
- ref: ref,
30
- style: virtualRow ? {
31
- position: 'absolute',
32
- top: 0,
33
- left: 0,
34
- width: '100%',
35
- transform: `translateY(${virtualRow.start}px)`
36
- } : undefined
37
- }, attributes, {
38
- children: children
39
- }));
40
- });
@@ -1,2 +0,0 @@
1
- import { Table } from '@tanstack/react-table';
2
- export declare function useRowVirtualizer(table: Table<any>, enabled: boolean): import("@tanstack/virtual-core").Virtualizer<Element, Element> | undefined;