@snack-uikit/tree 0.2.2 → 0.3.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,29 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 0.3.1 (2023-12-14)
7
+
8
+ ### Only dependencies have been changed
9
+ * [@snack-uikit/droplist@0.12.1](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/droplist/CHANGELOG.md)
10
+ * [@snack-uikit/icons@0.19.1](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/icons/CHANGELOG.md)
11
+ * [@snack-uikit/toggles@0.9.1](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/toggles/CHANGELOG.md)
12
+ * [@snack-uikit/truncate-string@0.4.1](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/truncate-string/CHANGELOG.md)
13
+
14
+
15
+
16
+
17
+
18
+ # 0.3.0 (2023-12-14)
19
+
20
+
21
+ ### BREAKING CHANGES
22
+
23
+
24
+ * **FF-3729:** replace enum with unions ([910db4a](https://github.com/cloud-ru-tech/snack-uikit/commit/910db4aa8231ccbc58e538e5c5c1f461b1dec275))
25
+
26
+
27
+
28
+
6
29
  ## 0.2.2 (2023-12-07)
7
30
 
8
31
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Example
9
9
 
10
- #### selectionMode = Tree.selectionModes.Single
10
+ #### selectionMode = 'single'
11
11
 
12
12
  ```typescript jsx
13
13
  import { Tree } from '@snack-uikit/tree';
@@ -18,10 +18,11 @@ const [selectedNode, setSelected] = useState<TreeNodeId>();
18
18
 
19
19
  // ...
20
20
 
21
- <Tree data={data} selectionMode={Tree.selectionModes.Single} selected={selectedNode} onSelect={setSelected} />
21
+ <Tree data={data} selectionMode='single' selected={selectedNode} onSelect={setSelected} />
22
22
  ```
23
23
 
24
- #### selectionMode = Tree.selectionModes.Multi
24
+ #### selectionMode = 'multi'
25
+
25
26
  ```typescript jsx
26
27
  import { Tree } from '@snack-uikit/tree';
27
28
 
@@ -31,7 +32,7 @@ const [selectedNodes, setSelected] = useState<TreeNodeId[]>([]);
31
32
 
32
33
  // ...
33
34
 
34
- <Tree data={data} selectionMode={Tree.selectionModes.Multi} selected={selectedNodes} onSelect={setSelected} />
35
+ <Tree data={data} selectionMode='multi' selected={selectedNodes} onSelect={setSelected} />
35
36
  ```
36
37
 
37
38
 
@@ -42,7 +43,7 @@ const [selectedNodes, setSelected] = useState<TreeNodeId[]>([]);
42
43
  | name | type | default value | description |
43
44
  |------|------|---------------|-------------|
44
45
  | data* | `TreeNodeProps[]` | - | Данные для отрисовки |
45
- | selectionMode | enum SelectionMode: `"single"`, `"multi"` | - | Режим выбора элементов: <br> - `Single` - одиночный выбор <br> - `Multi` - множественный выбор |
46
+ | selectionMode | "single" \| "multi" | - | Режим выбора элементов: <br> - `Single` - одиночный выбор <br> - `Multi` - множественный выбор |
46
47
  | onNodeClick | `OnNodeClick` | - | Обработчик клика по элементу дерева |
47
48
  | expandedNodes | `string[]` | - | Состояние для раскрытых элементов |
48
49
  | onExpand | `(expandedKeys: string[], nodeId: string) => void` | - | Колбэк при раскрытии/закрытии элементов |
@@ -1,8 +1,4 @@
1
1
  import { WithSupportProps } from '@snack-uikit/utils';
2
- import { SelectionMode } from '../../constants';
3
2
  import { TreeBaseProps } from '../../types';
4
3
  export type TreeProps = WithSupportProps<TreeBaseProps>;
5
4
  export declare function Tree({ data, selected, selectionMode, onSelect, onNodeClick, onExpand, expandedNodes, nodeActions, parentActions, onDataLoad, showLines, className, ...rest }: TreeProps): import("react/jsx-runtime").JSX.Element;
6
- export declare namespace Tree {
7
- var selectionModes: typeof SelectionMode;
8
- }
@@ -12,13 +12,12 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import cn from 'classnames';
14
14
  import { extractSupportProps } from '@snack-uikit/utils';
15
- import { SelectionMode } from '../../constants';
16
15
  import { TreeContextProvider } from '../../contexts/TreeContext';
17
16
  import { TreeItem } from '../../helperComponents';
18
17
  import styles from './styles.module.css';
19
18
  export function Tree(_a) {
20
19
  var { data, selected, selectionMode, onSelect, onNodeClick, onExpand, expandedNodes, nodeActions, parentActions, onDataLoad, showLines = true, className } = _a, rest = __rest(_a, ["data", "selected", "selectionMode", "onSelect", "onNodeClick", "onExpand", "expandedNodes", "nodeActions", "parentActions", "onDataLoad", "showLines", "className"]);
21
- return (_jsx("div", Object.assign({ className: cn(styles.tree, className), role: 'tree' }, extractSupportProps(rest), { children: _jsx(TreeContextProvider, Object.assign({ value: {
20
+ return (_jsx("div", Object.assign({ className: cn(styles.tree, className), role: 'tree' }, extractSupportProps(rest), { children: _jsx(TreeContextProvider, { value: {
22
21
  data,
23
22
  selected: selected,
24
23
  selectionMode: selectionMode,
@@ -30,6 +29,5 @@ export function Tree(_a) {
30
29
  parentActions,
31
30
  onDataLoad,
32
31
  showLines,
33
- } }, { children: data.map((node, index) => (_jsx(TreeItem, { node: node, tabIndexAvailable: index === 0 || index === data.length - 1 }, node.id))) })) })));
32
+ }, children: data.map((node, index) => (_jsx(TreeItem, { node: node, tabIndexAvailable: index === 0 || index === data.length - 1 }, node.id))) }) })));
34
33
  }
35
- Tree.selectionModes = SelectionMode;
@@ -1,7 +1,7 @@
1
- export declare enum SelectionMode {
2
- Single = "single",
3
- Multi = "multi"
4
- }
1
+ export declare const SELECTION_MODE: {
2
+ readonly Single: "single";
3
+ readonly Multi: "multi";
4
+ };
5
5
  export declare const TRANSITION_TIMING: {
6
6
  accordionFolding: number;
7
7
  };
package/dist/constants.js CHANGED
@@ -1,8 +1,7 @@
1
- export var SelectionMode;
2
- (function (SelectionMode) {
3
- SelectionMode["Single"] = "single";
4
- SelectionMode["Multi"] = "multi";
5
- })(SelectionMode || (SelectionMode = {}));
1
+ export const SELECTION_MODE = {
2
+ Single: 'single',
3
+ Multi: 'multi',
4
+ };
6
5
  export const TRANSITION_TIMING = {
7
6
  accordionFolding: 200,
8
7
  };
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { createContext, useCallback, useContext, useMemo, useState } from 'react';
14
14
  import { useUncontrolledProp } from 'uncontrollable';
15
- import { SelectionMode } from '../constants';
15
+ import { SELECTION_MODE } from '../constants';
16
16
  import { findAllExpandedChildNodeIds, lookupTreeForSelectedNodes } from '../helpers';
17
17
  export const TreeContext = createContext({
18
18
  data: [],
@@ -32,8 +32,8 @@ export const TreeContext = createContext({
32
32
  });
33
33
  export function TreeContextProvider({ children, value }) {
34
34
  const { onNodeClick: onNodeClickProp, onExpand: onExpandProp, onSelect: onSelectProp, selectionMode, data } = value, props = __rest(value, ["onNodeClick", "onExpand", "onSelect", "selectionMode", "data"]);
35
- const isMultiSelect = selectionMode === SelectionMode.Multi;
36
- const isSingleSelect = selectionMode === SelectionMode.Single;
35
+ const isMultiSelect = selectionMode === SELECTION_MODE.Multi;
36
+ const isSingleSelect = selectionMode === SELECTION_MODE.Single;
37
37
  const [expandedNodes, onExpandHandler] = useUncontrolledProp(value.expandedNodes, value.expandedNodes || [], onExpandProp);
38
38
  const onExpand = useCallback(node => {
39
39
  const isExpanded = expandedNodes.includes(node.id);
@@ -84,7 +84,7 @@ export function TreeContextProvider({ children, value }) {
84
84
  }
85
85
  ((_a = node.onClick) === null || _a === void 0 ? void 0 : _a.call(node, e)) || (onNodeClickProp === null || onNodeClickProp === void 0 ? void 0 : onNodeClickProp(node, e));
86
86
  }, [isSingleSelect, onSelect, onNodeClickProp]);
87
- return (_jsx(TreeContext.Provider, Object.assign({ value: Object.assign(Object.assign({}, props), { data, selected: selectedNodes, isSingleSelect,
87
+ return (_jsx(TreeContext.Provider, { value: Object.assign(Object.assign({}, props), { data, selected: selectedNodes, isSingleSelect,
88
88
  isMultiSelect,
89
89
  expandedNodes,
90
90
  onExpand,
@@ -94,6 +94,6 @@ export function TreeContextProvider({ children, value }) {
94
94
  setFocusPosition,
95
95
  resetFocusPosition,
96
96
  setFocusIndex,
97
- focusableNodeIds }) }, { children: children })));
97
+ focusableNodeIds }), children: children }));
98
98
  }
99
99
  export const useTreeContext = () => useContext(TreeContext);
@@ -83,8 +83,8 @@ export function ExpandableTreeNode(_a) {
83
83
  return;
84
84
  }
85
85
  };
86
- return (_jsxs("div", Object.assign({ className: styles.expandableTreeNode, "data-test-id": dataTestId, "data-expandable": Boolean(node.nested) || undefined, "data-disabled": node.disabled || undefined }, { children: [_jsx(TreeNode, Object.assign({}, node, { isLoading: isLoading, parentNode: parentNode, onChevronClick: toggleExpand, onKeyDown: handleKeyDown, tabIndexAvailable: tabIndexAvailable })), node.nested && (_jsx("div", Object.assign({ className: styles.expandableWrap, "data-expanded": isExpanded || undefined, "data-test-id": TEST_IDS.expandable }, { children: showContent && (_jsxs("div", Object.assign({ className: styles.expandableContent, "data-test-id": TEST_IDS.expandableContent }, { children: [_jsx(TreeLine, { visible: showLines, halfHeight: isLineHalfHeight, "data-test-id": TEST_IDS.line }), _jsx("div", Object.assign({ className: styles.expandableNested }, { children: node.nested.map(nestedNode => {
86
+ return (_jsxs("div", { className: styles.expandableTreeNode, "data-test-id": dataTestId, "data-expandable": Boolean(node.nested) || undefined, "data-disabled": node.disabled || undefined, children: [_jsx(TreeNode, Object.assign({}, node, { isLoading: isLoading, parentNode: parentNode, onChevronClick: toggleExpand, onKeyDown: handleKeyDown, tabIndexAvailable: tabIndexAvailable })), node.nested && (_jsx("div", { className: styles.expandableWrap, "data-expanded": isExpanded || undefined, "data-test-id": TEST_IDS.expandable, children: showContent && (_jsxs("div", { className: styles.expandableContent, "data-test-id": TEST_IDS.expandableContent, children: [_jsx(TreeLine, { visible: showLines, halfHeight: isLineHalfHeight, "data-test-id": TEST_IDS.line }), _jsx("div", { className: styles.expandableNested, children: node.nested.map(nestedNode => {
87
87
  const parent = { id: node.id, nested: node.nested, parentNode };
88
88
  return _jsx(TreeItem, { node: nestedNode, parentNode: parent }, nestedNode.id);
89
- }) }))] }))) })))] })));
89
+ }) })] })) }))] }));
90
90
  }
@@ -137,10 +137,10 @@ export function TreeNode(_a) {
137
137
  }
138
138
  };
139
139
  const getNodeActions = Boolean(nested) ? parentActions : nodeActions;
140
- return (_jsxs("div", Object.assign({ role: 'presentation', className: cn(styles.treeNode, className) }, extractSupportProps(rest), { "data-node-id": id }, { children: [parentNode && (_jsx(TreeLine, { halfWidth: Boolean(nested), horizontal: true, visible: showLines, "data-test-id": TEST_IDS.line })), !parentNode && !Boolean(nested) && _jsx(TreeLine, { visible: false }), isExpandable && (_jsx(ButtonFunction, { size: ButtonFunction.sizes.Xs, icon: _jsx(ChevronRightSVG, {}), disabled: disabled, loading: isLoading, onClick: onChevronClick, "data-expanded": isExpanded || undefined, className: styles.treeNodeExpandButton, tabIndex: -1, "data-test-id": TEST_IDS.chevron })), _jsxs("div", Object.assign({ role: 'treeitem', "aria-expanded": isExpanded, "aria-selected": isSelected, "aria-disabled": disabled, "data-multiselect": isMultiSelect || undefined, "data-droplist-active": isDroplistOpen || isDroplistTriggerFocused || undefined, onClick: handleClick, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: resetFocusPosition, tabIndex: tabIndexAvailable ? 0 : -1, className: styles.treeNodeContent, "data-test-id": TEST_IDS.item, ref: ref }, { children: [isMultiSelect && (_jsx("div", Object.assign({ className: styles.treeNodeCheckboxWrap }, { children: _jsx(Checkbox, { size: Checkbox.sizes.S, disabled: disabled, checked: !disabled && isSelected, indeterminate: !disabled && !isSelected && (nestedNodesSelection === null || nestedNodesSelection === void 0 ? void 0 : nestedNodesSelection.someSelected), onChange: handleSelect, onClick: stopPropagationClick, "data-test-id": TEST_IDS.checkbox, tabIndex: -1 }) }))), _jsx("div", Object.assign({ className: styles.treeNodeIcon, "data-test-id": TEST_IDS.icon }, { children: treeNodeIcon })), _jsx(Typography.SansBodyM, Object.assign({ tag: Typography.tags.div, className: styles.treeNodeTitle }, { children: _jsx(TruncateString, { text: title, "data-test-id": TEST_IDS.title }) })), getNodeActions && (_jsx(TreeNodeActions, { getNodeActions: getNodeActions, node: {
140
+ return (_jsxs("div", Object.assign({ role: 'presentation', className: cn(styles.treeNode, className) }, extractSupportProps(rest), { "data-node-id": id, children: [parentNode && (_jsx(TreeLine, { halfWidth: Boolean(nested), horizontal: true, visible: showLines, "data-test-id": TEST_IDS.line })), !parentNode && !Boolean(nested) && _jsx(TreeLine, { visible: false }), isExpandable && (_jsx(ButtonFunction, { size: 'xs', icon: _jsx(ChevronRightSVG, {}), disabled: disabled, loading: isLoading, onClick: onChevronClick, "data-expanded": isExpanded || undefined, className: styles.treeNodeExpandButton, tabIndex: -1, "data-test-id": TEST_IDS.chevron })), _jsxs("div", { role: 'treeitem', "aria-expanded": isExpanded, "aria-selected": isSelected, "aria-disabled": disabled, "data-multiselect": isMultiSelect || undefined, "data-droplist-active": isDroplistOpen || isDroplistTriggerFocused || undefined, onClick: handleClick, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: resetFocusPosition, tabIndex: tabIndexAvailable ? 0 : -1, className: styles.treeNodeContent, "data-test-id": TEST_IDS.item, ref: ref, children: [isMultiSelect && (_jsx("div", { className: styles.treeNodeCheckboxWrap, children: _jsx(Checkbox, { size: 's', disabled: disabled, checked: !disabled && isSelected, indeterminate: !disabled && !isSelected && (nestedNodesSelection === null || nestedNodesSelection === void 0 ? void 0 : nestedNodesSelection.someSelected), onChange: handleSelect, onClick: stopPropagationClick, "data-test-id": TEST_IDS.checkbox, tabIndex: -1 }) })), _jsx("div", { className: styles.treeNodeIcon, "data-test-id": TEST_IDS.icon, children: treeNodeIcon }), _jsx(Typography.SansBodyM, { tag: 'div', className: styles.treeNodeTitle, children: _jsx(TruncateString, { text: title, "data-test-id": TEST_IDS.title }) }), getNodeActions && (_jsx(TreeNodeActions, { getNodeActions: getNodeActions, node: {
141
141
  id,
142
142
  title,
143
143
  disabled,
144
144
  nested,
145
- }, focusNode: handleFocus, onBlurActions: handleBlurActions, isDroplistTriggerFocused: isDroplistTriggerFocused, isDroplistOpen: isDroplistOpen, setDroplistOpen: setDroplistOpen }))] }))] })));
145
+ }, focusNode: handleFocus, onBlurActions: handleBlurActions, isDroplistTriggerFocused: isDroplistTriggerFocused, isDroplistOpen: isDroplistOpen, setDroplistOpen: setDroplistOpen }))] })] })));
146
146
  }
@@ -35,5 +35,5 @@ export function TreeNodeActions({ getNodeActions, isDroplistTriggerFocused, focu
35
35
  return;
36
36
  }
37
37
  };
38
- return (_jsx("div", Object.assign({ role: 'presentation', className: styles.treeNodeActions, "data-focused": isDroplistTriggerFocused || undefined, onClick: stopPropagationClick }, { children: _jsx(Droplist, Object.assign({ open: isDroplistOpen, onOpenChange: setDroplistOpen, onFocusLeave: handleDroplistFocusLeave, firstElementRefCallback: firstElementRefCallback, triggerRef: triggerElementRef, placement: Droplist.placements.BottomEnd, triggerElement: _jsx(ButtonFunction, { size: ButtonFunction.sizes.Xs, icon: _jsx(KebabSVG, { size: 24 }), onKeyDown: handleKeyDown, onBlur: onBlurActions, tabIndex: -1, "data-test-id": TEST_IDS.droplistTrigger }) }, { children: droplistActions.map(action => (_jsx(Droplist.ItemSingle, Object.assign({}, action, { onKeyDown: handleDroplistItemKeyDown, onClick: e => handleDroplistItemClick(e, action.onClick), "data-test-id": TEST_IDS.droplistAction }), action.option))) })) })));
38
+ return (_jsx("div", { role: 'presentation', className: styles.treeNodeActions, "data-focused": isDroplistTriggerFocused || undefined, onClick: stopPropagationClick, children: _jsx(Droplist, { open: isDroplistOpen, onOpenChange: setDroplistOpen, onFocusLeave: handleDroplistFocusLeave, firstElementRefCallback: firstElementRefCallback, triggerRef: triggerElementRef, placement: 'bottom-end', triggerElement: _jsx(ButtonFunction, { size: 'xs', icon: _jsx(KebabSVG, { size: 24 }), onKeyDown: handleKeyDown, onBlur: onBlurActions, tabIndex: -1, "data-test-id": TEST_IDS.droplistTrigger }), children: droplistActions.map(action => (_jsx(Droplist.ItemSingle, Object.assign({}, action, { onKeyDown: handleDroplistItemKeyDown, onClick: e => handleDroplistItemClick(e, action.onClick), "data-test-id": TEST_IDS.droplistAction }), action.option))) }) }));
39
39
  }
package/dist/types.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { MouseEvent, MouseEventHandler, ReactNode } from 'react';
2
2
  import { ItemSingleProps } from '@snack-uikit/droplist';
3
- import { WithSupportProps } from '@snack-uikit/utils';
4
- import { SelectionMode } from './constants';
3
+ import { ValueOf, WithSupportProps } from '@snack-uikit/utils';
4
+ import { SELECTION_MODE } from './constants';
5
+ export type SelectionMode = ValueOf<typeof SELECTION_MODE>;
5
6
  export type TreeNodeId = string;
6
7
  export type BaseTreeNode = WithSupportProps<{
7
8
  /** Идентификатор элемента */
@@ -63,7 +64,7 @@ export type TreeCommonProps = {
63
64
  className?: string;
64
65
  };
65
66
  export type TreeSingleSelect = Omit<TreeCommonProps, 'selected'> & {
66
- selectionMode: SelectionMode.Single;
67
+ selectionMode: 'single';
67
68
  /** Состояние для выбраного элемента */
68
69
  /** <br> - При <strong>selectionMode</strong>=`Single` - принимает строку */
69
70
  selected?: TreeNodeId;
@@ -71,7 +72,7 @@ export type TreeSingleSelect = Omit<TreeCommonProps, 'selected'> & {
71
72
  onSelect?(selectedKey: TreeNodeId, node: TreeNodeProps): void;
72
73
  };
73
74
  export type TreeMultiSelect = Omit<TreeCommonProps, 'selected'> & {
74
- selectionMode: SelectionMode.Multi;
75
+ selectionMode: 'multi';
75
76
  /**
76
77
  * Состояние для выбраных элементов:
77
78
  * <br> - При <strong>selectionMode</strong>=`Multi` - принимает массив строк
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Tree",
7
- "version": "0.2.2",
7
+ "version": "0.3.1",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -32,16 +32,16 @@
32
32
  "license": "Apache-2.0",
33
33
  "scripts": {},
34
34
  "dependencies": {
35
- "@snack-uikit/button": "0.14.1",
36
- "@snack-uikit/droplist": "0.11.2",
37
- "@snack-uikit/icons": "0.19.0",
38
- "@snack-uikit/toggles": "0.8.1",
39
- "@snack-uikit/truncate-string": "0.3.1",
40
- "@snack-uikit/typography": "0.5.1",
41
- "@snack-uikit/utils": "3.1.0",
35
+ "@snack-uikit/button": "0.15.0",
36
+ "@snack-uikit/droplist": "0.12.1",
37
+ "@snack-uikit/icons": "0.19.1",
38
+ "@snack-uikit/toggles": "0.9.1",
39
+ "@snack-uikit/truncate-string": "0.4.1",
40
+ "@snack-uikit/typography": "0.6.0",
41
+ "@snack-uikit/utils": "3.2.0",
42
42
  "classnames": "2.3.2",
43
43
  "react-transition-state": "2.1.1",
44
44
  "uncontrollable": "8.0.4"
45
45
  },
46
- "gitHead": "e124e31699926810648702f97db72413d7ebd2b2"
46
+ "gitHead": "62f43bf0cbfd611d0b746117400f67096b1790f6"
47
47
  }
@@ -2,10 +2,10 @@ import cn from 'classnames';
2
2
 
3
3
  import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
4
4
 
5
- import { SelectionMode } from '../../constants';
5
+ import { SELECTION_MODE } from '../../constants';
6
6
  import { TreeContextProvider } from '../../contexts/TreeContext';
7
7
  import { TreeItem } from '../../helperComponents';
8
- import { TreeBaseProps, TreeMultiSelect, TreeNodeId, TreeSingleSelect } from '../../types';
8
+ import { SelectionMode, TreeBaseProps, TreeMultiSelect, TreeNodeId, TreeSingleSelect } from '../../types';
9
9
  import styles from './styles.module.scss';
10
10
 
11
11
  export type TreeProps = WithSupportProps<TreeBaseProps>;
@@ -30,9 +30,11 @@ export function Tree({
30
30
  <TreeContextProvider
31
31
  value={{
32
32
  data,
33
- selected: selected as typeof SelectionMode extends SelectionMode.Single ? TreeNodeId : TreeNodeId[],
34
- selectionMode: selectionMode as typeof selected extends string ? SelectionMode.Single : SelectionMode.Multi,
35
- onSelect: onSelect as typeof SelectionMode extends SelectionMode.Single
33
+ selected: selected as SelectionMode extends typeof SELECTION_MODE.Single ? TreeNodeId : TreeNodeId[],
34
+ selectionMode: selectionMode as typeof selected extends string
35
+ ? typeof SELECTION_MODE.Single
36
+ : typeof SELECTION_MODE.Multi,
37
+ onSelect: onSelect as SelectionMode extends typeof SELECTION_MODE.Single
36
38
  ? TreeSingleSelect['onSelect']
37
39
  : TreeMultiSelect['onSelect'],
38
40
  expandedNodes,
@@ -51,5 +53,3 @@ export function Tree({
51
53
  </div>
52
54
  );
53
55
  }
54
-
55
- Tree.selectionModes = SelectionMode;
package/src/constants.ts CHANGED
@@ -1,7 +1,7 @@
1
- export enum SelectionMode {
2
- Single = 'single',
3
- Multi = 'multi',
4
- }
1
+ export const SELECTION_MODE = {
2
+ Single: 'single',
3
+ Multi: 'multi',
4
+ } as const;
5
5
 
6
6
  export const TRANSITION_TIMING = {
7
7
  accordionFolding: 200,
@@ -1,7 +1,7 @@
1
1
  import { createContext, Dispatch, ReactNode, SetStateAction, useCallback, useContext, useMemo, useState } from 'react';
2
2
  import { useUncontrolledProp } from 'uncontrollable';
3
3
 
4
- import { SelectionMode } from '../constants';
4
+ import { SELECTION_MODE } from '../constants';
5
5
  import { findAllExpandedChildNodeIds, lookupTreeForSelectedNodes } from '../helpers';
6
6
  import { OnNodeClick, ParentNode, TreeBaseProps, TreeNodeId, TreeNodeProps } from '../types';
7
7
 
@@ -51,8 +51,8 @@ export function TreeContextProvider({ children, value }: TreeContextProviderProp
51
51
  ...props
52
52
  } = value;
53
53
 
54
- const isMultiSelect = selectionMode === SelectionMode.Multi;
55
- const isSingleSelect = selectionMode === SelectionMode.Single;
54
+ const isMultiSelect = selectionMode === SELECTION_MODE.Multi;
55
+ const isSingleSelect = selectionMode === SELECTION_MODE.Single;
56
56
 
57
57
  const [expandedNodes, onExpandHandler] = useUncontrolledProp<TreeNodeId[]>(
58
58
  value.expandedNodes,
@@ -215,7 +215,7 @@ export function TreeNode({
215
215
 
216
216
  {isExpandable && (
217
217
  <ButtonFunction
218
- size={ButtonFunction.sizes.Xs}
218
+ size='xs'
219
219
  icon={<ChevronRightSVG />}
220
220
  disabled={disabled}
221
221
  loading={isLoading}
@@ -246,7 +246,7 @@ export function TreeNode({
246
246
  {isMultiSelect && (
247
247
  <div className={styles.treeNodeCheckboxWrap}>
248
248
  <Checkbox
249
- size={Checkbox.sizes.S}
249
+ size='s'
250
250
  disabled={disabled}
251
251
  checked={!disabled && isSelected}
252
252
  indeterminate={!disabled && !isSelected && nestedNodesSelection?.someSelected}
@@ -262,7 +262,7 @@ export function TreeNode({
262
262
  {treeNodeIcon}
263
263
  </div>
264
264
 
265
- <Typography.SansBodyM tag={Typography.tags.div} className={styles.treeNodeTitle}>
265
+ <Typography.SansBodyM tag='div' className={styles.treeNodeTitle}>
266
266
  <TruncateString text={title} data-test-id={TEST_IDS.title} />
267
267
  </Typography.SansBodyM>
268
268
 
@@ -82,10 +82,10 @@ export function TreeNodeActions({
82
82
  onFocusLeave={handleDroplistFocusLeave}
83
83
  firstElementRefCallback={firstElementRefCallback}
84
84
  triggerRef={triggerElementRef}
85
- placement={Droplist.placements.BottomEnd}
85
+ placement='bottom-end'
86
86
  triggerElement={
87
87
  <ButtonFunction
88
- size={ButtonFunction.sizes.Xs}
88
+ size='xs'
89
89
  icon={<KebabSVG size={24} />}
90
90
  onKeyDown={handleKeyDown}
91
91
  onBlur={onBlurActions}
package/src/types.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { MouseEvent, MouseEventHandler, ReactNode } from 'react';
2
2
 
3
3
  import { ItemSingleProps } from '@snack-uikit/droplist';
4
- import { WithSupportProps } from '@snack-uikit/utils';
4
+ import { ValueOf, WithSupportProps } from '@snack-uikit/utils';
5
5
 
6
- import { SelectionMode } from './constants';
6
+ import { SELECTION_MODE } from './constants';
7
+
8
+ export type SelectionMode = ValueOf<typeof SELECTION_MODE>;
7
9
 
8
10
  export type TreeNodeId = string;
9
11
 
@@ -72,7 +74,7 @@ export type TreeCommonProps = {
72
74
  };
73
75
 
74
76
  export type TreeSingleSelect = Omit<TreeCommonProps, 'selected'> & {
75
- selectionMode: SelectionMode.Single;
77
+ selectionMode: 'single';
76
78
  /** Состояние для выбраного элемента */
77
79
  /** <br> - При <strong>selectionMode</strong>=`Single` - принимает строку */
78
80
  selected?: TreeNodeId;
@@ -81,7 +83,7 @@ export type TreeSingleSelect = Omit<TreeCommonProps, 'selected'> & {
81
83
  };
82
84
 
83
85
  export type TreeMultiSelect = Omit<TreeCommonProps, 'selected'> & {
84
- selectionMode: SelectionMode.Multi;
86
+ selectionMode: 'multi';
85
87
  /**
86
88
  * Состояние для выбраных элементов:
87
89
  * <br> - При <strong>selectionMode</strong>=`Multi` - принимает массив строк