@pega/cosmos-react-core 4.0.0-dev.6.1 → 4.0.0-dev.8.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/lib/components/Backdrop/Backdrop.d.ts.map +1 -1
- package/lib/components/Backdrop/Backdrop.js +22 -2
- package/lib/components/Backdrop/Backdrop.js.map +1 -1
- package/lib/components/Banner/Banner.d.ts +9 -1
- package/lib/components/Banner/Banner.d.ts.map +1 -1
- package/lib/components/Banner/Banner.js +21 -10
- package/lib/components/Banner/Banner.js.map +1 -1
- package/lib/components/Banner/index.d.ts +1 -1
- package/lib/components/Banner/index.d.ts.map +1 -1
- package/lib/components/Banner/index.js.map +1 -1
- package/lib/components/Card/Card.d.ts +4 -7
- package/lib/components/Card/Card.d.ts.map +1 -1
- package/lib/components/Card/Card.js +2 -9
- package/lib/components/Card/Card.js.map +1 -1
- package/lib/components/Configuration/Configuration.d.ts +4 -1
- package/lib/components/Configuration/Configuration.d.ts.map +1 -1
- package/lib/components/Configuration/Configuration.js +2 -0
- package/lib/components/Configuration/Configuration.js.map +1 -1
- package/lib/components/DateTime/DateTime.types.d.ts +4 -1
- package/lib/components/DateTime/DateTime.types.d.ts.map +1 -1
- package/lib/components/DateTime/DateTime.types.js.map +1 -1
- package/lib/components/DateTime/Input/DateInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateInput.js +12 -1
- package/lib/components/DateTime/Input/DateInput.js.map +1 -1
- package/lib/components/DateTime/Input/DateRangeInput.d.ts +4 -2
- package/lib/components/DateTime/Input/DateRangeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateRangeInput.js +71 -34
- package/lib/components/DateTime/Input/DateRangeInput.js.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.js +19 -2
- package/lib/components/DateTime/Input/DateTimeInput.js.map +1 -1
- package/lib/components/DateTime/Input/PartInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/PartInput.js +2 -2
- package/lib/components/DateTime/Input/PartInput.js.map +1 -1
- package/lib/components/DateTime/Input/TimeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/TimeInput.js +13 -2
- package/lib/components/DateTime/Input/TimeInput.js.map +1 -1
- package/lib/components/DateTime/Input/TimeRangeInput.d.ts +4 -2
- package/lib/components/DateTime/Input/TimeRangeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/TimeRangeInput.js +70 -27
- package/lib/components/DateTime/Input/TimeRangeInput.js.map +1 -1
- package/lib/components/Dialog/FormDialog.d.ts.map +1 -1
- package/lib/components/Dialog/FormDialog.js +2 -6
- package/lib/components/Dialog/FormDialog.js.map +1 -1
- package/lib/components/Dialog/InfoDialog.d.ts.map +1 -1
- package/lib/components/Dialog/InfoDialog.js +2 -6
- package/lib/components/Dialog/InfoDialog.js.map +1 -1
- package/lib/components/FormControl/FormControl.d.ts +4 -0
- package/lib/components/FormControl/FormControl.d.ts.map +1 -1
- package/lib/components/FormControl/FormControl.js.map +1 -1
- package/lib/components/FormControl/index.d.ts +1 -0
- package/lib/components/FormControl/index.d.ts.map +1 -1
- package/lib/components/FormControl/index.js.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.d.ts.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.js +84 -66
- package/lib/components/ListToolbar/ListToolbar.js.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.styles.d.ts +2 -0
- package/lib/components/ListToolbar/ListToolbar.styles.d.ts.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.styles.js +37 -5
- package/lib/components/ListToolbar/ListToolbar.styles.js.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.types.d.ts +4 -4
- package/lib/components/ListToolbar/ListToolbar.types.d.ts.map +1 -1
- package/lib/components/ListToolbar/ListToolbar.types.js.map +1 -1
- package/lib/components/LiveLog/Context.d.ts +3 -0
- package/lib/components/LiveLog/Context.d.ts.map +1 -0
- package/lib/components/LiveLog/Context.js +9 -0
- package/lib/components/LiveLog/Context.js.map +1 -0
- package/lib/components/LiveLog/LiveLog.d.ts +10 -0
- package/lib/components/LiveLog/LiveLog.d.ts.map +1 -0
- package/lib/components/LiveLog/LiveLog.js +99 -0
- package/lib/components/LiveLog/LiveLog.js.map +1 -0
- package/lib/components/LiveLog/LiveLog.styles.d.ts +3 -0
- package/lib/components/LiveLog/LiveLog.styles.d.ts.map +1 -0
- package/lib/components/LiveLog/LiveLog.styles.js +9 -0
- package/lib/components/LiveLog/LiveLog.styles.js.map +1 -0
- package/lib/components/LiveLog/LiveLog.types.d.ts +93 -0
- package/lib/components/LiveLog/LiveLog.types.d.ts.map +1 -0
- package/lib/components/LiveLog/LiveLog.types.js +2 -0
- package/lib/components/LiveLog/LiveLog.types.js.map +1 -0
- package/lib/components/LiveLog/index.d.ts +4 -0
- package/lib/components/LiveLog/index.d.ts.map +1 -0
- package/lib/components/LiveLog/index.js +3 -0
- package/lib/components/LiveLog/index.js.map +1 -0
- package/lib/components/Menu/Menu.d.ts.map +1 -1
- package/lib/components/Menu/Menu.js +2 -0
- package/lib/components/Menu/Menu.js.map +1 -1
- package/lib/components/Menu/MenuList.d.ts.map +1 -1
- package/lib/components/Menu/MenuList.js +4 -3
- package/lib/components/Menu/MenuList.js.map +1 -1
- package/lib/components/Modal/Modal.d.ts.map +1 -1
- package/lib/components/Modal/Modal.js +6 -8
- package/lib/components/Modal/Modal.js.map +1 -1
- package/lib/components/Modal/Modal.types.d.ts +1 -0
- package/lib/components/Modal/Modal.types.d.ts.map +1 -1
- package/lib/components/Modal/Modal.types.js.map +1 -1
- package/lib/components/Number/NumberInput.types.d.ts +3 -1
- package/lib/components/Number/NumberInput.types.d.ts.map +1 -1
- package/lib/components/Number/NumberInput.types.js.map +1 -1
- package/lib/components/Number/NumberRangeInput.d.ts.map +1 -1
- package/lib/components/Number/NumberRangeInput.js +71 -4
- package/lib/components/Number/NumberRangeInput.js.map +1 -1
- package/lib/components/PageTemplates/CategorySubPage.d.ts.map +1 -1
- package/lib/components/PageTemplates/CategorySubPage.js +14 -3
- package/lib/components/PageTemplates/CategorySubPage.js.map +1 -1
- package/lib/components/PageTemplates/CategorySubPage.styles.d.ts.map +1 -1
- package/lib/components/PageTemplates/CategorySubPage.styles.js +5 -0
- package/lib/components/PageTemplates/CategorySubPage.styles.js.map +1 -1
- package/lib/components/PageTemplates/DashboardPage.d.ts.map +1 -1
- package/lib/components/PageTemplates/DashboardPage.js +16 -2
- package/lib/components/PageTemplates/DashboardPage.js.map +1 -1
- package/lib/components/PageTemplates/PageTemplates.d.ts.map +1 -1
- package/lib/components/PageTemplates/PageTemplates.js +20 -3
- package/lib/components/PageTemplates/PageTemplates.js.map +1 -1
- package/lib/components/Popover/Popover.d.ts.map +1 -1
- package/lib/components/Popover/Popover.js +2 -5
- package/lib/components/Popover/Popover.js.map +1 -1
- package/lib/components/Popover/Popover.styles.d.ts +0 -1
- package/lib/components/Popover/Popover.styles.d.ts.map +1 -1
- package/lib/components/Popover/Popover.styles.js +0 -6
- package/lib/components/Popover/Popover.styles.js.map +1 -1
- package/lib/components/Popover/modifiers.d.ts +0 -2
- package/lib/components/Popover/modifiers.d.ts.map +1 -1
- package/lib/components/Popover/modifiers.js +1 -32
- package/lib/components/Popover/modifiers.js.map +1 -1
- package/lib/components/Progress/Progress.d.ts.map +1 -1
- package/lib/components/Progress/Progress.js +92 -50
- package/lib/components/Progress/Progress.js.map +1 -1
- package/lib/components/Progress/Progress.styles.d.ts.map +1 -1
- package/lib/components/Progress/Progress.styles.js +0 -1
- package/lib/components/Progress/Progress.styles.js.map +1 -1
- package/lib/components/Progress/Progress.types.d.ts +18 -6
- package/lib/components/Progress/Progress.types.d.ts.map +1 -1
- package/lib/components/Progress/Progress.types.js.map +1 -1
- package/lib/components/Progress/index.d.ts +1 -1
- package/lib/components/Progress/index.d.ts.map +1 -1
- package/lib/components/Progress/index.js.map +1 -1
- package/lib/components/QRCode/QRCode.d.ts +14 -0
- package/lib/components/QRCode/QRCode.d.ts.map +1 -0
- package/lib/components/QRCode/QRCode.js +39 -0
- package/lib/components/QRCode/QRCode.js.map +1 -0
- package/lib/components/QRCode/index.d.ts +3 -0
- package/lib/components/QRCode/index.d.ts.map +1 -0
- package/lib/components/QRCode/index.js +2 -0
- package/lib/components/QRCode/index.js.map +1 -0
- package/lib/components/SearchInput/SearchInput.d.ts.map +1 -1
- package/lib/components/SearchInput/SearchInput.js +27 -7
- package/lib/components/SearchInput/SearchInput.js.map +1 -1
- package/lib/components/Tabs/Tabs.d.ts.map +1 -1
- package/lib/components/Tabs/Tabs.js +6 -0
- package/lib/components/Tabs/Tabs.js.map +1 -1
- package/lib/components/Toaster/Context.d.ts +1 -0
- package/lib/components/Toaster/Context.d.ts.map +1 -1
- package/lib/components/Toaster/Context.js.map +1 -1
- package/lib/components/Toaster/Toaster.d.ts.map +1 -1
- package/lib/components/Toaster/Toaster.js +5 -1
- package/lib/components/Toaster/Toaster.js.map +1 -1
- package/lib/components/Tree/StandardTree.d.ts.map +1 -1
- package/lib/components/Tree/StandardTree.js +70 -27
- package/lib/components/Tree/StandardTree.js.map +1 -1
- package/lib/components/Tree/StandardTree.styles.d.ts +1 -0
- package/lib/components/Tree/StandardTree.styles.d.ts.map +1 -1
- package/lib/components/Tree/StandardTree.styles.js +32 -18
- package/lib/components/Tree/StandardTree.styles.js.map +1 -1
- package/lib/components/Tree/StandardTree.types.d.ts +27 -0
- package/lib/components/Tree/StandardTree.types.d.ts.map +1 -1
- package/lib/components/Tree/StandardTree.types.js.map +1 -1
- package/lib/components/Tree/helpers.d.ts +11 -9
- package/lib/components/Tree/helpers.d.ts.map +1 -1
- package/lib/components/Tree/helpers.js +25 -5
- package/lib/components/Tree/helpers.js.map +1 -1
- package/lib/components/Tree/index.d.ts +1 -1
- package/lib/components/Tree/index.d.ts.map +1 -1
- package/lib/components/Tree/index.js.map +1 -1
- package/lib/components/URL/URLDisplay.d.ts +2 -2
- package/lib/components/URL/URLDisplay.d.ts.map +1 -1
- package/lib/components/URL/URLDisplay.js +8 -1
- package/lib/components/URL/URLDisplay.js.map +1 -1
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.d.ts.map +1 -1
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useArrows.d.ts.map +1 -1
- package/lib/hooks/useArrows.js +3 -3
- package/lib/hooks/useArrows.js.map +1 -1
- package/lib/hooks/useBreakpoint.d.ts.map +1 -1
- package/lib/hooks/useBreakpoint.js +3 -2
- package/lib/hooks/useBreakpoint.js.map +1 -1
- package/lib/hooks/useI18n.d.ts +43 -0
- package/lib/hooks/useI18n.d.ts.map +1 -1
- package/lib/hooks/useLiveLog.d.ts +8 -0
- package/lib/hooks/useLiveLog.d.ts.map +1 -0
- package/lib/hooks/useLiveLog.js +16 -0
- package/lib/hooks/useLiveLog.js.map +1 -0
- package/lib/i18n/default.d.ts +43 -0
- package/lib/i18n/default.d.ts.map +1 -1
- package/lib/i18n/default.js +50 -6
- package/lib/i18n/default.js.map +1 -1
- package/lib/i18n/i18n.d.ts +43 -0
- package/lib/i18n/i18n.d.ts.map +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/lib/register-contexts.js +2 -0
- package/lib/register-contexts.js.map +1 -1
- package/lib/theme/theme.d.ts +12 -0
- package/lib/theme/theme.d.ts.map +1 -1
- package/lib/theme/themeDefinition.json +8 -0
- package/lib/theme/themes/darkTheme.json +3 -1
- package/lib/types/types.d.ts +3 -0
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/types.js.map +1 -1
- package/package.json +3 -1
- package/lib/components/ListToolbar/QueryOptionPopover.d.ts +0 -12
- package/lib/components/ListToolbar/QueryOptionPopover.d.ts.map +0 -1
- package/lib/components/ListToolbar/QueryOptionPopover.js +0 -36
- package/lib/components/ListToolbar/QueryOptionPopover.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, createContext, useMemo, useContext, useCallback, useState, useEffect, useRef } from 'react';
|
|
3
3
|
import Progress from '../Progress';
|
|
4
|
-
import { useDirection } from '../../hooks';
|
|
4
|
+
import { useConsolidatedRef, useDirection, useFocusWithin } from '../../hooks';
|
|
5
5
|
import Flex from '../Flex';
|
|
6
|
-
import Button from '../Button';
|
|
7
6
|
import Actions from '../Actions';
|
|
8
7
|
import { cap } from '../../utils';
|
|
9
|
-
import
|
|
8
|
+
import Button from '../Button';
|
|
9
|
+
import { StyledStandardTreeParent, StyledToggleIcon, StyledToggleIconWrapper, StyledStandardTreeItemSubTree, StyledStandardTreeLeaf, StyledStandardTree, StyledNodeInteraction, StyledStandardTreeNode, StyledNodeActions, StyledLabelContent, StyledNodeIcon, StyledNodeText } from './StandardTree.styles';
|
|
10
10
|
import helpers from './helpers';
|
|
11
11
|
const StandardTreeContext = createContext({
|
|
12
12
|
currentNodeId: undefined,
|
|
@@ -16,20 +16,24 @@ const StandardTreeContext = createContext({
|
|
|
16
16
|
firstNodeId: undefined,
|
|
17
17
|
lastNodeId: undefined,
|
|
18
18
|
focusedNodeId: undefined,
|
|
19
|
-
changeFocusedNodeId: () => { }
|
|
19
|
+
changeFocusedNodeId: () => { },
|
|
20
|
+
selectableParents: true
|
|
20
21
|
});
|
|
21
|
-
const NodeRenderer = ({ id, label, icon, depth, hasParentSibling, nodes, expanded = false, loading = false, subTree, actions, onClick }) => {
|
|
22
|
-
const { currentNodeId, onNodeClick, onNodeToggle, lined, focusedNodeId, changeFocusedNodeId, firstNodeId, lastNodeId } = useContext(StandardTreeContext);
|
|
22
|
+
const NodeRenderer = ({ id, label, icon, depth, hasParentSibling, nodes, expanded = false, loading = false, subTree, actions, onClick, href }) => {
|
|
23
|
+
const { currentNodeId, onNodeClick, onNodeToggle, lined, focusedNodeId, changeFocusedNodeId, firstNodeId, lastNodeId, selectableParents } = useContext(StandardTreeContext);
|
|
23
24
|
const current = currentNodeId === id;
|
|
24
25
|
const focusedEl = focusedNodeId === id;
|
|
25
26
|
const firstNode = firstNodeId === id;
|
|
26
27
|
const { start, end } = useDirection();
|
|
28
|
+
const ariaCurrent = useMemo(() => {
|
|
29
|
+
return href ? 'page' : 'true';
|
|
30
|
+
}, [href]);
|
|
27
31
|
const tabIndex = useMemo(() => {
|
|
28
32
|
let index = -1;
|
|
29
33
|
if (focusedNodeId) {
|
|
30
34
|
index = focusedEl ? 0 : -1;
|
|
31
35
|
}
|
|
32
|
-
else if (currentNodeId) {
|
|
36
|
+
else if (currentNodeId && nodes && helpers.getNode(nodes, currentNodeId)) {
|
|
33
37
|
index = current ? 0 : -1;
|
|
34
38
|
}
|
|
35
39
|
else {
|
|
@@ -37,12 +41,20 @@ const NodeRenderer = ({ id, label, icon, depth, hasParentSibling, nodes, expande
|
|
|
37
41
|
}
|
|
38
42
|
return index;
|
|
39
43
|
}, [focusedNodeId, currentNodeId, current, focusedEl]);
|
|
40
|
-
const
|
|
44
|
+
const handleParentClick = useCallback((e) => {
|
|
41
45
|
onNodeClick?.(id, e);
|
|
42
46
|
changeFocusedNodeId(id);
|
|
43
47
|
}, [id, onNodeClick, changeFocusedNodeId]);
|
|
48
|
+
const handleParentToggle = useCallback((e) => {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
onNodeToggle?.(id, e);
|
|
52
|
+
changeFocusedNodeId(id);
|
|
53
|
+
}, [id, onNodeToggle, changeFocusedNodeId]);
|
|
44
54
|
const onKeyDown = useCallback((e) => {
|
|
45
|
-
if (['ArrowUp', 'ArrowDown', '
|
|
55
|
+
if (['ArrowUp', 'ArrowDown', 'Home', 'End'].includes(e.key))
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
if (e.key === 'Enter' && !href)
|
|
46
58
|
e.preventDefault();
|
|
47
59
|
switch (e.key) {
|
|
48
60
|
case 'ArrowUp':
|
|
@@ -70,11 +82,18 @@ const NodeRenderer = ({ id, label, icon, depth, hasParentSibling, nodes, expande
|
|
|
70
82
|
}
|
|
71
83
|
break;
|
|
72
84
|
case 'Enter':
|
|
73
|
-
|
|
74
|
-
|
|
85
|
+
onClick?.(id, e);
|
|
86
|
+
if (nodes) {
|
|
87
|
+
if (selectableParents) {
|
|
88
|
+
handleParentClick(e);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
handleParentToggle(e);
|
|
92
|
+
}
|
|
75
93
|
}
|
|
76
94
|
else {
|
|
77
|
-
|
|
95
|
+
onNodeClick?.(id, e);
|
|
96
|
+
changeFocusedNodeId(id);
|
|
78
97
|
}
|
|
79
98
|
break;
|
|
80
99
|
case 'Home':
|
|
@@ -95,11 +114,19 @@ const NodeRenderer = ({ id, label, icon, depth, hasParentSibling, nodes, expande
|
|
|
95
114
|
...action,
|
|
96
115
|
onClick: (actionId, e) => {
|
|
97
116
|
e.stopPropagation();
|
|
117
|
+
e.preventDefault();
|
|
98
118
|
action?.onClick?.(actionId, e);
|
|
119
|
+
},
|
|
120
|
+
onKeyDown: (e) => {
|
|
121
|
+
if (e.key === 'Enter')
|
|
122
|
+
e.stopPropagation();
|
|
99
123
|
}
|
|
100
124
|
};
|
|
101
125
|
}), menuAt: 3, menuButtonProps: {
|
|
102
|
-
onClick: (e) =>
|
|
126
|
+
onClick: (e) => {
|
|
127
|
+
e.stopPropagation();
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
},
|
|
103
130
|
onKeyDown: (e) => {
|
|
104
131
|
e.stopPropagation();
|
|
105
132
|
if (['ArrowUp', 'ArrowDown'].includes(e.key)) {
|
|
@@ -118,11 +145,11 @@ const NodeRenderer = ({ id, label, icon, depth, hasParentSibling, nodes, expande
|
|
|
118
145
|
const internal = (
|
|
119
146
|
// Wrapping in a div for handling of flex space-between when there are node actions.
|
|
120
147
|
_jsxs(Flex, { container: { alignItems: 'center', gap: 0.5 }, as: StyledLabelContent, children: [icon && _jsx(StyledNodeIcon, { name: icon }), _jsx(StyledNodeText, { children: label })] }));
|
|
121
|
-
return !nodes && (onClick ?? onNodeClick) ? (_jsxs(Flex, { container: { alignItems: 'center', justify: 'between', gap: 2 }, as: StyledNodeInteraction, role: 'treeitem', "aria-current": current ?
|
|
148
|
+
return !nodes && (onClick ?? onNodeClick) ? (_jsxs(Flex, { container: { alignItems: 'center', justify: 'between', gap: 2 }, as: StyledNodeInteraction, forwardedAs: href ? 'a' : 'div', role: 'treeitem', "aria-current": current ? ariaCurrent : undefined, tabIndex: tabIndex, onClick: (e) => {
|
|
122
149
|
onClick?.(id, e);
|
|
123
150
|
onNodeClick?.(id, e);
|
|
124
151
|
changeFocusedNodeId(id);
|
|
125
|
-
}, onKeyDown: onKeyDown, ref: elRef, children: [internal, actionsJSX] })) : (internal);
|
|
152
|
+
}, href: href, onKeyDown: onKeyDown, ref: elRef, children: [internal, actionsJSX] })) : (internal);
|
|
126
153
|
}, [
|
|
127
154
|
id,
|
|
128
155
|
label,
|
|
@@ -137,16 +164,15 @@ const NodeRenderer = ({ id, label, icon, depth, hasParentSibling, nodes, expande
|
|
|
137
164
|
changeFocusedNodeId,
|
|
138
165
|
onKeyDown
|
|
139
166
|
]);
|
|
140
|
-
return (_jsx(StyledStandardTreeNode, { id: id, style: {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
}, children: _jsx(StyledToggleIcon, { name: 'caret-right' }) }), labelContent] }), actionsJSX] }), _jsxs(StyledStandardTreeItemSubTree, { lined: lined, children: [subTree, loading && _jsx(Progress, { variant: 'ring', placement: 'inline' })] })] })) : (_jsx(StyledStandardTreeLeaf, { children: labelContent })) }));
|
|
167
|
+
return (_jsx(StyledStandardTreeNode, { id: id, style: {
|
|
168
|
+
'--depth': depth,
|
|
169
|
+
'--has-parent': depth ? 1 : 0,
|
|
170
|
+
'--has-parent-sibling': hasParentSibling ? 1 : 0
|
|
171
|
+
}, "aria-busy": loading, children: nodes ? (_jsxs(_Fragment, { children: [_jsxs(Flex, { container: { alignItems: 'center', justify: 'between', gap: 2 }, as: StyledStandardTreeParent, forwardedAs: href ? 'a' : 'div', role: 'treeitem', "aria-current": current ? ariaCurrent : undefined, tabIndex: tabIndex, variant: 'text', onClick: selectableParents ? handleParentClick : handleParentToggle, href: selectableParents ? href : undefined, "aria-expanded": expanded ? 'true' : 'false', "aria-owns": `${id}-subtree`, "aria-label": label, onKeyDown: onKeyDown, ref: elRef, children: [_jsxs(Flex, { container: { alignItems: 'center' }, as: 'span', children: [selectableParents ? (_jsx(Button, { variant: 'simple', tabIndex: -1, icon: true, compact: true, onClick: handleParentToggle, children: _jsx(StyledToggleIcon, { name: 'caret-right' }) })) : (_jsx(Flex, { as: StyledToggleIconWrapper, container: { justify: 'center', alignItems: 'center' }, children: _jsx(StyledToggleIcon, { name: 'caret-right' }) })), labelContent] }), actionsJSX] }), _jsxs(StyledStandardTreeItemSubTree, { lined: lined, id: `${id}-subtree`, children: [subTree, loading && _jsx(Progress, { variant: 'ring', placement: 'inline' })] })] })) : (_jsx(StyledStandardTreeLeaf, { children: labelContent })) }));
|
|
147
172
|
};
|
|
148
|
-
const StandardTreeWithNodes = forwardRef(({ nodes, currentNodeId, onNodeClick, onNodeToggle, lined = false, ...restProps }, ref) => {
|
|
173
|
+
const StandardTreeWithNodes = forwardRef(({ nodes, currentNodeId, onNodeClick, onNodeToggle, lined = false, selectableParents = true, ...restProps }, ref) => {
|
|
149
174
|
const [focusedNodeId, setFocusedNodedId] = useState();
|
|
175
|
+
const treeRef = useConsolidatedRef(ref);
|
|
150
176
|
const lastNodeId = useMemo(() => {
|
|
151
177
|
return helpers.getDeepestNode(nodes, nodes[nodes.length - 1].id)?.id;
|
|
152
178
|
}, [nodes]);
|
|
@@ -176,10 +202,18 @@ const StandardTreeWithNodes = forwardRef(({ nodes, currentNodeId, onNodeClick, o
|
|
|
176
202
|
setFocusedNodedId(childNode.id);
|
|
177
203
|
break;
|
|
178
204
|
}
|
|
179
|
-
default:
|
|
180
|
-
|
|
205
|
+
default: {
|
|
206
|
+
if (id !== focusedNodeId)
|
|
207
|
+
setFocusedNodedId(id);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
181
210
|
}
|
|
182
211
|
}, [nodes]);
|
|
212
|
+
const onFocusChange = (focused) => {
|
|
213
|
+
if (!focused)
|
|
214
|
+
setFocusedNodedId('');
|
|
215
|
+
};
|
|
216
|
+
useFocusWithin([treeRef], onFocusChange);
|
|
183
217
|
return (_jsx(StandardTreeContext.Provider, { value: useMemo(() => ({
|
|
184
218
|
currentNodeId,
|
|
185
219
|
focusedNodeId,
|
|
@@ -188,8 +222,17 @@ const StandardTreeWithNodes = forwardRef(({ nodes, currentNodeId, onNodeClick, o
|
|
|
188
222
|
changeFocusedNodeId,
|
|
189
223
|
onNodeClick,
|
|
190
224
|
onNodeToggle,
|
|
191
|
-
lined
|
|
192
|
-
|
|
225
|
+
lined,
|
|
226
|
+
selectableParents
|
|
227
|
+
}), [
|
|
228
|
+
currentNodeId,
|
|
229
|
+
onNodeClick,
|
|
230
|
+
lined,
|
|
231
|
+
focusedNodeId,
|
|
232
|
+
lastNodeId,
|
|
233
|
+
onNodeToggle,
|
|
234
|
+
selectableParents
|
|
235
|
+
]), children: _jsx(StyledStandardTree, { ...restProps, ref: treeRef, nodes: nodes, nodeRenderer: NodeRenderer }) }));
|
|
193
236
|
});
|
|
194
237
|
const StandardTree = forwardRef((props, ref) => {
|
|
195
238
|
return props.nodes.length > 0 ? _jsx(StandardTreeWithNodes, { ...props, ref: ref }) : null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StandardTree.js","sourceRoot":"","sources":["../../../src/components/Tree/StandardTree.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,OAAO,EACP,UAAU,EACV,WAAW,EACX,QAAQ,EAER,SAAS,EACT,MAAM,EACP,MAAM,OAAO,C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ACb,aAAa;YACb,UAAU;YACV,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;YACxB,mBAAmB;YACnB,WAAW;YACX,YAAY;YACZ,KAAK;SACN,CAAC,EACF,CAAC,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,CAAC,CAC7E,YAGD,KAAC,kBAAkB,OAAK,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,GAAI,GAC5D,CAChC,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,MAAM,YAAY,GAAwD,UAAU,CAClF,CAAC,KAAyC,EAAE,GAA6B,EAAE,EAAE;IAC3E,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAC,qBAAqB,OAAK,KAAK,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACxF,CAAC,CACF,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import {\n forwardRef,\n createContext,\n useMemo,\n useContext,\n useCallback,\n useState,\n KeyboardEvent,\n useEffect,\n useRef\n} from 'react';\nimport type { FunctionComponent, PropsWithoutRef, CSSProperties, MouseEvent } from 'react';\n\nimport Progress from '../Progress';\nimport { useDirection } from '../../hooks';\nimport Flex from '../Flex';\nimport Button from '../Button';\nimport Actions from '../Actions';\nimport type { Action, ForwardProps } from '../../types';\nimport { cap } from '../../utils';\n\nimport {\n StyledStandardTreeParent,\n StyledToggleIcon,\n StyledStandardTreeItemSubTree,\n StyledStandardTreeLeaf,\n StyledStandardTree,\n StyledNodeInteraction,\n StyledStandardTreeNode,\n StyledNodeActions,\n StyledLabelContent,\n StyledNodeIcon,\n StyledNodeText\n} from './StandardTree.styles';\nimport type { TreeProps } from './Tree';\nimport type {\n StandardTreeContextProps,\n StandardTreeNode,\n StandardTreeProps,\n StandardTreePropsWithDefaults\n} from './StandardTree.types';\nimport helpers from './helpers';\n\nconst StandardTreeContext = createContext<\n Pick<\n StandardTreePropsWithDefaults,\n | 'currentNodeId'\n | 'lined'\n | 'onNodeClick'\n | 'onNodeToggle'\n | 'firstNodeId'\n | 'lastNodeId'\n | 'focusedNodeId'\n | 'changeFocusedNodeId'\n >\n>({\n currentNodeId: undefined,\n lined: false,\n onNodeClick: () => {},\n onNodeToggle: () => {},\n firstNodeId: undefined,\n lastNodeId: undefined,\n focusedNodeId: undefined,\n changeFocusedNodeId: () => {}\n});\n\nconst NodeRenderer: TreeProps<StandardTreeNode>['nodeRenderer'] = ({\n id,\n label,\n icon,\n depth,\n hasParentSibling,\n nodes,\n expanded = false,\n loading = false,\n subTree,\n actions,\n onClick\n}) => {\n const {\n currentNodeId,\n onNodeClick,\n onNodeToggle,\n lined,\n focusedNodeId,\n changeFocusedNodeId,\n firstNodeId,\n lastNodeId\n } = useContext(StandardTreeContext);\n const current = currentNodeId === id;\n const focusedEl = focusedNodeId === id;\n const firstNode = firstNodeId === id;\n const { start, end } = useDirection();\n\n const tabIndex = useMemo(() => {\n let index = -1;\n if (focusedNodeId) {\n index = focusedEl ? 0 : -1;\n } else if (currentNodeId) {\n index = current ? 0 : -1;\n } else {\n index = firstNode ? 0 : -1;\n }\n return index;\n }, [focusedNodeId, currentNodeId, current, focusedEl]);\n\n const handleToggleClick = useCallback(\n (e: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>) => {\n onNodeClick?.(id, e);\n changeFocusedNodeId(id);\n },\n [id, onNodeClick, changeFocusedNodeId]\n );\n\n const onKeyDown = useCallback(\n (e: KeyboardEvent<HTMLElement>) => {\n if (['ArrowUp', 'ArrowDown', 'Enter', 'Home', 'End'].includes(e.key)) e.preventDefault();\n switch (e.key) {\n case 'ArrowUp':\n changeFocusedNodeId(id, 'up');\n break;\n case 'ArrowDown':\n changeFocusedNodeId(id, 'down');\n break;\n case `Arrow${cap(end)}`:\n if (nodes) {\n if (expanded) {\n changeFocusedNodeId(id, 'right');\n } else {\n onNodeToggle?.(id);\n }\n }\n break;\n case `Arrow${cap(start)}`:\n if (expanded) {\n onNodeToggle?.(id);\n } else {\n changeFocusedNodeId(id, 'left');\n }\n break;\n case 'Enter':\n if (onClick) {\n onClick(id, e);\n } else {\n handleToggleClick(e);\n }\n break;\n case 'Home':\n if (firstNodeId) changeFocusedNodeId(firstNodeId);\n break;\n case 'End':\n if (lastNodeId) changeFocusedNodeId(lastNodeId);\n break;\n default:\n }\n },\n [id, end, nodes, expanded, actions, firstNodeId, lastNodeId, changeFocusedNodeId]\n );\n\n const actionsJSX = useMemo(() => {\n // since Actions may render a frag of buttons and we need a wrapper for flex space-between.\n return actions ? (\n <StyledNodeActions>\n <Actions\n items={actions.map(action => {\n return {\n ...action,\n onClick: (\n actionId: Action['id'],\n e: MouseEvent<HTMLButtonElement | HTMLAnchorElement | HTMLInputElement>\n ) => {\n e.stopPropagation();\n action?.onClick?.(actionId, e);\n }\n };\n })}\n menuAt={3}\n menuButtonProps={{\n onClick: (e: MouseEvent) => e.stopPropagation(),\n onKeyDown: (e: KeyboardEvent) => {\n e.stopPropagation();\n if (['ArrowUp', 'ArrowDown'].includes(e.key)) {\n e.preventDefault();\n }\n }\n }}\n />\n </StyledNodeActions>\n ) : null;\n }, [actions]);\n\n const elRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (focusedEl) {\n elRef?.current?.focus();\n }\n }, [focusedEl]);\n\n const labelContent = useMemo(() => {\n const internal = (\n // Wrapping in a div for handling of flex space-between when there are node actions.\n <Flex container={{ alignItems: 'center', gap: 0.5 }} as={StyledLabelContent}>\n {icon && <StyledNodeIcon name={icon} />}\n <StyledNodeText>{label}</StyledNodeText>\n </Flex>\n );\n\n return !nodes && (onClick ?? onNodeClick) ? (\n <Flex\n container={{ alignItems: 'center', justify: 'between', gap: 2 }}\n as={StyledNodeInteraction}\n role='treeitem'\n aria-current={current ? 'true' : undefined}\n tabIndex={tabIndex}\n onClick={(e: MouseEvent<HTMLElement>) => {\n onClick?.(id, e);\n onNodeClick?.(id, e);\n changeFocusedNodeId(id);\n }}\n onKeyDown={onKeyDown}\n ref={elRef}\n >\n {internal}\n {actionsJSX}\n </Flex>\n ) : (\n internal\n );\n }, [\n id,\n label,\n icon,\n nodes,\n actions,\n onClick,\n onNodeClick,\n current,\n focusedEl,\n tabIndex,\n changeFocusedNodeId,\n onKeyDown\n ]);\n\n return (\n <StyledStandardTreeNode\n id={id}\n style={\n { '--depth': depth, '--has-parent-sibling': Number(hasParentSibling) } as CSSProperties\n }\n aria-busy={loading}\n >\n {nodes ? (\n <>\n <Flex\n container={{ alignItems: 'center', justify: 'between', gap: 2 }}\n as={StyledStandardTreeParent}\n role='treeitem'\n aria-current={current ? 'true' : undefined}\n tabIndex={tabIndex}\n variant='text'\n onClick={handleToggleClick}\n aria-expanded={expanded ? 'true' : 'false'}\n aria-label={label}\n onKeyDown={onKeyDown}\n ref={elRef}\n >\n <Flex container={{ alignItems: 'center', gap: 0.5 }} as='span'>\n <Button\n variant='simple'\n icon\n compact\n onClick={(e: MouseEvent<HTMLElement>) => {\n if (onNodeToggle) {\n e.stopPropagation();\n onNodeToggle(id, e);\n changeFocusedNodeId(id);\n }\n }}\n >\n <StyledToggleIcon name='caret-right' />\n </Button>\n {labelContent}\n </Flex>\n {actionsJSX}\n </Flex>\n <StyledStandardTreeItemSubTree lined={lined}>\n {subTree}\n {loading && <Progress variant='ring' placement='inline' />}\n </StyledStandardTreeItemSubTree>\n </>\n ) : (\n <StyledStandardTreeLeaf>{labelContent}</StyledStandardTreeLeaf>\n )}\n </StyledStandardTreeNode>\n );\n};\n\nconst StandardTreeWithNodes: FunctionComponent<StandardTreeProps & ForwardProps> = forwardRef(\n (\n {\n nodes,\n currentNodeId,\n onNodeClick,\n onNodeToggle,\n lined = false,\n ...restProps\n }: PropsWithoutRef<StandardTreeProps>,\n ref: StandardTreeProps['ref']\n ) => {\n const [focusedNodeId, setFocusedNodedId] = useState<string | undefined>();\n\n const lastNodeId = useMemo(() => {\n return helpers.getDeepestNode(nodes, nodes[nodes.length - 1].id)?.id;\n }, [nodes]);\n\n const changeFocusedNodeId: StandardTreeContextProps['changeFocusedNodeId'] = useCallback(\n (id, type) => {\n switch (type) {\n case 'up': {\n const previousNode = helpers.getPreviousNode(nodes, id);\n if (previousNode) setFocusedNodedId(previousNode.id);\n break;\n }\n case 'down': {\n const nextNode = helpers.getNextNode(nodes, id);\n if (nextNode) setFocusedNodedId(nextNode.id);\n break;\n }\n case 'left': {\n const parentNode = helpers.getParentNode(nodes, id);\n if (parentNode) setFocusedNodedId(parentNode.id);\n break;\n }\n case 'right': {\n const childNode = helpers.getFirstChildNode(nodes, id);\n if (childNode) setFocusedNodedId(childNode.id);\n break;\n }\n default:\n setFocusedNodedId(id);\n }\n },\n [nodes]\n );\n\n return (\n <StandardTreeContext.Provider\n value={useMemo(\n () => ({\n currentNodeId,\n focusedNodeId,\n lastNodeId,\n firstNodeId: nodes[0].id,\n changeFocusedNodeId,\n onNodeClick,\n onNodeToggle,\n lined\n }),\n [currentNodeId, onNodeClick, lined, focusedNodeId, lastNodeId, onNodeToggle]\n )}\n >\n {/* FIXME: Types are having issues when styled(Tree) is typeof Tree. */}\n <StyledStandardTree {...restProps} ref={ref} nodes={nodes} nodeRenderer={NodeRenderer} />\n </StandardTreeContext.Provider>\n );\n }\n);\n\nconst StandardTree: FunctionComponent<StandardTreeProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<StandardTreeProps>, ref: StandardTreeProps['ref']) => {\n return props.nodes.length > 0 ? <StandardTreeWithNodes {...props} ref={ref} /> : null;\n }\n);\n\nexport default StandardTree;\n"]}
|
|
1
|
+
{"version":3,"file":"StandardTree.js","sourceRoot":"","sources":["../../../src/components/Tree/StandardTree.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,OAAO,EACP,UAAU,EACV,WAAW,EACX,QAAQ,EAER,SAAS,EACT,MAAM,EACP,MAAM,O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,EAAE;IAC3E,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAC,qBAAqB,OAAK,KAAK,EAAE,GAAG,EAAE,GAAG,GAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACxF,CAAC,CACF,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import {\n forwardRef,\n createContext,\n useMemo,\n useContext,\n useCallback,\n useState,\n KeyboardEvent,\n useEffect,\n useRef\n} from 'react';\nimport type { FunctionComponent, PropsWithoutRef, CSSProperties, MouseEvent } from 'react';\n\nimport Progress from '../Progress';\nimport { useConsolidatedRef, useDirection, useFocusWithin } from '../../hooks';\nimport Flex from '../Flex';\nimport Actions from '../Actions';\nimport type { Action, ForwardProps } from '../../types';\nimport { cap } from '../../utils';\nimport Button from '../Button';\n\nimport {\n StyledStandardTreeParent,\n StyledToggleIcon,\n StyledToggleIconWrapper,\n StyledStandardTreeItemSubTree,\n StyledStandardTreeLeaf,\n StyledStandardTree,\n StyledNodeInteraction,\n StyledStandardTreeNode,\n StyledNodeActions,\n StyledLabelContent,\n StyledNodeIcon,\n StyledNodeText\n} from './StandardTree.styles';\nimport type { TreeProps } from './Tree';\nimport type {\n StandardTreeContextProps,\n StandardTreeNode,\n StandardTreeProps,\n StandardTreePropsWithDefaults\n} from './StandardTree.types';\nimport helpers from './helpers';\n\nconst StandardTreeContext = createContext<\n Pick<\n StandardTreePropsWithDefaults,\n | 'currentNodeId'\n | 'lined'\n | 'onNodeClick'\n | 'onNodeToggle'\n | 'firstNodeId'\n | 'lastNodeId'\n | 'focusedNodeId'\n | 'changeFocusedNodeId'\n | 'selectableParents'\n >\n>({\n currentNodeId: undefined,\n lined: false,\n onNodeClick: () => {},\n onNodeToggle: () => {},\n firstNodeId: undefined,\n lastNodeId: undefined,\n focusedNodeId: undefined,\n changeFocusedNodeId: () => {},\n selectableParents: true\n});\n\nconst NodeRenderer: TreeProps<StandardTreeNode>['nodeRenderer'] = ({\n id,\n label,\n icon,\n depth,\n hasParentSibling,\n nodes,\n expanded = false,\n loading = false,\n subTree,\n actions,\n onClick,\n href\n}) => {\n const {\n currentNodeId,\n onNodeClick,\n onNodeToggle,\n lined,\n focusedNodeId,\n changeFocusedNodeId,\n firstNodeId,\n lastNodeId,\n selectableParents\n } = useContext(StandardTreeContext);\n const current = currentNodeId === id;\n const focusedEl = focusedNodeId === id;\n const firstNode = firstNodeId === id;\n const { start, end } = useDirection();\n\n const ariaCurrent = useMemo(() => {\n return href ? 'page' : 'true';\n }, [href]);\n\n const tabIndex = useMemo(() => {\n let index = -1;\n if (focusedNodeId) {\n index = focusedEl ? 0 : -1;\n } else if (currentNodeId && nodes && helpers.getNode(nodes, currentNodeId)) {\n index = current ? 0 : -1;\n } else {\n index = firstNode ? 0 : -1;\n }\n return index;\n }, [focusedNodeId, currentNodeId, current, focusedEl]);\n\n const handleParentClick = useCallback(\n (e: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>) => {\n onNodeClick?.(id, e);\n changeFocusedNodeId(id);\n },\n [id, onNodeClick, changeFocusedNodeId]\n );\n\n const handleParentToggle = useCallback(\n (e: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>) => {\n e.preventDefault();\n e.stopPropagation();\n onNodeToggle?.(id, e);\n changeFocusedNodeId(id);\n },\n [id, onNodeToggle, changeFocusedNodeId]\n );\n\n const onKeyDown = useCallback(\n (e: KeyboardEvent<HTMLElement>) => {\n if (['ArrowUp', 'ArrowDown', 'Home', 'End'].includes(e.key)) e.preventDefault();\n if (e.key === 'Enter' && !href) e.preventDefault();\n switch (e.key) {\n case 'ArrowUp':\n changeFocusedNodeId(id, 'up');\n break;\n case 'ArrowDown':\n changeFocusedNodeId(id, 'down');\n break;\n case `Arrow${cap(end)}`:\n if (nodes) {\n if (expanded) {\n changeFocusedNodeId(id, 'right');\n } else {\n onNodeToggle?.(id);\n }\n }\n break;\n case `Arrow${cap(start)}`:\n if (expanded) {\n onNodeToggle?.(id);\n } else {\n changeFocusedNodeId(id, 'left');\n }\n break;\n case 'Enter':\n onClick?.(id, e);\n if (nodes) {\n if (selectableParents) {\n handleParentClick(e);\n } else {\n handleParentToggle(e);\n }\n } else {\n onNodeClick?.(id, e);\n changeFocusedNodeId(id);\n }\n break;\n case 'Home':\n if (firstNodeId) changeFocusedNodeId(firstNodeId);\n break;\n case 'End':\n if (lastNodeId) changeFocusedNodeId(lastNodeId);\n break;\n default:\n }\n },\n [id, end, nodes, expanded, actions, firstNodeId, lastNodeId, changeFocusedNodeId]\n );\n\n const actionsJSX = useMemo(() => {\n // since Actions may render a frag of buttons and we need a wrapper for flex space-between.\n return actions ? (\n <StyledNodeActions>\n <Actions\n items={actions.map(action => {\n return {\n ...action,\n onClick: (\n actionId: Action['id'],\n e: MouseEvent<HTMLButtonElement | HTMLAnchorElement | HTMLInputElement>\n ) => {\n e.stopPropagation();\n e.preventDefault();\n action?.onClick?.(actionId, e);\n },\n onKeyDown: (e: KeyboardEvent) => {\n if (e.key === 'Enter') e.stopPropagation();\n }\n };\n })}\n menuAt={3}\n menuButtonProps={{\n onClick: (e: MouseEvent) => {\n e.stopPropagation();\n e.preventDefault();\n },\n onKeyDown: (e: KeyboardEvent) => {\n e.stopPropagation();\n if (['ArrowUp', 'ArrowDown'].includes(e.key)) {\n e.preventDefault();\n }\n }\n }}\n />\n </StyledNodeActions>\n ) : null;\n }, [actions]);\n\n const elRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (focusedEl) {\n elRef?.current?.focus();\n }\n }, [focusedEl]);\n\n const labelContent = useMemo(() => {\n const internal = (\n // Wrapping in a div for handling of flex space-between when there are node actions.\n <Flex container={{ alignItems: 'center', gap: 0.5 }} as={StyledLabelContent}>\n {icon && <StyledNodeIcon name={icon} />}\n <StyledNodeText>{label}</StyledNodeText>\n </Flex>\n );\n\n return !nodes && (onClick ?? onNodeClick) ? (\n <Flex\n container={{ alignItems: 'center', justify: 'between', gap: 2 }}\n as={StyledNodeInteraction}\n forwardedAs={href ? 'a' : 'div'}\n role='treeitem'\n aria-current={current ? ariaCurrent : undefined}\n tabIndex={tabIndex}\n onClick={(e: MouseEvent<HTMLElement>) => {\n onClick?.(id, e);\n onNodeClick?.(id, e);\n changeFocusedNodeId(id);\n }}\n href={href}\n onKeyDown={onKeyDown}\n ref={elRef}\n >\n {internal}\n {actionsJSX}\n </Flex>\n ) : (\n internal\n );\n }, [\n id,\n label,\n icon,\n nodes,\n actions,\n onClick,\n onNodeClick,\n current,\n focusedEl,\n tabIndex,\n changeFocusedNodeId,\n onKeyDown\n ]);\n\n return (\n <StyledStandardTreeNode\n id={id}\n style={\n {\n '--depth': depth,\n '--has-parent': depth ? 1 : 0,\n '--has-parent-sibling': hasParentSibling ? 1 : 0\n } as CSSProperties\n }\n aria-busy={loading}\n >\n {nodes ? (\n <>\n <Flex\n container={{ alignItems: 'center', justify: 'between', gap: 2 }}\n as={StyledStandardTreeParent}\n forwardedAs={href ? 'a' : 'div'}\n role='treeitem'\n aria-current={current ? ariaCurrent : undefined}\n tabIndex={tabIndex}\n variant='text'\n onClick={selectableParents ? handleParentClick : handleParentToggle}\n href={selectableParents ? href : undefined}\n aria-expanded={expanded ? 'true' : 'false'}\n aria-owns={`${id}-subtree`}\n aria-label={label}\n onKeyDown={onKeyDown}\n ref={elRef}\n >\n <Flex container={{ alignItems: 'center' }} as='span'>\n {selectableParents ? (\n <Button variant='simple' tabIndex={-1} icon compact onClick={handleParentToggle}>\n <StyledToggleIcon name='caret-right' />\n </Button>\n ) : (\n <Flex\n as={StyledToggleIconWrapper}\n container={{ justify: 'center', alignItems: 'center' }}\n >\n <StyledToggleIcon name='caret-right' />\n </Flex>\n )}\n {labelContent}\n </Flex>\n {actionsJSX}\n </Flex>\n <StyledStandardTreeItemSubTree lined={lined} id={`${id}-subtree`}>\n {subTree}\n {loading && <Progress variant='ring' placement='inline' />}\n </StyledStandardTreeItemSubTree>\n </>\n ) : (\n <StyledStandardTreeLeaf>{labelContent}</StyledStandardTreeLeaf>\n )}\n </StyledStandardTreeNode>\n );\n};\n\nconst StandardTreeWithNodes: FunctionComponent<StandardTreeProps & ForwardProps> = forwardRef(\n (\n {\n nodes,\n currentNodeId,\n onNodeClick,\n onNodeToggle,\n lined = false,\n selectableParents = true,\n ...restProps\n }: PropsWithoutRef<StandardTreeProps>,\n ref: StandardTreeProps['ref']\n ) => {\n const [focusedNodeId, setFocusedNodedId] = useState<string | undefined>();\n const treeRef = useConsolidatedRef(ref);\n\n const lastNodeId = useMemo(() => {\n return helpers.getDeepestNode(nodes, nodes[nodes.length - 1].id)?.id;\n }, [nodes]);\n\n const changeFocusedNodeId: StandardTreeContextProps['changeFocusedNodeId'] = useCallback(\n (id, type) => {\n switch (type) {\n case 'up': {\n const previousNode = helpers.getPreviousNode(nodes, id);\n if (previousNode) setFocusedNodedId(previousNode.id);\n break;\n }\n case 'down': {\n const nextNode = helpers.getNextNode(nodes, id);\n if (nextNode) setFocusedNodedId(nextNode.id);\n break;\n }\n case 'left': {\n const parentNode = helpers.getParentNode(nodes, id);\n if (parentNode) setFocusedNodedId(parentNode.id);\n break;\n }\n case 'right': {\n const childNode = helpers.getFirstChildNode(nodes, id);\n if (childNode) setFocusedNodedId(childNode.id);\n break;\n }\n default: {\n if (id !== focusedNodeId) setFocusedNodedId(id);\n break;\n }\n }\n },\n [nodes]\n );\n\n const onFocusChange = (focused: boolean) => {\n if (!focused) setFocusedNodedId('');\n };\n\n useFocusWithin([treeRef], onFocusChange);\n\n return (\n <StandardTreeContext.Provider\n value={useMemo(\n () => ({\n currentNodeId,\n focusedNodeId,\n lastNodeId,\n firstNodeId: nodes[0].id,\n changeFocusedNodeId,\n onNodeClick,\n onNodeToggle,\n lined,\n selectableParents\n }),\n [\n currentNodeId,\n onNodeClick,\n lined,\n focusedNodeId,\n lastNodeId,\n onNodeToggle,\n selectableParents\n ]\n )}\n >\n {/* FIXME: Types are having issues when styled(Tree) is typeof Tree. */}\n <StyledStandardTree\n {...restProps}\n ref={treeRef}\n nodes={nodes}\n nodeRenderer={NodeRenderer}\n />\n </StandardTreeContext.Provider>\n );\n }\n);\n\nconst StandardTree: FunctionComponent<StandardTreeProps & ForwardProps> = forwardRef(\n (props: PropsWithoutRef<StandardTreeProps>, ref: StandardTreeProps['ref']) => {\n return props.nodes.length > 0 ? <StandardTreeWithNodes {...props} ref={ref} /> : null;\n }\n);\n\nexport default StandardTree;\n"]}
|
|
@@ -4,6 +4,7 @@ export declare const StyledNodeActions: import("styled-components").StyledCompon
|
|
|
4
4
|
export declare const StyledLabelContent: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
5
5
|
export declare const StyledNodeIcon: import("styled-components").StyledComponent<import("react").FunctionComponent<import("../Icon").IconProps & import("../..").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
|
|
6
6
|
export declare const StyledNodeText: import("styled-components").StyledComponent<"span", import("styled-components").DefaultTheme, {}, never>;
|
|
7
|
+
export declare const StyledToggleIconWrapper: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
7
8
|
export declare const StyledStandardTreeItemSubTree: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, Pick<StandardTreePropsWithDefaults, "lined">, never>;
|
|
8
9
|
export declare const StyledNodeInteraction: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
9
10
|
export declare const StyledStandardTreeLeaf: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StandardTree.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Tree/StandardTree.styles.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAErE,eAAO,MAAM,gBAAgB,iMAAiB,CAAC;AAE/C,eAAO,MAAM,iBAAiB,yGAAe,CAAC;AAE9C,eAAO,MAAM,kBAAkB,yGAAe,CAAC;AAE/C,eAAO,MAAM,cAAc,iMAAiB,CAAC;AAE7C,eAAO,MAAM,cAAc,0GAAgB,CAAC;AAE5C,eAAO,MAAM,6BAA6B,mJAgCxC,CAAC;AAIH,eAAO,MAAM,qBAAqB,yGA8ChC,CAAC;AAIH,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"StandardTree.styles.d.ts","sourceRoot":"","sources":["../../../src/components/Tree/StandardTree.styles.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAErE,eAAO,MAAM,gBAAgB,iMAAiB,CAAC;AAE/C,eAAO,MAAM,iBAAiB,yGAAe,CAAC;AAE9C,eAAO,MAAM,kBAAkB,yGAAe,CAAC;AAE/C,eAAO,MAAM,cAAc,iMAAiB,CAAC;AAE7C,eAAO,MAAM,cAAc,0GAAgB,CAAC;AAE5C,eAAO,MAAM,uBAAuB,yGAKlC,CAAC;AAIH,eAAO,MAAM,6BAA6B,mJAgCxC,CAAC;AAIH,eAAO,MAAM,qBAAqB,yGA8ChC,CAAC;AAIH,eAAO,MAAM,sBAAsB,yGASjC,CAAC;AAKH,eAAO,MAAM,wBAAwB,EAAE,GA2BrC,CAAC;AAIH,eAAO,MAAM,sBAAsB,yGAclC,CAAC;AAIF,eAAO,MAAM,kBAAkB,kQAU7B,CAAC"}
|
|
@@ -11,6 +11,13 @@ export const StyledNodeActions = styled.div ``;
|
|
|
11
11
|
export const StyledLabelContent = styled.div ``;
|
|
12
12
|
export const StyledNodeIcon = styled(Icon) ``;
|
|
13
13
|
export const StyledNodeText = styled.span ``;
|
|
14
|
+
export const StyledToggleIconWrapper = styled.div(({ theme }) => {
|
|
15
|
+
return css `
|
|
16
|
+
min-height: ${theme.base['hit-area'].compact};
|
|
17
|
+
min-width: ${theme.base['hit-area'].compact};
|
|
18
|
+
`;
|
|
19
|
+
});
|
|
20
|
+
StyledToggleIconWrapper.defaultProps = defaultThemeProp;
|
|
14
21
|
export const StyledStandardTreeItemSubTree = styled.div(({ theme, lined }) => {
|
|
15
22
|
return css `
|
|
16
23
|
position: relative;
|
|
@@ -45,9 +52,8 @@ export const StyledStandardTreeItemSubTree = styled.div(({ theme, lined }) => {
|
|
|
45
52
|
StyledStandardTreeItemSubTree.defaultProps = defaultThemeProp;
|
|
46
53
|
export const StyledNodeInteraction = styled.div(({ theme }) => {
|
|
47
54
|
return css `
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*/
|
|
55
|
+
color: ${theme.base.palette['foreground-color']};
|
|
56
|
+
text-decoration: none;
|
|
51
57
|
min-height: 2.25rem;
|
|
52
58
|
padding-inline-start: calc(var(--parent-caret-width) * var(--depth) + var(--initial-padding));
|
|
53
59
|
padding-inline-end: calc(var(--initial-padding) + ${theme.base.spacing});
|
|
@@ -81,6 +87,7 @@ export const StyledNodeInteraction = styled.div(({ theme }) => {
|
|
|
81
87
|
}
|
|
82
88
|
}
|
|
83
89
|
|
|
90
|
+
&[aria-current='page'],
|
|
84
91
|
&[aria-current='true'] {
|
|
85
92
|
background-color: ${transparentize(0.95, theme.base.palette['foreground-color'])};
|
|
86
93
|
|
|
@@ -94,12 +101,9 @@ StyledNodeInteraction.defaultProps = defaultThemeProp;
|
|
|
94
101
|
export const StyledStandardTreeLeaf = styled.div(() => {
|
|
95
102
|
return css `
|
|
96
103
|
${StyledNodeInteraction} {
|
|
97
|
-
/* 1 when not at root and no parent sibling, 0 otherwise. */
|
|
98
|
-
--include-parent-icon-width: min((1.5 - var(--has-parent-sibling)), (var(--depth) + 0.5));
|
|
99
104
|
padding-inline-start: calc(
|
|
100
|
-
var(--initial-padding) +
|
|
101
|
-
(var(--parent-caret-width) * (var(--
|
|
102
|
-
(var(--parent-icon-width) * var(--include-parent-icon-width))
|
|
105
|
+
var(--initial-padding) + (var(--parent-caret-width) * var(--depth)) +
|
|
106
|
+
(var(--parent-caret-spacing-width) * (max(var(--has-parent-sibling), var(--has-parent))))
|
|
103
107
|
);
|
|
104
108
|
}
|
|
105
109
|
`;
|
|
@@ -135,21 +139,31 @@ export const StyledStandardTreeParent = styled(StyledNodeInteraction)(({ theme }
|
|
|
135
139
|
});
|
|
136
140
|
StyledStandardTreeParent.defaultProps = defaultThemeProp;
|
|
137
141
|
export const StyledStandardTreeNode = styled.div(({ theme }) => css `
|
|
138
|
-
--initial-padding: calc(${theme.base.spacing} *
|
|
139
|
-
--parent-caret-width:
|
|
140
|
-
--parent-
|
|
142
|
+
--initial-padding: calc(${theme.base.spacing} * 0.5);
|
|
143
|
+
--parent-caret-width: 1em;
|
|
144
|
+
--parent-caret-spacing-width: max(
|
|
145
|
+
(var(--parent-caret-width) + (2 * ${theme.components.button['border-width']})),
|
|
146
|
+
${theme.base['hit-area'].compact}
|
|
147
|
+
);
|
|
141
148
|
|
|
142
149
|
${StyledIcon} {
|
|
143
|
-
width:
|
|
144
|
-
height:
|
|
150
|
+
width: var(--parent-caret-width);
|
|
151
|
+
height: var(--parent-caret-width);
|
|
145
152
|
}
|
|
146
153
|
`);
|
|
147
154
|
StyledStandardTreeNode.defaultProps = defaultThemeProp;
|
|
148
|
-
export const StyledStandardTree = styled(Tree)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
155
|
+
export const StyledStandardTree = styled(Tree)(({ theme }) => {
|
|
156
|
+
return css `
|
|
157
|
+
${StyledTreeListItem} {
|
|
158
|
+
display: block;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
&:has(:focus-visible) {
|
|
162
|
+
box-shadow: ${theme.base.shadow['focus-group']};
|
|
163
|
+
}
|
|
164
|
+
`;
|
|
165
|
+
});
|
|
166
|
+
StyledStandardTree.defaultProps = defaultThemeProp;
|
|
153
167
|
// FIXME: We need to determine why styled-component types are "eating" our types.
|
|
154
168
|
StyledStandardTree.defaultProps = defaultThemeProp;
|
|
155
169
|
//# sourceMappingURL=StandardTree.styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StandardTree.styles.js","sour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AAE,EAAE,EAAE,CAAC,GAAG,CAAA;8BACU,KAAK,CAAC,IAAI,CAAC,OAAO;;;0CAGN,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,cAAc,CAAC;QACzE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO;;;MAGhC,UAAU;;;;GAIb,CACF,CAAC;AAEF,sBAAsB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEvD,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC3D,OAAO,GAAG,CAAA;MACN,kBAAkB;;;;;oBAKJ,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;;GAEjD,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,kBAAkB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEnD,iFAAiF;AAChF,kBAA6D,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\nimport { transparentize } from 'polished';\n\nimport { StyledButton } from '../Button';\nimport Icon, { StyledIcon } from '../Icon';\nimport { StyledProgressRing } from '../Progress';\nimport { defaultThemeProp } from '../../theme';\nimport { useDirection } from '../../hooks';\n\nimport Tree, { StyledTreeListItem } from './Tree';\nimport { StandardTreePropsWithDefaults } from './StandardTree.types';\n\nexport const StyledToggleIcon = styled(Icon)``;\n\nexport const StyledNodeActions = styled.div``;\n\nexport const StyledLabelContent = styled.div``;\n\nexport const StyledNodeIcon = styled(Icon)``;\n\nexport const StyledNodeText = styled.span``;\n\nexport const StyledToggleIconWrapper = styled.div(({ theme }) => {\n return css`\n min-height: ${theme.base['hit-area'].compact};\n min-width: ${theme.base['hit-area'].compact};\n `;\n});\n\nStyledToggleIconWrapper.defaultProps = defaultThemeProp;\n\nexport const StyledStandardTreeItemSubTree = styled.div<\n Pick<StandardTreePropsWithDefaults, 'lined'>\n>(({ theme, lined }) => {\n return css`\n position: relative;\n\n ${lined &&\n css`\n ::before {\n content: '';\n display: block;\n position: absolute;\n background-color: currentColor;\n inset-block-start: -${theme.base.spacing};\n inset-block-end: 0;\n inset-inline-start: calc(\n 0.5em * (var(--depth) + 1) + (${theme.base.spacing} * var(--depth) + 0.5em * var(--depth)) +\n ${theme.base.spacing} * 1.5\n );\n width: 0.0625rem;\n opacity: 0.2;\n transition: opacity ${theme.base.animation.speed} ${theme.base.animation.timing.ease};\n }\n `}\n\n ${StyledProgressRing} {\n margin: calc(${theme.base.spacing} * 1.25) 0;\n margin-inline-start: calc(\n var(--parent-caret-width) * (var(--depth) + 1) + var(--initial-padding)\n );\n }\n `;\n});\n\nStyledStandardTreeItemSubTree.defaultProps = defaultThemeProp;\n\nexport const StyledNodeInteraction = styled.div(({ theme }) => {\n return css`\n color: ${theme.base.palette['foreground-color']};\n text-decoration: none;\n min-height: 2.25rem;\n padding-inline-start: calc(var(--parent-caret-width) * var(--depth) + var(--initial-padding));\n padding-inline-end: calc(var(--initial-padding) + ${theme.base.spacing});\n cursor: pointer;\n\n & > ${StyledNodeActions} {\n display: none;\n ${StyledButton} {\n margin-inline-start: calc(${theme.base.spacing} / 2);\n }\n }\n\n &:focus,\n &:focus-within {\n box-shadow: ${theme.base.shadow.focus};\n\n & > ${StyledNodeActions} {\n display: block;\n }\n }\n\n &:focus-visible {\n outline: none;\n }\n\n &:hover {\n background-color: ${transparentize(0.9, theme.base.palette['foreground-color'])};\n\n & > ${StyledNodeActions} {\n display: block;\n }\n }\n\n &[aria-current='page'],\n &[aria-current='true'] {\n background-color: ${transparentize(0.95, theme.base.palette['foreground-color'])};\n\n & > ${StyledLabelContent}, & > :first-child > ${StyledLabelContent} {\n color: ${theme.base.palette.interactive};\n }\n }\n `;\n});\n\nStyledNodeInteraction.defaultProps = defaultThemeProp;\n\nexport const StyledStandardTreeLeaf = styled.div(() => {\n return css`\n ${StyledNodeInteraction} {\n padding-inline-start: calc(\n var(--initial-padding) + (var(--parent-caret-width) * var(--depth)) +\n (var(--parent-caret-spacing-width) * (max(var(--has-parent-sibling), var(--has-parent))))\n );\n }\n `;\n});\n\nStyledStandardTreeLeaf.defaultProps = defaultThemeProp;\n\n// FIXME: any is used since typeof StyledNodeInteraction not playing nicely.\nexport const StyledStandardTreeParent: any = styled(StyledNodeInteraction)(({ theme }) => {\n const { ltr } = useDirection();\n\n return css`\n &[aria-expanded='true'] ${StyledToggleIcon} {\n transform: rotate(90deg);\n }\n\n &[aria-expanded='false'] {\n ${StyledToggleIcon} {\n transform: rotate(${ltr ? '0' : '180'}deg);\n }\n\n + ${StyledStandardTreeItemSubTree} {\n display: none;\n }\n }\n\n &:hover + ${StyledStandardTreeItemSubTree}::before {\n opacity: 0.5;\n }\n\n ${StyledToggleIcon} {\n transition: transform calc(${theme.base.animation.speed} / 2)\n ${theme.base.animation.timing.ease};\n }\n `;\n});\n\nStyledStandardTreeParent.defaultProps = defaultThemeProp;\n\nexport const StyledStandardTreeNode = styled.div(\n ({ theme }) => css`\n --initial-padding: calc(${theme.base.spacing} * 0.5);\n --parent-caret-width: 1em;\n --parent-caret-spacing-width: max(\n (var(--parent-caret-width) + (2 * ${theme.components.button['border-width']})),\n ${theme.base['hit-area'].compact}\n );\n\n ${StyledIcon} {\n width: var(--parent-caret-width);\n height: var(--parent-caret-width);\n }\n `\n);\n\nStyledStandardTreeNode.defaultProps = defaultThemeProp;\n\nexport const StyledStandardTree = styled(Tree)(({ theme }) => {\n return css`\n ${StyledTreeListItem} {\n display: block;\n }\n\n &:has(:focus-visible) {\n box-shadow: ${theme.base.shadow['focus-group']};\n }\n `;\n});\n\nStyledStandardTree.defaultProps = defaultThemeProp;\n\n// FIXME: We need to determine why styled-component types are \"eating\" our types.\n(StyledStandardTree as typeof Tree & { defaultProps: object }).defaultProps = defaultThemeProp;\n"]}
|
|
@@ -2,19 +2,46 @@ import type { MouseEvent, KeyboardEvent } from 'react';
|
|
|
2
2
|
import type { Action, PropsWithDefaults } from '../../types';
|
|
3
3
|
import type { TreeProps, TreeNode } from './Tree';
|
|
4
4
|
export interface StandardTreeNode extends TreeNode {
|
|
5
|
+
/** A set of nested tree nodes. */
|
|
5
6
|
nodes?: StandardTreeNode[];
|
|
7
|
+
/** The display text of the tree node. */
|
|
6
8
|
label: string;
|
|
9
|
+
/** The name of the Cosmos Icon to render as a visual, next to the label. */
|
|
7
10
|
icon?: string;
|
|
11
|
+
/**
|
|
12
|
+
* If true, the node's children will be displayed.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
8
15
|
expanded?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* If true, the node will render a loading indicator in place of any children.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
9
20
|
loading?: boolean;
|
|
21
|
+
/** A set of actions attached to the node. */
|
|
10
22
|
actions?: Action[];
|
|
23
|
+
/** Click handler for the tree node. */
|
|
11
24
|
onClick?: (id: TreeNode['id'], e: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>) => void;
|
|
25
|
+
/** URL or DOM id to navigate to. This will render the tree node as a link. */
|
|
26
|
+
href?: string;
|
|
12
27
|
}
|
|
13
28
|
export interface StandardTreeProps extends TreeProps<StandardTreeNode> {
|
|
29
|
+
/** The id of the currently active tree node. */
|
|
14
30
|
currentNodeId?: TreeNode['id'];
|
|
31
|
+
/**
|
|
32
|
+
* If true, a vertical line will render alongside nested nodes.
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
15
35
|
lined?: boolean;
|
|
36
|
+
/** Callback function for click events on tree nodes. This will only be called on parent nodes if selectableParents is true. It will always be called on leaf nodes. */
|
|
16
37
|
onNodeClick?: (id: TreeNode['id'], e: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>) => void;
|
|
38
|
+
/** Callback function for toggling tree nodes between expanded/collapsed states. This is only ever called on parent nodes. */
|
|
17
39
|
onNodeToggle?: (id: TreeNode['id'], e?: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>) => void;
|
|
40
|
+
/**
|
|
41
|
+
* If true, parent tree nodes can be selected independently from being toggled expanded/collapsed.
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
selectableParents?: boolean;
|
|
18
45
|
}
|
|
19
46
|
export interface StandardTreeContextProps extends StandardTreeProps {
|
|
20
47
|
firstNodeId?: TreeNode['id'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StandardTree.types.d.ts","sourceRoot":"","sources":["../../../src/components/Tree/StandardTree.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElD,MAAM,WAAW,gBAAiB,SAAQ,QAAQ;IAChD,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,aAAa,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"StandardTree.types.d.ts","sourceRoot":"","sources":["../../../src/components/Tree/StandardTree.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE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E,WAAW,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,UAAU,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5B,aAAa,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/B,mBAAmB,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,KAAK,IAAI,CAAC;CAC5F;AAED,oBAAY,6BAA6B,GAAG,iBAAiB,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StandardTree.types.js","sourceRoot":"","sources":["../../../src/components/Tree/StandardTree.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MouseEvent, KeyboardEvent } from 'react';\n\nimport type { Action, PropsWithDefaults } from '../../types';\n\nimport type { TreeProps, TreeNode } from './Tree';\n\nexport interface StandardTreeNode extends TreeNode {\n nodes?: StandardTreeNode[];\n label: string;\n icon?: string;\n expanded?: boolean;\n loading?: boolean;\n actions?: Action[];\n onClick?: (id: TreeNode['id'], e: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>) => void;\n}\n\nexport interface StandardTreeProps extends TreeProps<StandardTreeNode> {\n currentNodeId?: TreeNode['id'];\n lined?: boolean;\n onNodeClick?: (\n id: TreeNode['id'],\n e: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>\n ) => void;\n onNodeToggle?: (\n id: TreeNode['id'],\n e?: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>\n ) => void;\n}\n\nexport interface StandardTreeContextProps extends StandardTreeProps {\n firstNodeId?: TreeNode['id'];\n lastNodeId?: TreeNode['id'];\n focusedNodeId?: TreeNode['id'];\n changeFocusedNodeId: (id: TreeNode['id'], type?: 'up' | 'down' | 'left' | 'right') => void;\n}\n\nexport type StandardTreePropsWithDefaults = PropsWithDefaults<StandardTreeContextProps, 'lined'>;\n"]}
|
|
1
|
+
{"version":3,"file":"StandardTree.types.js","sourceRoot":"","sources":["../../../src/components/Tree/StandardTree.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MouseEvent, KeyboardEvent } from 'react';\n\nimport type { Action, PropsWithDefaults } from '../../types';\n\nimport type { TreeProps, TreeNode } from './Tree';\n\nexport interface StandardTreeNode extends TreeNode {\n /** A set of nested tree nodes. */\n nodes?: StandardTreeNode[];\n /** The display text of the tree node. */\n label: string;\n /** The name of the Cosmos Icon to render as a visual, next to the label. */\n icon?: string;\n /**\n * If true, the node's children will be displayed.\n * @default false\n */\n expanded?: boolean;\n /**\n * If true, the node will render a loading indicator in place of any children.\n * @default false\n */\n loading?: boolean;\n /** A set of actions attached to the node. */\n actions?: Action[];\n /** Click handler for the tree node. */\n onClick?: (id: TreeNode['id'], e: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>) => void;\n /** URL or DOM id to navigate to. This will render the tree node as a link. */\n href?: string;\n}\n\nexport interface StandardTreeProps extends TreeProps<StandardTreeNode> {\n /** The id of the currently active tree node. */\n currentNodeId?: TreeNode['id'];\n /**\n * If true, a vertical line will render alongside nested nodes.\n * @default false\n */\n lined?: boolean;\n /** Callback function for click events on tree nodes. This will only be called on parent nodes if selectableParents is true. It will always be called on leaf nodes. */\n onNodeClick?: (\n id: TreeNode['id'],\n e: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>\n ) => void;\n /** Callback function for toggling tree nodes between expanded/collapsed states. This is only ever called on parent nodes. */\n onNodeToggle?: (\n id: TreeNode['id'],\n e?: MouseEvent<HTMLElement> | KeyboardEvent<HTMLElement>\n ) => void;\n /**\n * If true, parent tree nodes can be selected independently from being toggled expanded/collapsed.\n * @default true\n */\n selectableParents?: boolean;\n}\n\nexport interface StandardTreeContextProps extends StandardTreeProps {\n firstNodeId?: TreeNode['id'];\n lastNodeId?: TreeNode['id'];\n focusedNodeId?: TreeNode['id'];\n changeFocusedNodeId: (id: TreeNode['id'], type?: 'up' | 'down' | 'left' | 'right') => void;\n}\n\nexport type StandardTreePropsWithDefaults = PropsWithDefaults<StandardTreeContextProps, 'lined'>;\n"]}
|
|
@@ -3,17 +3,19 @@ declare const helpers: {
|
|
|
3
3
|
getNode<T extends TreeNode = TreeNode>(nodes: T[], id: T["id"]): T | undefined;
|
|
4
4
|
getParentNode<T_1 extends TreeNode = TreeNode>(nodes: T_1[], id: T_1["id"]): T_1 | undefined;
|
|
5
5
|
mapTree<T1 extends TreeNode = TreeNode, T2 extends TreeNode = T1>(nodes: T1[], fn: (node: T1, index: number, nodes: T1[]) => T2): T2[];
|
|
6
|
+
forEachNode<T_2 extends TreeNode = TreeNode>(nodes: T_2[], fn: (node: T_2, index: number, nodes: T_2[]) => void): void;
|
|
6
7
|
mapNode<T1_1 extends TreeNode = TreeNode, T2_1 extends TreeNode = T1_1>(nodes: T1_1[], id: T1_1["id"], fn: (node: T1_1, index: number, array: T1_1[]) => T2_1): (T1_1 | T2_1)[];
|
|
7
|
-
flatten<
|
|
8
|
-
ancestors?:
|
|
8
|
+
flatten<T_3 extends TreeNode = TreeNode>(nodes: T_3[], ancestors?: T_3[] | undefined): (T_3 & {
|
|
9
|
+
ancestors?: T_3[] | undefined;
|
|
9
10
|
})[];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
getAncestors<T_4 extends TreeNode = TreeNode>(nodes: T_4[], id: T_4["id"], ancestors?: T_4[]): T_4[];
|
|
12
|
+
appendTo<T_5 extends TreeNode = TreeNode>(nodes: T_5[], id: T_5["id"], newNodes: T_5[]): T_5[];
|
|
13
|
+
expandTo<T_6 extends TreeNode = TreeNode>(nodes: T_6[], id: T_6["id"], collapseOthers?: boolean): T_6[];
|
|
14
|
+
getFirstChildNode<T_7 extends TreeNode = TreeNode>(nodes: T_7[], id: T_7["id"]): T_7 | undefined;
|
|
15
|
+
getAdjacentNode<T_8 extends TreeNode = TreeNode>(nodes: T_8[], id: T_8["id"]): T_8 | undefined;
|
|
16
|
+
getNextNode<T_9 extends TreeNode = TreeNode>(nodes: T_9[], id: T_9["id"]): T_9 | undefined;
|
|
17
|
+
getDeepestNode<T_10 extends TreeNode = TreeNode>(nodes: T_10[], id: T_10["id"]): T_10 | undefined;
|
|
18
|
+
getPreviousNode<T_11 extends TreeNode = TreeNode>(nodes: T_11[], id: T_11["id"]): T_11 | undefined;
|
|
17
19
|
};
|
|
18
20
|
export default helpers;
|
|
19
21
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/components/Tree/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvC,QAAA,MAAM,OAAO;;;yGA8Ca,MAAM;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/components/Tree/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvC,QAAA,MAAM,OAAO;;;yGA8Ca,MAAM;sFAkBP,MAAM,mBAAiB,IAAI,GAC/C,IAAI;mIAaiB,MAAM;;;;;;;;;;;;CA4J/B,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -45,6 +45,14 @@ const helpers = {
|
|
|
45
45
|
return fn(newNode, index, array);
|
|
46
46
|
});
|
|
47
47
|
},
|
|
48
|
+
forEachNode(nodes, fn) {
|
|
49
|
+
nodes.forEach((node, index, array) => {
|
|
50
|
+
if (node.nodes) {
|
|
51
|
+
this.forEachNode(node.nodes, fn);
|
|
52
|
+
}
|
|
53
|
+
fn(node, index, array);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
48
56
|
mapNode(nodes, id, fn) {
|
|
49
57
|
return nodes.map((node, index, array) => {
|
|
50
58
|
let newNode = node;
|
|
@@ -72,6 +80,14 @@ const helpers = {
|
|
|
72
80
|
return [...flatNodes, ancestors ? { ...node, ancestors } : node];
|
|
73
81
|
}, []);
|
|
74
82
|
},
|
|
83
|
+
getAncestors(nodes, id, ancestors = []) {
|
|
84
|
+
const directParent = this.getParentNode(nodes, id);
|
|
85
|
+
if (directParent) {
|
|
86
|
+
ancestors.push(directParent);
|
|
87
|
+
this.getAncestors(nodes, directParent.id, ancestors);
|
|
88
|
+
}
|
|
89
|
+
return ancestors;
|
|
90
|
+
},
|
|
75
91
|
appendTo(nodes, id, newNodes) {
|
|
76
92
|
if (id) {
|
|
77
93
|
return this.mapNode(nodes, id, node => ({
|
|
@@ -81,7 +97,7 @@ const helpers = {
|
|
|
81
97
|
}
|
|
82
98
|
return [...nodes, ...newNodes];
|
|
83
99
|
},
|
|
84
|
-
expandTo(nodes, id) {
|
|
100
|
+
expandTo(nodes, id, collapseOthers = false) {
|
|
85
101
|
return nodes.map(node => {
|
|
86
102
|
// leaf node
|
|
87
103
|
if (node.id === id) {
|
|
@@ -91,14 +107,18 @@ const helpers = {
|
|
|
91
107
|
};
|
|
92
108
|
}
|
|
93
109
|
// parent node
|
|
94
|
-
if (node.nodes
|
|
110
|
+
if (node.nodes) {
|
|
111
|
+
let expanded = collapseOthers ? false : node.expanded;
|
|
112
|
+
if (this.getNode(node.nodes, id)) {
|
|
113
|
+
expanded = true;
|
|
114
|
+
}
|
|
95
115
|
return {
|
|
96
116
|
...node,
|
|
97
|
-
nodes: this.expandTo(node.nodes, id),
|
|
98
|
-
expanded
|
|
117
|
+
nodes: this.expandTo(node.nodes, id, collapseOthers),
|
|
118
|
+
expanded
|
|
99
119
|
};
|
|
100
120
|
}
|
|
101
|
-
return { ...node, expanded: false };
|
|
121
|
+
return { ...node, expanded: collapseOthers ? false : node.expanded };
|
|
102
122
|
});
|
|
103
123
|
},
|
|
104
124
|
getFirstChildNode(nodes, id) {
|