@cloud-ru/ds-tree 1.0.51-preview-c75d4f3d.0 → 1.0.51-preview-2df639a4.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 +2 -2
- package/dist/cjs/constants.d.ts +4 -0
- package/dist/cjs/constants.js +4 -0
- package/dist/cjs/helperComponents/ExpandableTreeNode/ExpandableTreeNode.js +3 -3
- package/dist/cjs/helperComponents/TreeLine/TreeLine.d.ts +4 -3
- package/dist/cjs/helperComponents/TreeLine/TreeLine.js +2 -2
- package/dist/cjs/helperComponents/TreeNode/TreeNode.js +4 -15
- package/dist/cjs/helperComponents/TreeNode/components/TreeNodeActions.js +1 -1
- package/dist/esm/constants.d.ts +4 -0
- package/dist/esm/constants.js +4 -0
- package/dist/esm/helperComponents/ExpandableTreeNode/ExpandableTreeNode.js +3 -3
- package/dist/esm/helperComponents/TreeLine/TreeLine.d.ts +4 -3
- package/dist/esm/helperComponents/TreeLine/TreeLine.js +2 -2
- package/dist/esm/helperComponents/TreeNode/TreeNode.js +4 -15
- package/dist/esm/helperComponents/TreeNode/components/TreeNodeActions.js +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/constants.ts +4 -0
- package/src/helperComponents/ExpandableTreeNode/ExpandableTreeNode.tsx +3 -2
- package/src/helperComponents/TreeLine/TreeLine.tsx +6 -4
- package/src/helperComponents/TreeNode/TreeNode.tsx +20 -22
- package/src/helperComponents/TreeNode/components/TreeNodeActions.tsx +1 -0
package/README.md
CHANGED
|
@@ -313,8 +313,8 @@ export function AsyncLoad() {
|
|
|
313
313
|
| Prop | Type | Default | Description |
|
|
314
314
|
|------|------|---------|-------------|
|
|
315
315
|
| `className` | `string` | — | CSS-класс |
|
|
316
|
-
| `data` | `
|
|
317
|
-
| `data-test-id` | `string` | — |
|
|
316
|
+
| `data` | `TreeNodeProps` | — | Данные для отрисовки |
|
|
317
|
+
| `data-test-id` | `string` | — | Идентификатор элемента для поиска в автоматизированных тестах. |
|
|
318
318
|
| `expandedNodes` | `TreeNodeId` | — | Состояние для раскрытых элементов |
|
|
319
319
|
| `nodeActions` | `((node: TreeNodeProps) => Item[])` | — | Дополнительные действия для элемента-потомка |
|
|
320
320
|
| `onDataLoad` | `((node: TreeNodeProps) => Promise<unknown>)` | — | Колбэк для асинхронной загрузки данных при раскрытии дерева |
|
package/dist/cjs/constants.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export declare const TRANSITION_TIMING: {
|
|
|
11
11
|
readonly accordionFolding: 200;
|
|
12
12
|
};
|
|
13
13
|
export declare const TEST_IDS: {
|
|
14
|
+
readonly expandableTreeNodeTreeNode: "expandable-tree-node__tree-node";
|
|
15
|
+
readonly treeNodeActionsDroplist: "tree-node-actions__droplist";
|
|
16
|
+
readonly treeNodeSpinner: "tree-node__spinner";
|
|
17
|
+
readonly treeNodeTreeNodeTitle: "tree-node__tree-node-title";
|
|
14
18
|
readonly node: "tree__node";
|
|
15
19
|
readonly line: "tree__node__line";
|
|
16
20
|
readonly item: "tree__node__item";
|
package/dist/cjs/constants.js
CHANGED
|
@@ -14,6 +14,10 @@ exports.TRANSITION_TIMING = {
|
|
|
14
14
|
accordionFolding: 200,
|
|
15
15
|
};
|
|
16
16
|
exports.TEST_IDS = {
|
|
17
|
+
expandableTreeNodeTreeNode: 'expandable-tree-node__tree-node',
|
|
18
|
+
treeNodeActionsDroplist: 'tree-node-actions__droplist',
|
|
19
|
+
treeNodeSpinner: 'tree-node__spinner',
|
|
20
|
+
treeNodeTreeNodeTitle: 'tree-node__tree-node-title',
|
|
17
21
|
node: 'tree__node',
|
|
18
22
|
line: 'tree__node__line',
|
|
19
23
|
item: 'tree__node__item',
|
|
@@ -59,11 +59,11 @@ exports.ExpandableTreeNode = (0, react_1.forwardRef)(({ node: { 'data-test-id':
|
|
|
59
59
|
const toggleExpand = async () => {
|
|
60
60
|
if (node.nested && !node.nested.length && !isExpanded && onDataLoad) {
|
|
61
61
|
setLoading(true);
|
|
62
|
-
await onDataLoad(node).finally(() => {
|
|
62
|
+
await onDataLoad({ ...node, 'data-test-id': dataTestId }).finally(() => {
|
|
63
63
|
setLoading(false);
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
-
onExpand(node);
|
|
66
|
+
onExpand({ ...node, 'data-test-id': dataTestId });
|
|
67
67
|
toggle();
|
|
68
68
|
};
|
|
69
69
|
const handleKeyDown = e => {
|
|
@@ -86,7 +86,7 @@ exports.ExpandableTreeNode = (0, react_1.forwardRef)(({ node: { 'data-test-id':
|
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_2.default.expandableTreeNode, "data-test-id": dataTestId, "data-expandable": Boolean(node.nested) || undefined, "data-disabled": node.disabled || undefined, ref: ref, children: [(0, jsx_runtime_1.jsx)(TreeNode_1.TreeNode, { ...node, loading: loading, parentNode: parentNode, onChevronClick: toggleExpand, onKeyDown: handleKeyDown, tabIndexAvailable: tabIndexAvailable }), node.nested && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_2.default.expandableWrap, "data-expanded": isExpanded || undefined, "data-entered": state.status === 'entered' || undefined, "data-test-id": constants_1.TEST_IDS.expandable, children: showContent && ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_2.default.expandableContent, "data-test-id": constants_1.TEST_IDS.expandableContent, children: [(0, jsx_runtime_1.jsx)(TreeLine_1.TreeLine, { visible: showLines, "data-test-id": constants_1.TEST_IDS.line, style: { height: `calc(100% - ${lastItemHeight}px)` } }), (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_2.default.expandableNested, children: node.nested.map((nestedNode, index) => {
|
|
89
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_2.default.expandableTreeNode, "data-test-id": dataTestId, "data-expandable": Boolean(node.nested) || undefined, "data-disabled": node.disabled || undefined, ref: ref, children: [(0, jsx_runtime_1.jsx)(TreeNode_1.TreeNode, { "data-test-id": constants_1.TEST_IDS.expandableTreeNodeTreeNode, ...node, loading: loading, parentNode: parentNode, onChevronClick: toggleExpand, onKeyDown: handleKeyDown, tabIndexAvailable: tabIndexAvailable }), node.nested && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_2.default.expandableWrap, "data-expanded": isExpanded || undefined, "data-entered": state.status === 'entered' || undefined, "data-test-id": constants_1.TEST_IDS.expandable, children: showContent && ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_2.default.expandableContent, "data-test-id": constants_1.TEST_IDS.expandableContent, children: [(0, jsx_runtime_1.jsx)(TreeLine_1.TreeLine, { visible: showLines, "data-test-id": constants_1.TEST_IDS.line, style: { height: `calc(100% - ${lastItemHeight}px)` } }), (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_2.default.expandableNested, children: node.nested.map((nestedNode, index) => {
|
|
90
90
|
const parent = { id: node.id, nested: node.nested, parentNode };
|
|
91
91
|
return ((0, jsx_runtime_1.jsx)(TreeItem_1.TreeItem, { ref: el => (childrenRefs.current[index] = el), node: { ...nestedNode, disabled: node.disabled || nestedNode.disabled }, parentNode: parent }, nestedNode.id));
|
|
92
92
|
}) })] })) }))] }));
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { WithSupportProps } from '@cloud-ru/ds-utils';
|
|
1
2
|
import { CSSProperties } from 'react';
|
|
2
|
-
export type TreeLineProps = {
|
|
3
|
+
export type TreeLineProps = WithSupportProps<{
|
|
3
4
|
className?: string;
|
|
4
5
|
/** Доп. инлайн-стили для контейнера (height/width передаются здесь, а не отдельными пропами). */
|
|
5
6
|
style?: CSSProperties;
|
|
6
7
|
halfWidth?: boolean;
|
|
7
8
|
visible?: boolean;
|
|
8
9
|
horizontal?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare function TreeLine({ className, style, halfWidth, horizontal, visible }: TreeLineProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function TreeLine({ className, style, halfWidth, horizontal, visible, ...supportProps }: TreeLineProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -8,6 +8,6 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
8
8
|
const classnames_1 = __importDefault(require("classnames"));
|
|
9
9
|
const constants_1 = require("../../constants");
|
|
10
10
|
const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
|
|
11
|
-
function TreeLine({ className, style, halfWidth, horizontal, visible }) {
|
|
12
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: (0, classnames_1.default)(styles_module_scss_1.default.treeLine, className), style: style, "data-horizontal": horizontal || undefined, "data-half-width": halfWidth || undefined, "data-visible": visible || undefined, "data-test-id": constants_1.TEST_IDS.line }));
|
|
11
|
+
function TreeLine({ className, style, halfWidth, horizontal, visible, ...supportProps }) {
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: (0, classnames_1.default)(styles_module_scss_1.default.treeLine, className), style: style, "data-horizontal": horizontal || undefined, "data-half-width": halfWidth || undefined, "data-visible": visible || undefined, ...supportProps, "data-test-id": supportProps['data-test-id'] ?? constants_1.TEST_IDS.line }));
|
|
13
13
|
}
|
|
@@ -73,14 +73,7 @@ exports.TreeNode = (0, react_1.forwardRef)(({ id, title, icon: iconProp, expande
|
|
|
73
73
|
return iconProp ?? (0, jsx_runtime_1.jsx)(system_1.FileSVG, {});
|
|
74
74
|
}, [showIcons, isExpandable, isExpanded, iconProp, expandedIconProp, collapsedIconProp]);
|
|
75
75
|
const handleClick = e => {
|
|
76
|
-
onNodeClick({
|
|
77
|
-
id,
|
|
78
|
-
title,
|
|
79
|
-
disabled,
|
|
80
|
-
nested,
|
|
81
|
-
onClick,
|
|
82
|
-
href,
|
|
83
|
-
}, e);
|
|
76
|
+
onNodeClick({ 'data-test-id': rest['data-test-id'], id, title, disabled, nested, onClick, href }, e);
|
|
84
77
|
};
|
|
85
78
|
const handleAnchorClick = (e) => {
|
|
86
79
|
e.stopPropagation();
|
|
@@ -181,12 +174,8 @@ exports.TreeNode = (0, react_1.forwardRef)(({ id, title, icon: iconProp, expande
|
|
|
181
174
|
}
|
|
182
175
|
};
|
|
183
176
|
const getNodeActions = nested ? parentActions : nodeActions;
|
|
184
|
-
return ((0, jsx_runtime_1.jsxs)("div", { role: 'presentation', className: (0, classnames_1.default)(styles_module_scss_1.default.treeNode, className), ...(0, utils_1.extractSupportProps)(rest), "data-node-id": id, "data-size": size, ref: ref, children: [parentNode && (0, jsx_runtime_1.jsx)(TreeLine_1.TreeLine, { halfWidth: isExpandable, horizontal: true, visible: showLines }), (isExpandable || !parentNode) && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.treeNodeExpandButtonWrapper, children: isExpandable ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("button", { type: 'button', onClick: onChevronClick, "data-expanded": isExpanded || undefined, className: styles_module_scss_1.default.treeNodeExpandButton, tabIndex: -1, "data-test-id": constants_1.TEST_IDS.chevron, "aria-label": isExpanded ? 'Collapse' : 'Expand', children: [(0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.treeNodeExpandButtonStateLayer, "aria-hidden": true, "data-state": 'emptyNeutralOnBackground' }), loading ? (0, jsx_runtime_1.jsx)(loader_1.Spinner, { size: constants_2.SPINNER_SIZE_BY_TREE_SIZE[size] }) : (0, jsx_runtime_1.jsx)(system_1.ChevronRightSVG, {})] }), (0, jsx_runtime_1.jsx)(TreeLine_1.TreeLine, { visible: isExpanded && showLines })] })) : ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.treeNodeExpandButtonSpacer, "aria-hidden": true })) })), (0, jsx_runtime_1.jsxs)("div", { role: 'treeitem', "aria-expanded": isExpanded, "aria-selected": isSelectable
|
|
177
|
+
return ((0, jsx_runtime_1.jsxs)("div", { role: 'presentation', className: (0, classnames_1.default)(styles_module_scss_1.default.treeNode, className), ...(0, utils_1.extractSupportProps)(rest), "data-node-id": id, "data-size": size, ref: ref, children: [parentNode && ((0, jsx_runtime_1.jsx)(TreeLine_1.TreeLine, { "data-test-id": constants_1.TEST_IDS.line, halfWidth: isExpandable, horizontal: true, visible: showLines })), (isExpandable || !parentNode) && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.treeNodeExpandButtonWrapper, children: isExpandable ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("button", { type: 'button', onClick: onChevronClick, "data-expanded": isExpanded || undefined, className: styles_module_scss_1.default.treeNodeExpandButton, tabIndex: -1, "data-test-id": constants_1.TEST_IDS.chevron, "aria-label": isExpanded ? 'Collapse' : 'Expand', children: [(0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.treeNodeExpandButtonStateLayer, "aria-hidden": true, "data-state": 'emptyNeutralOnBackground' }), loading ? ((0, jsx_runtime_1.jsx)(loader_1.Spinner, { "data-test-id": constants_1.TEST_IDS.treeNodeSpinner, size: constants_2.SPINNER_SIZE_BY_TREE_SIZE[size] })) : ((0, jsx_runtime_1.jsx)(system_1.ChevronRightSVG, {}))] }), (0, jsx_runtime_1.jsx)(TreeLine_1.TreeLine, { "data-test-id": constants_1.TEST_IDS.line, visible: isExpanded && showLines })] })) : ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.treeNodeExpandButtonSpacer, "aria-hidden": true })) })), (0, jsx_runtime_1.jsxs)("div", { role: 'treeitem', "aria-expanded": isExpanded, "aria-selected": isSelectable
|
|
185
178
|
? isSelected || (nestedNodesSelection?.someSelected && !isExpanded && !isMultiSelect)
|
|
186
|
-
: undefined, "aria-disabled": disabled, "data-disabled": disabled || undefined, "data-multiselect": isMultiSelect || undefined, "data-droplist-active": isDroplistOpen || isDroplistTriggerFocused || undefined, onClick: handleClick, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: resetFocusPosition, tabIndex: tabIndexAvailable ? 0 : -1, className: styles_module_scss_1.default.treeNodeContent, "data-test-id": constants_1.TEST_IDS.item, ref: contentRef, children: [(0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.stateLayer, "aria-hidden": true, "data-state": isSelected && !isMultiSelect ? 'activatedOnBackground' : 'emptyNeutralOnBackground' }), (isMultiSelect || showToggle) && ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.treeNodeCheckboxWrap, children: [isMultiSelect && ((0, jsx_runtime_1.jsx)(toggles_1.Checkbox, { size: constants_2.CONTROL_SIZE_BY_TREE_SIZE[size], disabled: disabled, checked: isSelected, indeterminate: isIndeterminate, onChange: handleSelect, onClick: utils_2.stopPropagationClick, "data-test-id": constants_1.TEST_IDS.checkbox, tabIndex: -1 })), showToggle && ((0, jsx_runtime_1.jsx)(toggles_1.Radio, { size: constants_2.CONTROL_SIZE_BY_TREE_SIZE[size], checked: isSelected, disabled: disabled, "data-test-id": constants_1.TEST_IDS.radio, tabIndex: -1 }))] })), (0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.treeNodeContentWrapper, children: [treeNodeIcon && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.treeNodeIcon, "data-test-id": constants_1.TEST_IDS.icon, children: treeNodeIcon })), (0, jsx_runtime_1.jsx)(typography_1.Typography, { variant: 'body', size: size, as: 'div', className: styles_module_scss_1.default.treeNodeTitle, children: (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.treeNodeTextContent, children: (0, jsx_runtime_1.jsxs)(components_1.TreeNodeHref, { href: href, onClick: handleAnchorClick, ref: anchorRef, children: [typeof title === 'string' && ((0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, { text: title, maxLines: titleMaxLines, "data-test-id": constants_1.TEST_IDS.title })), typeof title !== 'string' &&
|
|
187
|
-
|
|
188
|
-
title,
|
|
189
|
-
disabled,
|
|
190
|
-
nested,
|
|
191
|
-
}, focusNode: handleFocus, onBlurActions: handleBlurActions, isDroplistTriggerFocused: isDroplistTriggerFocused, isDroplistOpen: isDroplistOpen, setDroplistOpen: setDroplistOpen, size: size }))] })] }));
|
|
179
|
+
: undefined, "aria-disabled": disabled, "data-disabled": disabled || undefined, "data-multiselect": isMultiSelect || undefined, "data-droplist-active": isDroplistOpen || isDroplistTriggerFocused || undefined, onClick: handleClick, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: resetFocusPosition, tabIndex: tabIndexAvailable ? 0 : -1, className: styles_module_scss_1.default.treeNodeContent, "data-test-id": constants_1.TEST_IDS.item, ref: contentRef, children: [(0, jsx_runtime_1.jsx)("span", { className: styles_module_scss_1.default.stateLayer, "aria-hidden": true, "data-state": isSelected && !isMultiSelect ? 'activatedOnBackground' : 'emptyNeutralOnBackground' }), (isMultiSelect || showToggle) && ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.treeNodeCheckboxWrap, children: [isMultiSelect && ((0, jsx_runtime_1.jsx)(toggles_1.Checkbox, { size: constants_2.CONTROL_SIZE_BY_TREE_SIZE[size], disabled: disabled, checked: isSelected, indeterminate: isIndeterminate, onChange: handleSelect, onClick: utils_2.stopPropagationClick, "data-test-id": constants_1.TEST_IDS.checkbox, tabIndex: -1 })), showToggle && ((0, jsx_runtime_1.jsx)(toggles_1.Radio, { size: constants_2.CONTROL_SIZE_BY_TREE_SIZE[size], checked: isSelected, disabled: disabled, "data-test-id": constants_1.TEST_IDS.radio, tabIndex: -1 }))] })), (0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.treeNodeContentWrapper, children: [treeNodeIcon && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.treeNodeIcon, "data-test-id": constants_1.TEST_IDS.icon, children: treeNodeIcon })), (0, jsx_runtime_1.jsx)(typography_1.Typography, { "data-test-id": constants_1.TEST_IDS.treeNodeTreeNodeTitle, variant: 'body', size: size, as: 'div', className: styles_module_scss_1.default.treeNodeTitle, children: (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.treeNodeTextContent, children: (0, jsx_runtime_1.jsxs)(components_1.TreeNodeHref, { href: href, onClick: handleAnchorClick, ref: anchorRef, children: [typeof title === 'string' && ((0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, { text: title, maxLines: titleMaxLines, "data-test-id": constants_1.TEST_IDS.title })), typeof title !== 'string' &&
|
|
180
|
+
title({ 'data-test-id': rest['data-test-id'], id, disabled, nested })] }) }) })] }), getNodeActions && ((0, jsx_runtime_1.jsx)(components_1.TreeNodeActions, { getNodeActions: getNodeActions, node: { 'data-test-id': rest['data-test-id'], id, title, disabled, nested }, focusNode: handleFocus, onBlurActions: handleBlurActions, isDroplistTriggerFocused: isDroplistTriggerFocused, isDroplistOpen: isDroplistOpen, setDroplistOpen: setDroplistOpen, size: size }))] })] }));
|
|
192
181
|
});
|
|
@@ -68,7 +68,7 @@ function TreeNodeActions({ getNodeActions, isDroplistTriggerFocused, focusNode,
|
|
|
68
68
|
if (!droplistActions.length) {
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
71
|
-
return ((0, jsx_runtime_1.jsx)("div", { role: 'presentation', className: styles_module_scss_1.default.treeNodeActions, "data-focused": isDroplistTriggerFocused || undefined, onClick: utils_1.stopPropagationClick, onKeyDown: handleKeyDown, onFocus: utils_1.stopPropagationFocus, children: (0, jsx_runtime_1.jsx)(list_1.Droplist, { open: isDroplistOpen, onOpenChange: open => {
|
|
71
|
+
return ((0, jsx_runtime_1.jsx)("div", { role: 'presentation', className: styles_module_scss_1.default.treeNodeActions, "data-focused": isDroplistTriggerFocused || undefined, onClick: utils_1.stopPropagationClick, onKeyDown: handleKeyDown, onFocus: utils_1.stopPropagationFocus, children: (0, jsx_runtime_1.jsx)(list_1.Droplist, { "data-test-id": constants_1.TEST_IDS.treeNodeActionsDroplist, open: isDroplistOpen, onOpenChange: open => {
|
|
72
72
|
setDroplistOpen(open);
|
|
73
73
|
if (open) {
|
|
74
74
|
return;
|
package/dist/esm/constants.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export declare const TRANSITION_TIMING: {
|
|
|
11
11
|
readonly accordionFolding: 200;
|
|
12
12
|
};
|
|
13
13
|
export declare const TEST_IDS: {
|
|
14
|
+
readonly expandableTreeNodeTreeNode: "expandable-tree-node__tree-node";
|
|
15
|
+
readonly treeNodeActionsDroplist: "tree-node-actions__droplist";
|
|
16
|
+
readonly treeNodeSpinner: "tree-node__spinner";
|
|
17
|
+
readonly treeNodeTreeNodeTitle: "tree-node__tree-node-title";
|
|
14
18
|
readonly node: "tree__node";
|
|
15
19
|
readonly line: "tree__node__line";
|
|
16
20
|
readonly item: "tree__node__item";
|
package/dist/esm/constants.js
CHANGED
|
@@ -11,6 +11,10 @@ export const TRANSITION_TIMING = {
|
|
|
11
11
|
accordionFolding: 200,
|
|
12
12
|
};
|
|
13
13
|
export const TEST_IDS = {
|
|
14
|
+
expandableTreeNodeTreeNode: 'expandable-tree-node__tree-node',
|
|
15
|
+
treeNodeActionsDroplist: 'tree-node-actions__droplist',
|
|
16
|
+
treeNodeSpinner: 'tree-node__spinner',
|
|
17
|
+
treeNodeTreeNodeTitle: 'tree-node__tree-node-title',
|
|
14
18
|
node: 'tree__node',
|
|
15
19
|
line: 'tree__node__line',
|
|
16
20
|
item: 'tree__node__item',
|
|
@@ -53,11 +53,11 @@ export const ExpandableTreeNode = forwardRef(({ node: { 'data-test-id': dataTest
|
|
|
53
53
|
const toggleExpand = async () => {
|
|
54
54
|
if (node.nested && !node.nested.length && !isExpanded && onDataLoad) {
|
|
55
55
|
setLoading(true);
|
|
56
|
-
await onDataLoad(node).finally(() => {
|
|
56
|
+
await onDataLoad({ ...node, 'data-test-id': dataTestId }).finally(() => {
|
|
57
57
|
setLoading(false);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
onExpand(node);
|
|
60
|
+
onExpand({ ...node, 'data-test-id': dataTestId });
|
|
61
61
|
toggle();
|
|
62
62
|
};
|
|
63
63
|
const handleKeyDown = e => {
|
|
@@ -80,7 +80,7 @@ export const ExpandableTreeNode = forwardRef(({ node: { 'data-test-id': dataTest
|
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
-
return (_jsxs("div", { className: styles.expandableTreeNode, "data-test-id": dataTestId, "data-expandable": Boolean(node.nested) || undefined, "data-disabled": node.disabled || undefined, ref: ref, children: [_jsx(TreeNode, { ...node, loading: loading, parentNode: parentNode, onChevronClick: toggleExpand, onKeyDown: handleKeyDown, tabIndexAvailable: tabIndexAvailable }), node.nested && (_jsx("div", { className: styles.expandableWrap, "data-expanded": isExpanded || undefined, "data-entered": state.status === 'entered' || 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, "data-test-id": TEST_IDS.line, style: { height: `calc(100% - ${lastItemHeight}px)` } }), _jsx("div", { className: styles.expandableNested, children: node.nested.map((nestedNode, index) => {
|
|
83
|
+
return (_jsxs("div", { className: styles.expandableTreeNode, "data-test-id": dataTestId, "data-expandable": Boolean(node.nested) || undefined, "data-disabled": node.disabled || undefined, ref: ref, children: [_jsx(TreeNode, { "data-test-id": TEST_IDS.expandableTreeNodeTreeNode, ...node, loading: loading, parentNode: parentNode, onChevronClick: toggleExpand, onKeyDown: handleKeyDown, tabIndexAvailable: tabIndexAvailable }), node.nested && (_jsx("div", { className: styles.expandableWrap, "data-expanded": isExpanded || undefined, "data-entered": state.status === 'entered' || 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, "data-test-id": TEST_IDS.line, style: { height: `calc(100% - ${lastItemHeight}px)` } }), _jsx("div", { className: styles.expandableNested, children: node.nested.map((nestedNode, index) => {
|
|
84
84
|
const parent = { id: node.id, nested: node.nested, parentNode };
|
|
85
85
|
return (_jsx(TreeItem, { ref: el => (childrenRefs.current[index] = el), node: { ...nestedNode, disabled: node.disabled || nestedNode.disabled }, parentNode: parent }, nestedNode.id));
|
|
86
86
|
}) })] })) }))] }));
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import type { WithSupportProps } from '@cloud-ru/ds-utils';
|
|
1
2
|
import { CSSProperties } from 'react';
|
|
2
|
-
export type TreeLineProps = {
|
|
3
|
+
export type TreeLineProps = WithSupportProps<{
|
|
3
4
|
className?: string;
|
|
4
5
|
/** Доп. инлайн-стили для контейнера (height/width передаются здесь, а не отдельными пропами). */
|
|
5
6
|
style?: CSSProperties;
|
|
6
7
|
halfWidth?: boolean;
|
|
7
8
|
visible?: boolean;
|
|
8
9
|
horizontal?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare function TreeLine({ className, style, halfWidth, horizontal, visible }: TreeLineProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function TreeLine({ className, style, halfWidth, horizontal, visible, ...supportProps }: TreeLineProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,6 +2,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import cn from 'classnames';
|
|
3
3
|
import { TEST_IDS } from '../../constants.js';
|
|
4
4
|
import styles from './styles.module.css';
|
|
5
|
-
export function TreeLine({ className, style, halfWidth, horizontal, visible }) {
|
|
6
|
-
return (_jsx("div", { className: cn(styles.treeLine, className), style: style, "data-horizontal": horizontal || undefined, "data-half-width": halfWidth || undefined, "data-visible": visible || undefined, "data-test-id": TEST_IDS.line }));
|
|
5
|
+
export function TreeLine({ className, style, halfWidth, horizontal, visible, ...supportProps }) {
|
|
6
|
+
return (_jsx("div", { className: cn(styles.treeLine, className), style: style, "data-horizontal": horizontal || undefined, "data-half-width": halfWidth || undefined, "data-visible": visible || undefined, ...supportProps, "data-test-id": supportProps['data-test-id'] ?? TEST_IDS.line }));
|
|
7
7
|
}
|
|
@@ -67,14 +67,7 @@ export const TreeNode = forwardRef(({ id, title, icon: iconProp, expandedIcon: e
|
|
|
67
67
|
return iconProp ?? _jsx(FileSVG, {});
|
|
68
68
|
}, [showIcons, isExpandable, isExpanded, iconProp, expandedIconProp, collapsedIconProp]);
|
|
69
69
|
const handleClick = e => {
|
|
70
|
-
onNodeClick({
|
|
71
|
-
id,
|
|
72
|
-
title,
|
|
73
|
-
disabled,
|
|
74
|
-
nested,
|
|
75
|
-
onClick,
|
|
76
|
-
href,
|
|
77
|
-
}, e);
|
|
70
|
+
onNodeClick({ 'data-test-id': rest['data-test-id'], id, title, disabled, nested, onClick, href }, e);
|
|
78
71
|
};
|
|
79
72
|
const handleAnchorClick = (e) => {
|
|
80
73
|
e.stopPropagation();
|
|
@@ -175,12 +168,8 @@ export const TreeNode = forwardRef(({ id, title, icon: iconProp, expandedIcon: e
|
|
|
175
168
|
}
|
|
176
169
|
};
|
|
177
170
|
const getNodeActions = nested ? parentActions : nodeActions;
|
|
178
|
-
return (_jsxs("div", { role: 'presentation', className: cn(styles.treeNode, className), ...extractSupportProps(rest), "data-node-id": id, "data-size": size, ref: ref, children: [parentNode && _jsx(TreeLine, { halfWidth: isExpandable, horizontal: true, visible: showLines }), (isExpandable || !parentNode) && (_jsx("div", { className: styles.treeNodeExpandButtonWrapper, children: isExpandable ? (_jsxs(_Fragment, { children: [_jsxs("button", { type: 'button', onClick: onChevronClick, "data-expanded": isExpanded || undefined, className: styles.treeNodeExpandButton, tabIndex: -1, "data-test-id": TEST_IDS.chevron, "aria-label": isExpanded ? 'Collapse' : 'Expand', children: [_jsx("span", { className: styles.treeNodeExpandButtonStateLayer, "aria-hidden": true, "data-state": 'emptyNeutralOnBackground' }), loading ? _jsx(Spinner, { size: SPINNER_SIZE_BY_TREE_SIZE[size] }) : _jsx(ChevronRightSVG, {})] }), _jsx(TreeLine, { visible: isExpanded && showLines })] })) : (_jsx("div", { className: styles.treeNodeExpandButtonSpacer, "aria-hidden": true })) })), _jsxs("div", { role: 'treeitem', "aria-expanded": isExpanded, "aria-selected": isSelectable
|
|
171
|
+
return (_jsxs("div", { role: 'presentation', className: cn(styles.treeNode, className), ...extractSupportProps(rest), "data-node-id": id, "data-size": size, ref: ref, children: [parentNode && (_jsx(TreeLine, { "data-test-id": TEST_IDS.line, halfWidth: isExpandable, horizontal: true, visible: showLines })), (isExpandable || !parentNode) && (_jsx("div", { className: styles.treeNodeExpandButtonWrapper, children: isExpandable ? (_jsxs(_Fragment, { children: [_jsxs("button", { type: 'button', onClick: onChevronClick, "data-expanded": isExpanded || undefined, className: styles.treeNodeExpandButton, tabIndex: -1, "data-test-id": TEST_IDS.chevron, "aria-label": isExpanded ? 'Collapse' : 'Expand', children: [_jsx("span", { className: styles.treeNodeExpandButtonStateLayer, "aria-hidden": true, "data-state": 'emptyNeutralOnBackground' }), loading ? (_jsx(Spinner, { "data-test-id": TEST_IDS.treeNodeSpinner, size: SPINNER_SIZE_BY_TREE_SIZE[size] })) : (_jsx(ChevronRightSVG, {}))] }), _jsx(TreeLine, { "data-test-id": TEST_IDS.line, visible: isExpanded && showLines })] })) : (_jsx("div", { className: styles.treeNodeExpandButtonSpacer, "aria-hidden": true })) })), _jsxs("div", { role: 'treeitem', "aria-expanded": isExpanded, "aria-selected": isSelectable
|
|
179
172
|
? isSelected || (nestedNodesSelection?.someSelected && !isExpanded && !isMultiSelect)
|
|
180
|
-
: undefined, "aria-disabled": disabled, "data-disabled": disabled || undefined, "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: contentRef, children: [_jsx("span", { className: styles.stateLayer, "aria-hidden": true, "data-state": isSelected && !isMultiSelect ? 'activatedOnBackground' : 'emptyNeutralOnBackground' }), (isMultiSelect || showToggle) && (_jsxs("div", { className: styles.treeNodeCheckboxWrap, children: [isMultiSelect && (_jsx(Checkbox, { size: CONTROL_SIZE_BY_TREE_SIZE[size], disabled: disabled, checked: isSelected, indeterminate: isIndeterminate, onChange: handleSelect, onClick: stopPropagationClick, "data-test-id": TEST_IDS.checkbox, tabIndex: -1 })), showToggle && (_jsx(Radio, { size: CONTROL_SIZE_BY_TREE_SIZE[size], checked: isSelected, disabled: disabled, "data-test-id": TEST_IDS.radio, tabIndex: -1 }))] })), _jsxs("div", { className: styles.treeNodeContentWrapper, children: [treeNodeIcon && (_jsx("div", { className: styles.treeNodeIcon, "data-test-id": TEST_IDS.icon, children: treeNodeIcon })), _jsx(Typography, { variant: 'body', size: size, as: 'div', className: styles.treeNodeTitle, children: _jsx("div", { className: styles.treeNodeTextContent, children: _jsxs(TreeNodeHref, { href: href, onClick: handleAnchorClick, ref: anchorRef, children: [typeof title === 'string' && (_jsx(TruncateString, { text: title, maxLines: titleMaxLines, "data-test-id": TEST_IDS.title })), typeof title !== 'string' &&
|
|
181
|
-
|
|
182
|
-
title,
|
|
183
|
-
disabled,
|
|
184
|
-
nested,
|
|
185
|
-
}, focusNode: handleFocus, onBlurActions: handleBlurActions, isDroplistTriggerFocused: isDroplistTriggerFocused, isDroplistOpen: isDroplistOpen, setDroplistOpen: setDroplistOpen, size: size }))] })] }));
|
|
173
|
+
: undefined, "aria-disabled": disabled, "data-disabled": disabled || undefined, "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: contentRef, children: [_jsx("span", { className: styles.stateLayer, "aria-hidden": true, "data-state": isSelected && !isMultiSelect ? 'activatedOnBackground' : 'emptyNeutralOnBackground' }), (isMultiSelect || showToggle) && (_jsxs("div", { className: styles.treeNodeCheckboxWrap, children: [isMultiSelect && (_jsx(Checkbox, { size: CONTROL_SIZE_BY_TREE_SIZE[size], disabled: disabled, checked: isSelected, indeterminate: isIndeterminate, onChange: handleSelect, onClick: stopPropagationClick, "data-test-id": TEST_IDS.checkbox, tabIndex: -1 })), showToggle && (_jsx(Radio, { size: CONTROL_SIZE_BY_TREE_SIZE[size], checked: isSelected, disabled: disabled, "data-test-id": TEST_IDS.radio, tabIndex: -1 }))] })), _jsxs("div", { className: styles.treeNodeContentWrapper, children: [treeNodeIcon && (_jsx("div", { className: styles.treeNodeIcon, "data-test-id": TEST_IDS.icon, children: treeNodeIcon })), _jsx(Typography, { "data-test-id": TEST_IDS.treeNodeTreeNodeTitle, variant: 'body', size: size, as: 'div', className: styles.treeNodeTitle, children: _jsx("div", { className: styles.treeNodeTextContent, children: _jsxs(TreeNodeHref, { href: href, onClick: handleAnchorClick, ref: anchorRef, children: [typeof title === 'string' && (_jsx(TruncateString, { text: title, maxLines: titleMaxLines, "data-test-id": TEST_IDS.title })), typeof title !== 'string' &&
|
|
174
|
+
title({ 'data-test-id': rest['data-test-id'], id, disabled, nested })] }) }) })] }), getNodeActions && (_jsx(TreeNodeActions, { getNodeActions: getNodeActions, node: { 'data-test-id': rest['data-test-id'], id, title, disabled, nested }, focusNode: handleFocus, onBlurActions: handleBlurActions, isDroplistTriggerFocused: isDroplistTriggerFocused, isDroplistOpen: isDroplistOpen, setDroplistOpen: setDroplistOpen, size: size }))] })] }));
|
|
186
175
|
});
|
|
@@ -62,7 +62,7 @@ export function TreeNodeActions({ getNodeActions, isDroplistTriggerFocused, focu
|
|
|
62
62
|
if (!droplistActions.length) {
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
|
-
return (_jsx("div", { role: 'presentation', className: styles.treeNodeActions, "data-focused": isDroplistTriggerFocused || undefined, onClick: stopPropagationClick, onKeyDown: handleKeyDown, onFocus: stopPropagationFocus, children: _jsx(Droplist, { open: isDroplistOpen, onOpenChange: open => {
|
|
65
|
+
return (_jsx("div", { role: 'presentation', className: styles.treeNodeActions, "data-focused": isDroplistTriggerFocused || undefined, onClick: stopPropagationClick, onKeyDown: handleKeyDown, onFocus: stopPropagationFocus, children: _jsx(Droplist, { "data-test-id": TEST_IDS.treeNodeActionsDroplist, open: isDroplistOpen, onOpenChange: open => {
|
|
66
66
|
setDroplistOpen(open);
|
|
67
67
|
if (open) {
|
|
68
68
|
return;
|