@snack-uikit/table 0.39.6 → 0.39.7-preview-4aaa5650.0

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.
package/README.md CHANGED
@@ -117,7 +117,7 @@ const columnDefinitions: ColumnDefinition<TableData>[] = [
117
117
  | name | type | default value | description |
118
118
  |------|------|---------------|-------------|
119
119
  | columnSettings* | `{ enableDrag?: boolean; enableSettingsMenu?: boolean; }` | - | |
120
- | savedState* | `Pick<ToolbarPersistConfig<Record<string, unknown>>, "serializer" \| "parser"> & { id: string; filterQueryKey?: string; resize?: boolean; columnSettings?: boolean; }` | - | |
120
+ | savedState* | `Pick<ToolbarPersistConfig<TFilters>, "serializer" \| "parser"> & { id: string; filterQueryKey?: string; resize?: boolean; columnSettings?: boolean; }` | - | |
121
121
  | tableColumns* | `ColumnDefinition<TData>[]` | - | |
122
122
  ## useColumnSettings
123
123
  ### Props
@@ -168,8 +168,6 @@ const columnDefinitions: ColumnDefinition<TableData>[] = [
168
168
  ### Props
169
169
  | name | type | default value | description |
170
170
  |------|------|---------------|-------------|
171
- | filter | `FiltersState` | - | |
172
- | search | `string` | - | |
173
171
  | pagination | `PaginationState \| PaginationParams` | - | |
174
172
  | sorting | `SortingState` | - | |
175
173
  ## Table
@@ -2,31 +2,31 @@ import { CellContext } from '@tanstack/react-table';
2
2
  import { ReactNode } from 'react';
3
3
  import { RowAppearance } from '../../../components';
4
4
  import { ColumnDefinition } from '../../../types';
5
- type BaseTreeColumnDef = {
5
+ type BaseTreeColumnDef<TData> = {
6
6
  /** Имя ключа соответствующее полю в data */
7
7
  accessorKey: string;
8
8
  /** Иконка элемента-родителя в открытом состоянии */
9
- expandedIcon?: ReactNode;
9
+ expandedIcon?: ReactNode | ((ctx: CellContext<TData, unknown>) => ReactNode);
10
10
  /** Иконка элемента-родителя в закрытом состоянии */
11
- collapsedIcon?: ReactNode;
11
+ collapsedIcon?: ReactNode | ((ctx: CellContext<TData, unknown>) => ReactNode);
12
12
  /** Иконка дочернего */
13
- icon?: ReactNode;
13
+ icon?: ReactNode | ((ctx: CellContext<TData, unknown>) => ReactNode);
14
14
  /** Иконка дочернего элемента */
15
15
  showToggle?: boolean;
16
16
  /** Минимальный размер ячейки */
17
17
  minSize?: number;
18
18
  };
19
- type TreeColumnDef = BaseTreeColumnDef & {
19
+ type TreeColumnDef<TData> = BaseTreeColumnDef<TData> & {
20
20
  header?: never;
21
21
  cell?: never;
22
22
  };
23
- type TreeColumnDefWithDescription<TData> = BaseTreeColumnDef & {
23
+ type TreeColumnDefWithDescription<TData> = BaseTreeColumnDef<TData> & {
24
24
  /** Заголовок колонки */
25
25
  cell?(ctx: CellContext<TData, unknown>): ReactNode;
26
26
  /** Рендер функция заголовка колонки */
27
27
  header?: ColumnDefinition<TData>['header'];
28
28
  };
29
- export type TreeColumnDefinitionProps<TData> = TreeColumnDef | TreeColumnDefWithDescription<TData>;
29
+ export type TreeColumnDefinitionProps<TData> = TreeColumnDef<TData> | TreeColumnDefWithDescription<TData>;
30
30
  type TreeColDefProps<TData> = TreeColumnDefinitionProps<TData> & {
31
31
  enableSelection?: boolean;
32
32
  rowSelectionAppearance?: RowAppearance;
@@ -121,6 +121,9 @@ function getTreeColumnDef(_ref) {
121
121
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
122
122
  // @ts-ignore
123
123
  cell.row.original[accessorKey] : cell.getValue();
124
+ const iconNode = typeof icon === 'function' ? icon(ctx) : icon;
125
+ const expandedIconNode = typeof expandedIcon === 'function' ? expandedIcon(ctx) : expandedIcon;
126
+ const collapsedIconNode = typeof collapsedIcon === 'function' ? collapsedIcon(ctx) : collapsedIcon;
124
127
  return (0, jsx_runtime_1.jsx)("div", {
125
128
  role: 'presentation',
126
129
  "data-test-id": constants_1.TEST_IDS.tree.node,
@@ -163,11 +166,11 @@ function getTreeColumnDef(_ref) {
163
166
  role: 'presentation',
164
167
  onClick: chevronClickHandler,
165
168
  className: styles_module_scss_1.default.cellUserToggleIcon,
166
- children: [isExpandable && isExpanded && expandedIcon, isExpandable && !isExpanded && collapsedIcon]
169
+ children: [isExpandable && isExpanded && expandedIconNode, isExpandable && !isExpanded && collapsedIconNode]
167
170
  }), (0, jsx_runtime_1.jsxs)("div", {
168
171
  role: 'presentation',
169
172
  className: styles_module_scss_1.default.userContent,
170
- children: [!isExpandable && icon, renderCell ? renderCell(ctx) : (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, {
173
+ children: [!isExpandable && iconNode, renderCell ? renderCell(ctx) : (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, {
171
174
  text: value
172
175
  })]
173
176
  })]
@@ -2,31 +2,31 @@ import { CellContext } from '@tanstack/react-table';
2
2
  import { ReactNode } from 'react';
3
3
  import { RowAppearance } from '../../../components';
4
4
  import { ColumnDefinition } from '../../../types';
5
- type BaseTreeColumnDef = {
5
+ type BaseTreeColumnDef<TData> = {
6
6
  /** Имя ключа соответствующее полю в data */
7
7
  accessorKey: string;
8
8
  /** Иконка элемента-родителя в открытом состоянии */
9
- expandedIcon?: ReactNode;
9
+ expandedIcon?: ReactNode | ((ctx: CellContext<TData, unknown>) => ReactNode);
10
10
  /** Иконка элемента-родителя в закрытом состоянии */
11
- collapsedIcon?: ReactNode;
11
+ collapsedIcon?: ReactNode | ((ctx: CellContext<TData, unknown>) => ReactNode);
12
12
  /** Иконка дочернего */
13
- icon?: ReactNode;
13
+ icon?: ReactNode | ((ctx: CellContext<TData, unknown>) => ReactNode);
14
14
  /** Иконка дочернего элемента */
15
15
  showToggle?: boolean;
16
16
  /** Минимальный размер ячейки */
17
17
  minSize?: number;
18
18
  };
19
- type TreeColumnDef = BaseTreeColumnDef & {
19
+ type TreeColumnDef<TData> = BaseTreeColumnDef<TData> & {
20
20
  header?: never;
21
21
  cell?: never;
22
22
  };
23
- type TreeColumnDefWithDescription<TData> = BaseTreeColumnDef & {
23
+ type TreeColumnDefWithDescription<TData> = BaseTreeColumnDef<TData> & {
24
24
  /** Заголовок колонки */
25
25
  cell?(ctx: CellContext<TData, unknown>): ReactNode;
26
26
  /** Рендер функция заголовка колонки */
27
27
  header?: ColumnDefinition<TData>['header'];
28
28
  };
29
- export type TreeColumnDefinitionProps<TData> = TreeColumnDef | TreeColumnDefWithDescription<TData>;
29
+ export type TreeColumnDefinitionProps<TData> = TreeColumnDef<TData> | TreeColumnDefWithDescription<TData>;
30
30
  type TreeColDefProps<TData> = TreeColumnDefinitionProps<TData> & {
31
31
  enableSelection?: boolean;
32
32
  rowSelectionAppearance?: RowAppearance;
@@ -84,7 +84,10 @@ export function getTreeColumnDef({ showToggle = false, icon = _jsx(FileSVG, { si
84
84
  // @ts-ignore
85
85
  cell.row.original[accessorKey]
86
86
  : cell.getValue();
87
- return (_jsx("div", { role: 'presentation', "data-test-id": TEST_IDS.tree.node, className: styles.treeCellContainer, onClick: toggleClickHandler, children: _jsxs("div", { className: styles.treeCell, ref: ref, children: [lines, Boolean(parent) && _jsx(TreeLine, { horizontal: true, visible: true }), isExpandable && (_jsx(ButtonFunction, { size: 'xs', "data-test-id": TEST_IDS.tree.chevron, icon: _jsx(ChevronRightSVG, {}), onClick: chevronClickHandler, className: styles.cellExpandButton, "data-expanded": isExpanded || undefined })), _jsxs("div", { className: styles.treeNodeContent, "data-disabled": !isRowsSelectionEnabled || undefined, "data-selected": isRowSelected || undefined, "data-multiselect": isMultiSelect || undefined, children: [showToggle && !isToggleHidden && (_jsx("div", { tabIndex: -1, className: styles.treeCheckboxWrap, children: isMultiSelect ? (_jsx(Checkbox, { size: 's', disabled: !isRowsSelectionEnabled, checked: isRowSelected, "data-test-id": TEST_IDS.tree.checkbox, indeterminate: isSomeSubRowSelected && !isAllSubRowsSelected })) : (_jsx(Radio, { size: 's', disabled: !isRowsSelectionEnabled, "data-test-id": TEST_IDS.tree.radio, checked: isRowSelected })) })), _jsxs("div", { role: 'presentation', onClick: chevronClickHandler, className: styles.cellUserToggleIcon, children: [isExpandable && isExpanded && expandedIcon, isExpandable && !isExpanded && collapsedIcon] }), _jsxs("div", { role: 'presentation', className: styles.userContent, children: [!isExpandable && icon, renderCell ? renderCell(ctx) : _jsx(TruncateString, { text: value })] })] })] }) }));
87
+ const iconNode = typeof icon === 'function' ? icon(ctx) : icon;
88
+ const expandedIconNode = typeof expandedIcon === 'function' ? expandedIcon(ctx) : expandedIcon;
89
+ const collapsedIconNode = typeof collapsedIcon === 'function' ? collapsedIcon(ctx) : collapsedIcon;
90
+ return (_jsx("div", { role: 'presentation', "data-test-id": TEST_IDS.tree.node, className: styles.treeCellContainer, onClick: toggleClickHandler, children: _jsxs("div", { className: styles.treeCell, ref: ref, children: [lines, Boolean(parent) && _jsx(TreeLine, { horizontal: true, visible: true }), isExpandable && (_jsx(ButtonFunction, { size: 'xs', "data-test-id": TEST_IDS.tree.chevron, icon: _jsx(ChevronRightSVG, {}), onClick: chevronClickHandler, className: styles.cellExpandButton, "data-expanded": isExpanded || undefined })), _jsxs("div", { className: styles.treeNodeContent, "data-disabled": !isRowsSelectionEnabled || undefined, "data-selected": isRowSelected || undefined, "data-multiselect": isMultiSelect || undefined, children: [showToggle && !isToggleHidden && (_jsx("div", { tabIndex: -1, className: styles.treeCheckboxWrap, children: isMultiSelect ? (_jsx(Checkbox, { size: 's', disabled: !isRowsSelectionEnabled, checked: isRowSelected, "data-test-id": TEST_IDS.tree.checkbox, indeterminate: isSomeSubRowSelected && !isAllSubRowsSelected })) : (_jsx(Radio, { size: 's', disabled: !isRowsSelectionEnabled, "data-test-id": TEST_IDS.tree.radio, checked: isRowSelected })) })), _jsxs("div", { role: 'presentation', onClick: chevronClickHandler, className: styles.cellUserToggleIcon, children: [isExpandable && isExpanded && expandedIconNode, isExpandable && !isExpanded && collapsedIconNode] }), _jsxs("div", { role: 'presentation', className: styles.userContent, children: [!isExpandable && iconNode, renderCell ? renderCell(ctx) : _jsx(TruncateString, { text: value })] })] })] }) }));
88
91
  };
89
92
  return {
90
93
  id: TREE_CELL_ID,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Table",
7
- "version": "0.39.6",
7
+ "version": "0.39.7-preview-4aaa5650.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -65,5 +65,5 @@
65
65
  "peerDependencies": {
66
66
  "@snack-uikit/locale": "*"
67
67
  },
68
- "gitHead": "9e6abdd71a846caf1f1252b9504560a3b796942f"
68
+ "gitHead": "4bd6ac456b2bc3af92d4b718403c9da9dd6512a8"
69
69
  }
@@ -14,34 +14,34 @@ import { TREE_CELL_ID } from './constants';
14
14
  import styles from './styles.module.scss';
15
15
  import { TreeLine } from './TreeLine';
16
16
 
17
- type BaseTreeColumnDef = {
17
+ type BaseTreeColumnDef<TData> = {
18
18
  /** Имя ключа соответствующее полю в data */
19
19
  accessorKey: string;
20
20
  /** Иконка элемента-родителя в открытом состоянии */
21
- expandedIcon?: ReactNode;
21
+ expandedIcon?: ReactNode | ((ctx: CellContext<TData, unknown>) => ReactNode);
22
22
  /** Иконка элемента-родителя в закрытом состоянии */
23
- collapsedIcon?: ReactNode;
23
+ collapsedIcon?: ReactNode | ((ctx: CellContext<TData, unknown>) => ReactNode);
24
24
  /** Иконка дочернего */
25
- icon?: ReactNode;
25
+ icon?: ReactNode | ((ctx: CellContext<TData, unknown>) => ReactNode);
26
26
  /** Иконка дочернего элемента */
27
27
  showToggle?: boolean;
28
28
  /** Минимальный размер ячейки */
29
29
  minSize?: number;
30
30
  };
31
31
 
32
- type TreeColumnDef = BaseTreeColumnDef & {
32
+ type TreeColumnDef<TData> = BaseTreeColumnDef<TData> & {
33
33
  header?: never;
34
34
  cell?: never;
35
35
  };
36
36
 
37
- type TreeColumnDefWithDescription<TData> = BaseTreeColumnDef & {
37
+ type TreeColumnDefWithDescription<TData> = BaseTreeColumnDef<TData> & {
38
38
  /** Заголовок колонки */
39
39
  cell?(ctx: CellContext<TData, unknown>): ReactNode;
40
40
  /** Рендер функция заголовка колонки */
41
41
  header?: ColumnDefinition<TData>['header'];
42
42
  };
43
43
 
44
- export type TreeColumnDefinitionProps<TData> = TreeColumnDef | TreeColumnDefWithDescription<TData>;
44
+ export type TreeColumnDefinitionProps<TData> = TreeColumnDef<TData> | TreeColumnDefWithDescription<TData>;
45
45
 
46
46
  type TreeColDefProps<TData> = TreeColumnDefinitionProps<TData> & {
47
47
  enableSelection?: boolean;
@@ -163,6 +163,10 @@ export function getTreeColumnDef<TData>({
163
163
  cell.row.original[accessorKey]
164
164
  : cell.getValue<string>();
165
165
 
166
+ const iconNode = typeof icon === 'function' ? icon(ctx) : icon;
167
+ const expandedIconNode = typeof expandedIcon === 'function' ? expandedIcon(ctx) : expandedIcon;
168
+ const collapsedIconNode = typeof collapsedIcon === 'function' ? collapsedIcon(ctx) : collapsedIcon;
169
+
166
170
  return (
167
171
  <div
168
172
  role={'presentation'}
@@ -210,11 +214,11 @@ export function getTreeColumnDef<TData>({
210
214
  </div>
211
215
  )}
212
216
  <div role='presentation' onClick={chevronClickHandler} className={styles.cellUserToggleIcon}>
213
- {isExpandable && isExpanded && expandedIcon}
214
- {isExpandable && !isExpanded && collapsedIcon}
217
+ {isExpandable && isExpanded && expandedIconNode}
218
+ {isExpandable && !isExpanded && collapsedIconNode}
215
219
  </div>
216
220
  <div role='presentation' className={styles.userContent}>
217
- {!isExpandable && icon}
221
+ {!isExpandable && iconNode}
218
222
 
219
223
  {renderCell ? renderCell(ctx) : <TruncateString text={value} />}
220
224
  </div>