@snack-uikit/tree 0.5.22 → 0.6.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,28 @@
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.6.1 (2024-05-13)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **FF-0000:** add forgotten ([96e1334](https://github.com/cloud-ru-tech/snack-uikit/commit/96e13348e646f581a97cabe873cdfe02c5a96658))
12
+
13
+
14
+
15
+
16
+
17
+ # 0.6.0 (2024-05-13)
18
+
19
+
20
+ ### BREAKING CHANGES
21
+
22
+
23
+ * **FF-0000:** change droplist -> list package ([24b0090](https://github.com/cloud-ru-tech/snack-uikit/commit/24b0090acb586d0032c61acb6099f80aef9bff32))
24
+
25
+
26
+
27
+
6
28
  ## 0.5.22 (2024-05-08)
7
29
 
8
30
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -47,8 +47,8 @@ const [selectedNodes, setSelected] = useState<TreeNodeId[]>([]);
47
47
  | expandedNodes | `string[]` | - | Состояние для раскрытых элементов |
48
48
  | onExpand | `(expandedKeys: string[], nodeId: string) => void` | - | Колбэк при раскрытии/закрытии элементов |
49
49
  | onDataLoad | `(node: TreeNodeProps) => Promise<unknown>` | - | Колбэк для асинхронной загрузки данных при раскрытии дерева |
50
- | parentActions | `(node: TreeNodeProps) => DroplistItemSingleProps[]` | - | Дополнительные действия для элемента-родителя |
51
- | nodeActions | `(node: TreeNodeProps) => DroplistItemSingleProps[]` | - | Дополнительные действия для элемента-потомка |
50
+ | parentActions | `(node: TreeNodeProps) => Item[]` | - | Дополнительные действия для элемента-родителя |
51
+ | nodeActions | `(node: TreeNodeProps) => Item[]` | - | Дополнительные действия для элемента-потомка |
52
52
  | showIcons | `boolean` | true | Флаг отвечающий за отображение иконок у элементов дерева |
53
53
  | showLines | `boolean` | true | Флаг отвечающий за отображение линий вложенности |
54
54
  | className | `string` | - | CSS-класс |
@@ -1,10 +1,10 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
- import { ItemSingleProps } from '@snack-uikit/droplist';
2
+ import { ItemProps } from '@snack-uikit/list';
3
3
  import { TreeNodeProps } from '../../../types';
4
4
  type TreeNodeActionsProps = {
5
5
  isDroplistOpen: boolean;
6
6
  setDroplistOpen: Dispatch<SetStateAction<boolean>>;
7
- getNodeActions(node: TreeNodeProps): ItemSingleProps[];
7
+ getNodeActions(node: TreeNodeProps): ItemProps[];
8
8
  node: TreeNodeProps;
9
9
  isDroplistTriggerFocused: boolean;
10
10
  focusNode(): void;
@@ -1,39 +1,61 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect } from 'react';
2
+ import { useEffect, useRef } from 'react';
3
3
  import { ButtonFunction } from '@snack-uikit/button';
4
- import { Droplist } from '@snack-uikit/droplist';
5
4
  import { KebabSVG } from '@snack-uikit/icons';
5
+ import { Droplist } from '@snack-uikit/list';
6
6
  import { TEST_IDS } from '../../../constants';
7
7
  import styles from '../styles.module.css';
8
- import { stopPropagationClick } from '../utils';
8
+ import { stopPropagationClick, stopPropagationFocus } from '../utils';
9
9
  export function TreeNodeActions({ getNodeActions, isDroplistTriggerFocused, focusNode, isDroplistOpen, setDroplistOpen, onBlurActions, node, }) {
10
10
  const droplistActions = getNodeActions(node);
11
- const { triggerElementRef, handleDroplistFocusLeave, handleDroplistItemKeyDown, handleTriggerKeyDown, handleDroplistItemClick, firstElementRefCallback, } = Droplist.useKeyboardNavigation({ setDroplistOpen });
11
+ const localRef = useRef(null);
12
12
  useEffect(() => {
13
- if (triggerElementRef.current && isDroplistTriggerFocused) {
14
- triggerElementRef.current.focus();
13
+ if (localRef.current && isDroplistTriggerFocused) {
14
+ localRef.current.focus();
15
15
  }
16
- }, [isDroplistTriggerFocused, triggerElementRef]);
17
- if (!droplistActions.length) {
18
- return null;
19
- }
16
+ }, [isDroplistTriggerFocused, localRef]);
20
17
  const handleKeyDown = e => {
21
- handleTriggerKeyDown(e);
18
+ var _a;
22
19
  switch (e.key) {
23
20
  case 'Tab': {
21
+ focusNode();
22
+ setDroplistOpen(false);
24
23
  e.preventDefault();
24
+ e.stopPropagation();
25
25
  return;
26
26
  }
27
27
  case 'ArrowLeft': {
28
28
  if (isDroplistTriggerFocused) {
29
29
  focusNode();
30
30
  setDroplistOpen(false);
31
+ e.stopPropagation();
32
+ }
33
+ return;
34
+ }
35
+ case ' ':
36
+ case 'Enter': {
37
+ e.stopPropagation();
38
+ return;
39
+ }
40
+ case 'ArrowDown': {
41
+ if (isDroplistTriggerFocused) {
42
+ setDroplistOpen(true);
31
43
  }
44
+ e.stopPropagation();
45
+ return;
46
+ }
47
+ case 'ArrowUp': {
48
+ setDroplistOpen(false);
49
+ (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
50
+ e.stopPropagation();
32
51
  return;
33
52
  }
34
53
  default:
35
54
  return;
36
55
  }
37
56
  };
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))) }) }));
57
+ if (!droplistActions.length) {
58
+ return null;
59
+ }
60
+ return (_jsx("div", { role: 'presentation', className: styles.treeNodeActions, "data-focused": isDroplistTriggerFocused || undefined, onClick: stopPropagationClick, onKeyDown: handleKeyDown, onFocus: stopPropagationFocus, children: _jsx(Droplist, { open: isDroplistOpen, onOpenChange: setDroplistOpen, items: droplistActions, closeDroplistOnItemClick: true, placement: 'bottom-end', triggerElemRef: localRef, size: 'm', children: _jsx(ButtonFunction, { size: 'xs', icon: _jsx(KebabSVG, {}), onBlur: onBlurActions, tabIndex: -1, "data-test-id": TEST_IDS.droplistTrigger }) }) }));
39
61
  }
@@ -1,2 +1,3 @@
1
- import { MouseEvent } from 'react';
1
+ import { FocusEvent, MouseEvent } from 'react';
2
2
  export declare function stopPropagationClick(e: MouseEvent<HTMLInputElement>): void;
3
+ export declare function stopPropagationFocus(e: FocusEvent<HTMLInputElement>): void;
@@ -1,3 +1,6 @@
1
1
  export function stopPropagationClick(e) {
2
2
  e.stopPropagation();
3
3
  }
4
+ export function stopPropagationFocus(e) {
5
+ e.stopPropagation();
6
+ }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MouseEvent, MouseEventHandler, ReactNode } from 'react';
2
- import { ItemSingleProps } from '@snack-uikit/droplist';
2
+ import { ItemProps } from '@snack-uikit/list';
3
3
  import { ValueOf, WithSupportProps } from '@snack-uikit/utils';
4
4
  import { SELECTION_MODE } from './constants';
5
5
  export type SelectionMode = ValueOf<typeof SELECTION_MODE>;
@@ -57,9 +57,9 @@ export type TreeCommonProps = {
57
57
  /** Колбэк для асинхронной загрузки данных при раскрытии дерева */
58
58
  onDataLoad?(node: TreeNodeProps): Promise<boolean | unknown>;
59
59
  /** Дополнительные действия для элемента-родителя */
60
- parentActions?(node: TreeNodeProps): ItemSingleProps[];
60
+ parentActions?(node: TreeNodeProps): ItemProps[];
61
61
  /** Дополнительные действия для элемента-потомка */
62
- nodeActions?(node: TreeNodeProps): ItemSingleProps[];
62
+ nodeActions?(node: TreeNodeProps): ItemProps[];
63
63
  /**
64
64
  * Флаг отвечающий за отображение иконок у элементов дерева
65
65
  * @default true
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Tree",
7
- "version": "0.5.22",
7
+ "version": "0.6.1",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -33,8 +33,8 @@
33
33
  "scripts": {},
34
34
  "dependencies": {
35
35
  "@snack-uikit/button": "0.17.1",
36
- "@snack-uikit/droplist": "0.13.18",
37
36
  "@snack-uikit/icons": "0.21.0",
37
+ "@snack-uikit/list": "0.13.0",
38
38
  "@snack-uikit/toggles": "0.9.9",
39
39
  "@snack-uikit/truncate-string": "0.4.14",
40
40
  "@snack-uikit/typography": "0.6.2",
@@ -43,5 +43,5 @@
43
43
  "react-transition-state": "2.1.1",
44
44
  "uncontrollable": "8.0.4"
45
45
  },
46
- "gitHead": "59bd2ac46a341357d543ada864a34e09745b3e42"
46
+ "gitHead": "58d2de0677c973ff4510861699d6fc19b8912a44"
47
47
  }
@@ -1,18 +1,18 @@
1
- import { Dispatch, KeyboardEventHandler, SetStateAction, useEffect } from 'react';
1
+ import { Dispatch, KeyboardEventHandler, SetStateAction, useEffect, useRef } from 'react';
2
2
 
3
3
  import { ButtonFunction } from '@snack-uikit/button';
4
- import { Droplist, ItemSingleProps } from '@snack-uikit/droplist';
5
4
  import { KebabSVG } from '@snack-uikit/icons';
5
+ import { Droplist, ItemProps } from '@snack-uikit/list';
6
6
 
7
7
  import { TEST_IDS } from '../../../constants';
8
8
  import { TreeNodeProps } from '../../../types';
9
9
  import styles from '../styles.module.scss';
10
- import { stopPropagationClick } from '../utils';
10
+ import { stopPropagationClick, stopPropagationFocus } from '../utils';
11
11
 
12
12
  type TreeNodeActionsProps = {
13
13
  isDroplistOpen: boolean;
14
14
  setDroplistOpen: Dispatch<SetStateAction<boolean>>;
15
- getNodeActions(node: TreeNodeProps): ItemSingleProps[];
15
+ getNodeActions(node: TreeNodeProps): ItemProps[];
16
16
  node: TreeNodeProps;
17
17
  isDroplistTriggerFocused: boolean;
18
18
  focusNode(): void;
@@ -30,79 +30,86 @@ export function TreeNodeActions({
30
30
  }: TreeNodeActionsProps) {
31
31
  const droplistActions = getNodeActions(node);
32
32
 
33
- const {
34
- triggerElementRef,
35
- handleDroplistFocusLeave,
36
- handleDroplistItemKeyDown,
37
- handleTriggerKeyDown,
38
- handleDroplistItemClick,
39
- firstElementRefCallback,
40
- } = Droplist.useKeyboardNavigation<HTMLButtonElement>({ setDroplistOpen });
33
+ const localRef = useRef<HTMLButtonElement>(null);
41
34
 
42
35
  useEffect(() => {
43
- if (triggerElementRef.current && isDroplistTriggerFocused) {
44
- triggerElementRef.current.focus();
36
+ if (localRef.current && isDroplistTriggerFocused) {
37
+ localRef.current.focus();
45
38
  }
46
- }, [isDroplistTriggerFocused, triggerElementRef]);
47
-
48
- if (!droplistActions.length) {
49
- return null;
50
- }
51
-
52
- const handleKeyDown: KeyboardEventHandler<HTMLButtonElement> = e => {
53
- handleTriggerKeyDown(e);
39
+ }, [isDroplistTriggerFocused, localRef]);
54
40
 
41
+ const handleKeyDown: KeyboardEventHandler<HTMLElement> = e => {
55
42
  switch (e.key) {
56
43
  case 'Tab': {
44
+ focusNode();
45
+ setDroplistOpen(false);
57
46
  e.preventDefault();
47
+ e.stopPropagation();
58
48
  return;
59
49
  }
60
50
  case 'ArrowLeft': {
61
51
  if (isDroplistTriggerFocused) {
62
52
  focusNode();
63
53
  setDroplistOpen(false);
54
+ e.stopPropagation();
64
55
  }
65
56
  return;
66
57
  }
58
+ case ' ':
59
+ case 'Enter': {
60
+ e.stopPropagation();
61
+
62
+ return;
63
+ }
64
+ case 'ArrowDown': {
65
+ if (isDroplistTriggerFocused) {
66
+ setDroplistOpen(true);
67
+ }
68
+
69
+ e.stopPropagation();
70
+ return;
71
+ }
72
+ case 'ArrowUp': {
73
+ setDroplistOpen(false);
74
+ localRef.current?.focus();
75
+
76
+ e.stopPropagation();
77
+ return;
78
+ }
67
79
  default:
68
80
  return;
69
81
  }
70
82
  };
71
83
 
84
+ if (!droplistActions.length) {
85
+ return null;
86
+ }
87
+
72
88
  return (
73
89
  <div
74
90
  role='presentation'
75
91
  className={styles.treeNodeActions}
76
92
  data-focused={isDroplistTriggerFocused || undefined}
77
93
  onClick={stopPropagationClick}
94
+ onKeyDown={handleKeyDown}
95
+ onFocus={stopPropagationFocus}
78
96
  >
79
97
  <Droplist
80
98
  open={isDroplistOpen}
81
99
  onOpenChange={setDroplistOpen}
82
- onFocusLeave={handleDroplistFocusLeave}
83
- firstElementRefCallback={firstElementRefCallback}
84
- triggerRef={triggerElementRef}
100
+ items={droplistActions}
101
+ closeDroplistOnItemClick
85
102
  placement='bottom-end'
86
- triggerElement={
87
- <ButtonFunction
88
- size='xs'
89
- icon={<KebabSVG size={24} />}
90
- onKeyDown={handleKeyDown}
91
- onBlur={onBlurActions}
92
- tabIndex={-1}
93
- data-test-id={TEST_IDS.droplistTrigger}
94
- />
95
- }
103
+ triggerElemRef={localRef}
104
+ size='m'
96
105
  >
97
- {droplistActions.map(action => (
98
- <Droplist.ItemSingle
99
- key={action.option}
100
- {...action}
101
- onKeyDown={handleDroplistItemKeyDown}
102
- onClick={e => handleDroplistItemClick(e, action.onClick)}
103
- data-test-id={TEST_IDS.droplistAction}
104
- />
105
- ))}
106
+ <ButtonFunction
107
+ size='xs'
108
+ icon={<KebabSVG />}
109
+ onBlur={onBlurActions}
110
+ tabIndex={-1}
111
+ data-test-id={TEST_IDS.droplistTrigger}
112
+ />
106
113
  </Droplist>
107
114
  </div>
108
115
  );
@@ -1,5 +1,9 @@
1
- import { MouseEvent } from 'react';
1
+ import { FocusEvent, MouseEvent } from 'react';
2
2
 
3
3
  export function stopPropagationClick(e: MouseEvent<HTMLInputElement>) {
4
4
  e.stopPropagation();
5
5
  }
6
+
7
+ export function stopPropagationFocus(e: FocusEvent<HTMLInputElement>) {
8
+ e.stopPropagation();
9
+ }
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MouseEvent, MouseEventHandler, ReactNode } from 'react';
2
2
 
3
- import { ItemSingleProps } from '@snack-uikit/droplist';
3
+ import { ItemProps } from '@snack-uikit/list';
4
4
  import { ValueOf, WithSupportProps } from '@snack-uikit/utils';
5
5
 
6
6
  import { SELECTION_MODE } from './constants';
@@ -66,9 +66,9 @@ export type TreeCommonProps = {
66
66
  /** Колбэк для асинхронной загрузки данных при раскрытии дерева */
67
67
  onDataLoad?(node: TreeNodeProps): Promise<boolean | unknown>;
68
68
  /** Дополнительные действия для элемента-родителя */
69
- parentActions?(node: TreeNodeProps): ItemSingleProps[];
69
+ parentActions?(node: TreeNodeProps): ItemProps[];
70
70
  /** Дополнительные действия для элемента-потомка */
71
- nodeActions?(node: TreeNodeProps): ItemSingleProps[];
71
+ nodeActions?(node: TreeNodeProps): ItemProps[];
72
72
  /**
73
73
  * Флаг отвечающий за отображение иконок у элементов дерева
74
74
  * @default true