@snack-uikit/tree 0.3.3 → 0.4.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/CHANGELOG.md CHANGED
@@ -3,6 +3,30 @@
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.4.0 (2024-01-11)
7
+
8
+
9
+ ### Features
10
+
11
+ * **FF-4018:** add showIcons prop to disable tree node icon ([eecda7f](https://github.com/cloud-ru-tech/snack-uikit/commit/eecda7f35fc98efeea2770098acfe7241b44b57a))
12
+
13
+
14
+
15
+
16
+
17
+ ## 0.3.4 (2023-12-28)
18
+
19
+ ### Only dependencies have been changed
20
+ * [@snack-uikit/button@0.15.1](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/button/CHANGELOG.md)
21
+ * [@snack-uikit/droplist@0.12.4](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/droplist/CHANGELOG.md)
22
+ * [@snack-uikit/toggles@0.9.3](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/toggles/CHANGELOG.md)
23
+ * [@snack-uikit/truncate-string@0.4.4](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/truncate-string/CHANGELOG.md)
24
+ * [@snack-uikit/typography@0.6.1](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/typography/CHANGELOG.md)
25
+
26
+
27
+
28
+
29
+
6
30
  ## 0.3.3 (2023-12-25)
7
31
 
8
32
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -50,6 +50,7 @@ const [selectedNodes, setSelected] = useState<TreeNodeId[]>([]);
50
50
  | onDataLoad | `(node: TreeNodeProps) => Promise<unknown>` | - | Колбэк для асинхронной загрузки данных при раскрытии дерева |
51
51
  | parentActions | `(node: TreeNodeProps) => DroplistItemSingleProps[]` | - | Дополнительные действия для элемента-родителя |
52
52
  | nodeActions | `(node: TreeNodeProps) => DroplistItemSingleProps[]` | - | Дополнительные действия для элемента-потомка |
53
+ | showIcons | `boolean` | true | Флаг отвечающий за отображение иконок у элементов дерева |
53
54
  | showLines | `boolean` | true | Флаг отвечающий за отображение линий вложенности |
54
55
  | className | `string` | - | CSS-класс |
55
56
  | selected | `string \| string[]` | - | Состояние для выбраных элементов: <br> - При <strong>selectionMode</strong>=`Multi` - принимает массив строк <br> - При <strong>selectionMode</strong>=`Single` - принимает строку |
@@ -1,4 +1,4 @@
1
1
  import { WithSupportProps } from '@snack-uikit/utils';
2
2
  import { TreeBaseProps } from '../../types';
3
3
  export type TreeProps = WithSupportProps<TreeBaseProps>;
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;
4
+ export declare function Tree({ data, selected, selectionMode, onSelect, onNodeClick, onExpand, expandedNodes, nodeActions, parentActions, onDataLoad, showLines, showIcons, className, ...rest }: TreeProps): import("react/jsx-runtime").JSX.Element;
@@ -16,7 +16,7 @@ import { TreeContextProvider } from '../../contexts/TreeContext';
16
16
  import { TreeItem } from '../../helperComponents';
17
17
  import styles from './styles.module.css';
18
18
  export function Tree(_a) {
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"]);
19
+ var { data, selected, selectionMode, onSelect, onNodeClick, onExpand, expandedNodes, nodeActions, parentActions, onDataLoad, showLines = true, showIcons = true, className } = _a, rest = __rest(_a, ["data", "selected", "selectionMode", "onSelect", "onNodeClick", "onExpand", "expandedNodes", "nodeActions", "parentActions", "onDataLoad", "showLines", "showIcons", "className"]);
20
20
  return (_jsx("div", Object.assign({ className: cn(styles.tree, className), role: 'tree' }, extractSupportProps(rest), { children: _jsx(TreeContextProvider, { value: {
21
21
  data,
22
22
  selected: selected,
@@ -29,5 +29,6 @@ export function Tree(_a) {
29
29
  parentActions,
30
30
  onDataLoad,
31
31
  showLines,
32
+ showIcons,
32
33
  }, children: data.map((node, index) => (_jsx(TreeItem, { node: node, tabIndexAvailable: index === 0 || index === data.length - 1 }, node.id))) }) })));
33
34
  }
@@ -27,7 +27,7 @@ import styles from './styles.module.css';
27
27
  import { stopPropagationClick } from './utils';
28
28
  export function TreeNode(_a) {
29
29
  var { id, title, icon = _jsx(FileSVG, { size: 24 }), expandedIcon = _jsx(FolderOpenSVG, { size: 24 }), collapsedIcon = _jsx(FolderSVG, { size: 24 }), disabled, onClick, nested, className, onChevronClick, onKeyDown, isLoading, parentNode, tabIndexAvailable } = _a, rest = __rest(_a, ["id", "title", "icon", "expandedIcon", "collapsedIcon", "disabled", "onClick", "nested", "className", "onChevronClick", "onKeyDown", "isLoading", "parentNode", "tabIndexAvailable"]);
30
- const { isMultiSelect, onNodeClick, selected, expandedNodes, onSelect, nodeActions, parentActions, setFocusPosition, resetFocusPosition, focusedNodeId, setFocusIndex, focusableNodeIds, showLines, } = useTreeContext();
30
+ const { isMultiSelect, onNodeClick, selected, expandedNodes, onSelect, nodeActions, parentActions, setFocusPosition, resetFocusPosition, focusedNodeId, setFocusIndex, focusableNodeIds, showLines, showIcons, } = useTreeContext();
31
31
  const [isDroplistOpen, setDroplistOpen] = useState(false);
32
32
  const [isDroplistTriggerFocused, setFocusDroplistTrigger] = useState(false);
33
33
  const ref = useRef(null);
@@ -46,11 +46,13 @@ export function TreeNode(_a) {
46
46
  }
47
47
  }, [isFocused]);
48
48
  const treeNodeIcon = useMemo(() => {
49
+ if (!showIcons)
50
+ return undefined;
49
51
  if (isExpandable) {
50
52
  return isExpanded ? expandedIcon : collapsedIcon;
51
53
  }
52
54
  return icon;
53
- }, [isExpandable, icon, isExpanded, expandedIcon, collapsedIcon]);
55
+ }, [showIcons, isExpandable, icon, isExpanded, expandedIcon, collapsedIcon]);
54
56
  const handleClick = e => {
55
57
  onNodeClick({
56
58
  id,
@@ -137,7 +139,7 @@ export function TreeNode(_a) {
137
139
  }
138
140
  };
139
141
  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: '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: {
142
+ 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 }) })), treeNodeIcon && (_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
143
  id,
142
144
  title,
143
145
  disabled,
@@ -45,7 +45,6 @@
45
45
  align-items:center;
46
46
  box-sizing:border-box;
47
47
  width:100%;
48
- border-radius:var(--radius-tree-item-content-layout, 8px);
49
48
  }
50
49
  .treeNodeContent::before{
51
50
  pointer-events:none;
package/dist/types.d.ts CHANGED
@@ -59,6 +59,11 @@ export type TreeCommonProps = {
59
59
  parentActions?(node: TreeNodeProps): ItemSingleProps[];
60
60
  /** Дополнительные действия для элемента-потомка */
61
61
  nodeActions?(node: TreeNodeProps): ItemSingleProps[];
62
+ /**
63
+ * Флаг отвечающий за отображение иконок у элементов дерева
64
+ * @default true
65
+ */
66
+ showIcons?: boolean;
62
67
  /** Флаг отвечающий за отображение линий вложенности */
63
68
  showLines?: boolean;
64
69
  className?: string;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Tree",
7
- "version": "0.3.3",
7
+ "version": "0.4.0",
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.15.0",
36
- "@snack-uikit/droplist": "0.12.3",
35
+ "@snack-uikit/button": "0.15.1",
36
+ "@snack-uikit/droplist": "0.12.4",
37
37
  "@snack-uikit/icons": "0.19.2",
38
- "@snack-uikit/toggles": "0.9.2",
39
- "@snack-uikit/truncate-string": "0.4.3",
40
- "@snack-uikit/typography": "0.6.0",
38
+ "@snack-uikit/toggles": "0.9.3",
39
+ "@snack-uikit/truncate-string": "0.4.4",
40
+ "@snack-uikit/typography": "0.6.1",
41
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": "420ccb07e016ae79a8b783e88c24f2045fadc026"
46
+ "gitHead": "ebf50540bc191ed0f01ce6f1246f1a3e1263a835"
47
47
  }
@@ -22,6 +22,7 @@ export function Tree({
22
22
  parentActions,
23
23
  onDataLoad,
24
24
  showLines = true,
25
+ showIcons = true,
25
26
  className,
26
27
  ...rest
27
28
  }: TreeProps) {
@@ -44,6 +45,7 @@ export function Tree({
44
45
  parentActions,
45
46
  onDataLoad,
46
47
  showLines,
48
+ showIcons,
47
49
  }}
48
50
  >
49
51
  {data.map((node, index) => (
@@ -58,6 +58,7 @@ export function TreeNode({
58
58
  setFocusIndex,
59
59
  focusableNodeIds,
60
60
  showLines,
61
+ showIcons,
61
62
  } = useTreeContext();
62
63
 
63
64
  const [isDroplistOpen, setDroplistOpen] = useState(false);
@@ -86,12 +87,14 @@ export function TreeNode({
86
87
  }, [isFocused]);
87
88
 
88
89
  const treeNodeIcon = useMemo(() => {
90
+ if (!showIcons) return undefined;
91
+
89
92
  if (isExpandable) {
90
93
  return isExpanded ? expandedIcon : collapsedIcon;
91
94
  }
92
95
 
93
96
  return icon;
94
- }, [isExpandable, icon, isExpanded, expandedIcon, collapsedIcon]);
97
+ }, [showIcons, isExpandable, icon, isExpanded, expandedIcon, collapsedIcon]);
95
98
 
96
99
  const handleClick: TreeNodeProps['onClick'] = e => {
97
100
  onNodeClick(
@@ -258,9 +261,11 @@ export function TreeNode({
258
261
  </div>
259
262
  )}
260
263
 
261
- <div className={styles.treeNodeIcon} data-test-id={TEST_IDS.icon}>
262
- {treeNodeIcon}
263
- </div>
264
+ {treeNodeIcon && (
265
+ <div className={styles.treeNodeIcon} data-test-id={TEST_IDS.icon}>
266
+ {treeNodeIcon}
267
+ </div>
268
+ )}
264
269
 
265
270
  <Typography.SansBodyM tag='div' className={styles.treeNodeTitle}>
266
271
  <TruncateString text={title} data-test-id={TEST_IDS.title} />
@@ -53,8 +53,6 @@
53
53
  box-sizing: border-box;
54
54
  width: 100%;
55
55
 
56
- border-radius: $radius-tree-item-content-layout;
57
-
58
56
  &::before {
59
57
  pointer-events: none;
60
58
  content: '';
package/src/types.ts CHANGED
@@ -68,6 +68,11 @@ export type TreeCommonProps = {
68
68
  parentActions?(node: TreeNodeProps): ItemSingleProps[];
69
69
  /** Дополнительные действия для элемента-потомка */
70
70
  nodeActions?(node: TreeNodeProps): ItemSingleProps[];
71
+ /**
72
+ * Флаг отвечающий за отображение иконок у элементов дерева
73
+ * @default true
74
+ */
75
+ showIcons?: boolean;
71
76
  /** Флаг отвечающий за отображение линий вложенности */
72
77
  showLines?: boolean;
73
78
  className?: string;