@mui/x-tree-view 6.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3682 -0
- package/LICENSE +21 -0
- package/README.md +34 -0
- package/TreeItem/TreeItem.d.ts +13 -0
- package/TreeItem/TreeItem.js +392 -0
- package/TreeItem/TreeItem.types.d.ts +84 -0
- package/TreeItem/TreeItem.types.js +1 -0
- package/TreeItem/TreeItemContent.d.ts +52 -0
- package/TreeItem/TreeItemContent.js +101 -0
- package/TreeItem/index.d.ts +5 -0
- package/TreeItem/index.js +4 -0
- package/TreeItem/package.json +6 -0
- package/TreeItem/treeItemClasses.d.ts +23 -0
- package/TreeItem/treeItemClasses.js +6 -0
- package/TreeItem/useTreeItem.d.ts +10 -0
- package/TreeItem/useTreeItem.js +68 -0
- package/TreeView/TreeView.d.ts +14 -0
- package/TreeView/TreeView.js +854 -0
- package/TreeView/TreeView.types.d.ts +170 -0
- package/TreeView/TreeView.types.js +1 -0
- package/TreeView/TreeViewContext.d.ts +6 -0
- package/TreeView/TreeViewContext.js +31 -0
- package/TreeView/descendants.d.ts +42 -0
- package/TreeView/descendants.js +186 -0
- package/TreeView/index.d.ts +3 -0
- package/TreeView/index.js +3 -0
- package/TreeView/package.json +6 -0
- package/TreeView/treeViewClasses.d.ts +7 -0
- package/TreeView/treeViewClasses.js +6 -0
- package/index.d.ts +2 -0
- package/index.js +9 -0
- package/internals/models.d.ts +1 -0
- package/internals/models.js +1 -0
- package/legacy/TreeItem/TreeItem.js +391 -0
- package/legacy/TreeItem/TreeItem.types.js +1 -0
- package/legacy/TreeItem/TreeItemContent.js +98 -0
- package/legacy/TreeItem/index.js +4 -0
- package/legacy/TreeItem/treeItemClasses.js +6 -0
- package/legacy/TreeItem/useTreeItem.js +67 -0
- package/legacy/TreeView/TreeView.js +907 -0
- package/legacy/TreeView/TreeView.types.js +1 -0
- package/legacy/TreeView/TreeViewContext.js +41 -0
- package/legacy/TreeView/descendants.js +199 -0
- package/legacy/TreeView/index.js +3 -0
- package/legacy/TreeView/treeViewClasses.js +6 -0
- package/legacy/index.js +9 -0
- package/legacy/internals/models.js +1 -0
- package/modern/TreeItem/TreeItem.js +391 -0
- package/modern/TreeItem/TreeItem.types.js +1 -0
- package/modern/TreeItem/TreeItemContent.js +101 -0
- package/modern/TreeItem/index.js +4 -0
- package/modern/TreeItem/treeItemClasses.js +6 -0
- package/modern/TreeItem/useTreeItem.js +68 -0
- package/modern/TreeView/TreeView.js +853 -0
- package/modern/TreeView/TreeView.types.js +1 -0
- package/modern/TreeView/TreeViewContext.js +31 -0
- package/modern/TreeView/descendants.js +186 -0
- package/modern/TreeView/index.js +3 -0
- package/modern/TreeView/treeViewClasses.js +6 -0
- package/modern/index.js +9 -0
- package/modern/internals/models.js +1 -0
- package/node/TreeItem/TreeItem.js +400 -0
- package/node/TreeItem/TreeItem.types.js +5 -0
- package/node/TreeItem/TreeItemContent.js +109 -0
- package/node/TreeItem/index.js +38 -0
- package/node/TreeItem/treeItemClasses.js +15 -0
- package/node/TreeItem/useTreeItem.js +76 -0
- package/node/TreeView/TreeView.js +862 -0
- package/node/TreeView/TreeView.types.js +5 -0
- package/node/TreeView/TreeViewContext.js +40 -0
- package/node/TreeView/descendants.js +194 -0
- package/node/TreeView/index.js +27 -0
- package/node/TreeView/treeViewClasses.js +15 -0
- package/node/index.js +34 -0
- package/node/internals/models.js +5 -0
- package/package.json +59 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
5
|
+
var _excluded = ["children", "className", "collapseIcon", "ContentComponent", "ContentProps", "endIcon", "expandIcon", "disabled", "icon", "id", "label", "nodeId", "onClick", "onMouseDown", "TransitionComponent", "TransitionProps"];
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import clsx from 'clsx';
|
|
9
|
+
import Collapse from '@mui/material/Collapse';
|
|
10
|
+
import { alpha, styled, useThemeProps } from '@mui/material/styles';
|
|
11
|
+
import ownerDocument from '@mui/utils/ownerDocument';
|
|
12
|
+
import useForkRef from '@mui/utils/useForkRef';
|
|
13
|
+
import unsupportedProp from '@mui/utils/unsupportedProp';
|
|
14
|
+
import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef';
|
|
15
|
+
import { unstable_composeClasses as composeClasses } from '@mui/base';
|
|
16
|
+
import { TreeViewContext } from '../TreeView/TreeViewContext';
|
|
17
|
+
import { DescendantProvider, useDescendant } from '../TreeView/descendants';
|
|
18
|
+
import { TreeItemContent } from './TreeItemContent';
|
|
19
|
+
import { treeItemClasses, getTreeItemUtilityClass } from './treeItemClasses';
|
|
20
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
23
|
+
var classes = ownerState.classes;
|
|
24
|
+
var slots = {
|
|
25
|
+
root: ['root'],
|
|
26
|
+
content: ['content'],
|
|
27
|
+
expanded: ['expanded'],
|
|
28
|
+
selected: ['selected'],
|
|
29
|
+
focused: ['focused'],
|
|
30
|
+
disabled: ['disabled'],
|
|
31
|
+
iconContainer: ['iconContainer'],
|
|
32
|
+
label: ['label'],
|
|
33
|
+
group: ['group']
|
|
34
|
+
};
|
|
35
|
+
return composeClasses(slots, getTreeItemUtilityClass, classes);
|
|
36
|
+
};
|
|
37
|
+
var TreeItemRoot = styled('li', {
|
|
38
|
+
name: 'MuiTreeItem',
|
|
39
|
+
slot: 'Root',
|
|
40
|
+
overridesResolver: function overridesResolver(props, styles) {
|
|
41
|
+
return styles.root;
|
|
42
|
+
}
|
|
43
|
+
})({
|
|
44
|
+
listStyle: 'none',
|
|
45
|
+
margin: 0,
|
|
46
|
+
padding: 0,
|
|
47
|
+
outline: 0
|
|
48
|
+
});
|
|
49
|
+
var StyledTreeItemContent = styled(TreeItemContent, {
|
|
50
|
+
name: 'MuiTreeItem',
|
|
51
|
+
slot: 'Content',
|
|
52
|
+
overridesResolver: function overridesResolver(props, styles) {
|
|
53
|
+
return [styles.content, styles.iconContainer && _defineProperty({}, "& .".concat(treeItemClasses.iconContainer), styles.iconContainer), styles.label && _defineProperty({}, "& .".concat(treeItemClasses.label), styles.label)];
|
|
54
|
+
}
|
|
55
|
+
})(function (_ref3) {
|
|
56
|
+
var _ref4;
|
|
57
|
+
var theme = _ref3.theme;
|
|
58
|
+
return _ref4 = {
|
|
59
|
+
padding: '0 8px',
|
|
60
|
+
width: '100%',
|
|
61
|
+
display: 'flex',
|
|
62
|
+
alignItems: 'center',
|
|
63
|
+
cursor: 'pointer',
|
|
64
|
+
WebkitTapHighlightColor: 'transparent',
|
|
65
|
+
'&:hover': {
|
|
66
|
+
backgroundColor: (theme.vars || theme).palette.action.hover,
|
|
67
|
+
// Reset on touch devices, it doesn't add specificity
|
|
68
|
+
'@media (hover: none)': {
|
|
69
|
+
backgroundColor: 'transparent'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, _defineProperty(_ref4, "&.".concat(treeItemClasses.disabled), {
|
|
73
|
+
opacity: (theme.vars || theme).palette.action.disabledOpacity,
|
|
74
|
+
backgroundColor: 'transparent'
|
|
75
|
+
}), _defineProperty(_ref4, "&.".concat(treeItemClasses.focused), {
|
|
76
|
+
backgroundColor: (theme.vars || theme).palette.action.focus
|
|
77
|
+
}), _defineProperty(_ref4, "&.".concat(treeItemClasses.selected), _defineProperty({
|
|
78
|
+
backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.primary.mainChannel, " / ").concat(theme.vars.palette.action.selectedOpacity, ")") : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity),
|
|
79
|
+
'&:hover': {
|
|
80
|
+
backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.primary.mainChannel, " / calc(").concat(theme.vars.palette.action.selectedOpacity, " + ").concat(theme.vars.palette.action.hoverOpacity, "))") : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity),
|
|
81
|
+
// Reset on touch devices, it doesn't add specificity
|
|
82
|
+
'@media (hover: none)': {
|
|
83
|
+
backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.primary.mainChannel, " / ").concat(theme.vars.palette.action.selectedOpacity, ")") : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}, "&.".concat(treeItemClasses.focused), {
|
|
87
|
+
backgroundColor: theme.vars ? "rgba(".concat(theme.vars.palette.primary.mainChannel, " / calc(").concat(theme.vars.palette.action.selectedOpacity, " + ").concat(theme.vars.palette.action.focusOpacity, "))") : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.focusOpacity)
|
|
88
|
+
})), _defineProperty(_ref4, "& .".concat(treeItemClasses.iconContainer), {
|
|
89
|
+
marginRight: 4,
|
|
90
|
+
width: 15,
|
|
91
|
+
display: 'flex',
|
|
92
|
+
flexShrink: 0,
|
|
93
|
+
justifyContent: 'center',
|
|
94
|
+
'& svg': {
|
|
95
|
+
fontSize: 18
|
|
96
|
+
}
|
|
97
|
+
}), _defineProperty(_ref4, "& .".concat(treeItemClasses.label), _extends({
|
|
98
|
+
width: '100%',
|
|
99
|
+
// fixes overflow - see https://github.com/mui/material-ui/issues/27372
|
|
100
|
+
minWidth: 0,
|
|
101
|
+
paddingLeft: 4,
|
|
102
|
+
position: 'relative'
|
|
103
|
+
}, theme.typography.body1)), _ref4;
|
|
104
|
+
});
|
|
105
|
+
var TreeItemGroup = styled(Collapse, {
|
|
106
|
+
name: 'MuiTreeItem',
|
|
107
|
+
slot: 'Group',
|
|
108
|
+
overridesResolver: function overridesResolver(props, styles) {
|
|
109
|
+
return styles.group;
|
|
110
|
+
}
|
|
111
|
+
})({
|
|
112
|
+
margin: 0,
|
|
113
|
+
padding: 0,
|
|
114
|
+
marginLeft: 17
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
*
|
|
119
|
+
* Demos:
|
|
120
|
+
*
|
|
121
|
+
* - [Tree View](https://mui.com/material-ui/react-tree-view/)
|
|
122
|
+
*
|
|
123
|
+
* API:
|
|
124
|
+
*
|
|
125
|
+
* - [TreeItem API](https://mui.com/material-ui/api/tree-item/)
|
|
126
|
+
*/
|
|
127
|
+
export var TreeItem = /*#__PURE__*/React.forwardRef(function TreeItem(inProps, ref) {
|
|
128
|
+
var props = useThemeProps({
|
|
129
|
+
props: inProps,
|
|
130
|
+
name: 'MuiTreeItem'
|
|
131
|
+
});
|
|
132
|
+
var children = props.children,
|
|
133
|
+
className = props.className,
|
|
134
|
+
collapseIcon = props.collapseIcon,
|
|
135
|
+
_props$ContentCompone = props.ContentComponent,
|
|
136
|
+
ContentComponent = _props$ContentCompone === void 0 ? TreeItemContent : _props$ContentCompone,
|
|
137
|
+
ContentProps = props.ContentProps,
|
|
138
|
+
endIcon = props.endIcon,
|
|
139
|
+
expandIcon = props.expandIcon,
|
|
140
|
+
disabledProp = props.disabled,
|
|
141
|
+
icon = props.icon,
|
|
142
|
+
idProp = props.id,
|
|
143
|
+
label = props.label,
|
|
144
|
+
nodeId = props.nodeId,
|
|
145
|
+
onClick = props.onClick,
|
|
146
|
+
onMouseDown = props.onMouseDown,
|
|
147
|
+
_props$TransitionComp = props.TransitionComponent,
|
|
148
|
+
TransitionComponent = _props$TransitionComp === void 0 ? Collapse : _props$TransitionComp,
|
|
149
|
+
TransitionProps = props.TransitionProps,
|
|
150
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
151
|
+
var _React$useContext = React.useContext(TreeViewContext),
|
|
152
|
+
contextIcons = _React$useContext.icons,
|
|
153
|
+
focus = _React$useContext.focus,
|
|
154
|
+
isExpanded = _React$useContext.isExpanded,
|
|
155
|
+
isFocused = _React$useContext.isFocused,
|
|
156
|
+
isSelected = _React$useContext.isSelected,
|
|
157
|
+
isDisabled = _React$useContext.isDisabled,
|
|
158
|
+
multiSelect = _React$useContext.multiSelect,
|
|
159
|
+
disabledItemsFocusable = _React$useContext.disabledItemsFocusable,
|
|
160
|
+
mapFirstChar = _React$useContext.mapFirstChar,
|
|
161
|
+
unMapFirstChar = _React$useContext.unMapFirstChar,
|
|
162
|
+
registerNode = _React$useContext.registerNode,
|
|
163
|
+
unregisterNode = _React$useContext.unregisterNode,
|
|
164
|
+
treeId = _React$useContext.treeId;
|
|
165
|
+
var id;
|
|
166
|
+
if (idProp != null) {
|
|
167
|
+
id = idProp;
|
|
168
|
+
} else if (treeId && nodeId) {
|
|
169
|
+
id = "".concat(treeId, "-").concat(nodeId);
|
|
170
|
+
}
|
|
171
|
+
var _React$useState = React.useState(null),
|
|
172
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
173
|
+
treeItemElement = _React$useState2[0],
|
|
174
|
+
setTreeItemElement = _React$useState2[1];
|
|
175
|
+
var contentRef = React.useRef(null);
|
|
176
|
+
var handleRef = useForkRef(setTreeItemElement, ref);
|
|
177
|
+
var descendant = React.useMemo(function () {
|
|
178
|
+
return {
|
|
179
|
+
element: treeItemElement,
|
|
180
|
+
id: nodeId
|
|
181
|
+
};
|
|
182
|
+
}, [nodeId, treeItemElement]);
|
|
183
|
+
var _useDescendant = useDescendant(descendant),
|
|
184
|
+
index = _useDescendant.index,
|
|
185
|
+
parentId = _useDescendant.parentId;
|
|
186
|
+
var expandable = Boolean(Array.isArray(children) ? children.length : children);
|
|
187
|
+
var expanded = isExpanded ? isExpanded(nodeId) : false;
|
|
188
|
+
var focused = isFocused ? isFocused(nodeId) : false;
|
|
189
|
+
var selected = isSelected ? isSelected(nodeId) : false;
|
|
190
|
+
var disabled = isDisabled ? isDisabled(nodeId) : false;
|
|
191
|
+
var ownerState = _extends({}, props, {
|
|
192
|
+
expanded: expanded,
|
|
193
|
+
focused: focused,
|
|
194
|
+
selected: selected,
|
|
195
|
+
disabled: disabled
|
|
196
|
+
});
|
|
197
|
+
var classes = useUtilityClasses(ownerState);
|
|
198
|
+
var displayIcon;
|
|
199
|
+
var expansionIcon;
|
|
200
|
+
if (expandable) {
|
|
201
|
+
if (!expanded) {
|
|
202
|
+
expansionIcon = expandIcon || contextIcons.defaultExpandIcon;
|
|
203
|
+
} else {
|
|
204
|
+
expansionIcon = collapseIcon || contextIcons.defaultCollapseIcon;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (expandable) {
|
|
208
|
+
displayIcon = contextIcons.defaultParentIcon;
|
|
209
|
+
} else {
|
|
210
|
+
displayIcon = endIcon || contextIcons.defaultEndIcon;
|
|
211
|
+
}
|
|
212
|
+
React.useEffect(function () {
|
|
213
|
+
// On the first render a node's index will be -1. We want to wait for the real index.
|
|
214
|
+
if (registerNode && unregisterNode && index !== -1) {
|
|
215
|
+
registerNode({
|
|
216
|
+
id: nodeId,
|
|
217
|
+
idAttribute: id,
|
|
218
|
+
index: index,
|
|
219
|
+
parentId: parentId,
|
|
220
|
+
expandable: expandable,
|
|
221
|
+
disabled: disabledProp
|
|
222
|
+
});
|
|
223
|
+
return function () {
|
|
224
|
+
unregisterNode(nodeId);
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
return undefined;
|
|
228
|
+
}, [registerNode, unregisterNode, parentId, index, nodeId, expandable, disabledProp, id]);
|
|
229
|
+
React.useEffect(function () {
|
|
230
|
+
if (mapFirstChar && unMapFirstChar && label) {
|
|
231
|
+
var _contentRef$current$t, _contentRef$current;
|
|
232
|
+
mapFirstChar(nodeId, ((_contentRef$current$t = (_contentRef$current = contentRef.current) == null ? void 0 : _contentRef$current.textContent) != null ? _contentRef$current$t : '').substring(0, 1).toLowerCase());
|
|
233
|
+
return function () {
|
|
234
|
+
unMapFirstChar(nodeId);
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
return undefined;
|
|
238
|
+
}, [mapFirstChar, unMapFirstChar, nodeId, label]);
|
|
239
|
+
var ariaSelected;
|
|
240
|
+
if (multiSelect) {
|
|
241
|
+
ariaSelected = selected;
|
|
242
|
+
} else if (selected) {
|
|
243
|
+
/* single-selection trees unset aria-selected on un-selected items.
|
|
244
|
+
*
|
|
245
|
+
* If the tree does not support multiple selection, aria-selected
|
|
246
|
+
* is set to true for the selected node and it is not present on any other node in the tree.
|
|
247
|
+
* Source: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
|
|
248
|
+
*/
|
|
249
|
+
ariaSelected = true;
|
|
250
|
+
}
|
|
251
|
+
function handleFocus(event) {
|
|
252
|
+
// DOM focus stays on the tree which manages focus with aria-activedescendant
|
|
253
|
+
if (event.target === event.currentTarget) {
|
|
254
|
+
var rootElement;
|
|
255
|
+
if (typeof event.target.getRootNode === 'function') {
|
|
256
|
+
rootElement = event.target.getRootNode();
|
|
257
|
+
} else {
|
|
258
|
+
rootElement = ownerDocument(event.target);
|
|
259
|
+
}
|
|
260
|
+
rootElement.getElementById(treeId).focus({
|
|
261
|
+
preventScroll: true
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
var unfocusable = !disabledItemsFocusable && disabled;
|
|
265
|
+
if (!focused && event.currentTarget === event.target && !unfocusable) {
|
|
266
|
+
focus(event, nodeId);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return /*#__PURE__*/_jsxs(TreeItemRoot, _extends({
|
|
270
|
+
className: clsx(classes.root, className),
|
|
271
|
+
role: "treeitem",
|
|
272
|
+
"aria-expanded": expandable ? expanded : undefined,
|
|
273
|
+
"aria-selected": ariaSelected,
|
|
274
|
+
"aria-disabled": disabled || undefined,
|
|
275
|
+
id: id,
|
|
276
|
+
tabIndex: -1
|
|
277
|
+
}, other, {
|
|
278
|
+
ownerState: ownerState,
|
|
279
|
+
onFocus: handleFocus,
|
|
280
|
+
ref: handleRef,
|
|
281
|
+
children: [/*#__PURE__*/_jsx(StyledTreeItemContent, _extends({
|
|
282
|
+
as: ContentComponent,
|
|
283
|
+
ref: contentRef,
|
|
284
|
+
classes: {
|
|
285
|
+
root: classes.content,
|
|
286
|
+
expanded: classes.expanded,
|
|
287
|
+
selected: classes.selected,
|
|
288
|
+
focused: classes.focused,
|
|
289
|
+
disabled: classes.disabled,
|
|
290
|
+
iconContainer: classes.iconContainer,
|
|
291
|
+
label: classes.label
|
|
292
|
+
},
|
|
293
|
+
label: label,
|
|
294
|
+
nodeId: nodeId,
|
|
295
|
+
onClick: onClick,
|
|
296
|
+
onMouseDown: onMouseDown,
|
|
297
|
+
icon: icon,
|
|
298
|
+
expansionIcon: expansionIcon,
|
|
299
|
+
displayIcon: displayIcon,
|
|
300
|
+
ownerState: ownerState
|
|
301
|
+
}, ContentProps)), children && /*#__PURE__*/_jsx(DescendantProvider, {
|
|
302
|
+
id: nodeId,
|
|
303
|
+
children: /*#__PURE__*/_jsx(TreeItemGroup, _extends({
|
|
304
|
+
as: TransitionComponent,
|
|
305
|
+
unmountOnExit: true,
|
|
306
|
+
className: classes.group,
|
|
307
|
+
in: expanded,
|
|
308
|
+
component: "ul",
|
|
309
|
+
role: "group"
|
|
310
|
+
}, TransitionProps, {
|
|
311
|
+
children: children
|
|
312
|
+
}))
|
|
313
|
+
})]
|
|
314
|
+
}));
|
|
315
|
+
});
|
|
316
|
+
process.env.NODE_ENV !== "production" ? TreeItem.propTypes = {
|
|
317
|
+
// ----------------------------- Warning --------------------------------
|
|
318
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
319
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
320
|
+
// ----------------------------------------------------------------------
|
|
321
|
+
/**
|
|
322
|
+
* The content of the component.
|
|
323
|
+
*/
|
|
324
|
+
children: PropTypes.node,
|
|
325
|
+
/**
|
|
326
|
+
* Override or extend the styles applied to the component.
|
|
327
|
+
*/
|
|
328
|
+
classes: PropTypes.object,
|
|
329
|
+
/**
|
|
330
|
+
* className applied to the root element.
|
|
331
|
+
*/
|
|
332
|
+
className: PropTypes.string,
|
|
333
|
+
/**
|
|
334
|
+
* The icon used to collapse the node.
|
|
335
|
+
*/
|
|
336
|
+
collapseIcon: PropTypes.node,
|
|
337
|
+
/**
|
|
338
|
+
* The component used for the content node.
|
|
339
|
+
* @default TreeItemContent
|
|
340
|
+
*/
|
|
341
|
+
ContentComponent: elementTypeAcceptingRef,
|
|
342
|
+
/**
|
|
343
|
+
* Props applied to ContentComponent.
|
|
344
|
+
*/
|
|
345
|
+
ContentProps: PropTypes.object,
|
|
346
|
+
/**
|
|
347
|
+
* If `true`, the node is disabled.
|
|
348
|
+
* @default false
|
|
349
|
+
*/
|
|
350
|
+
disabled: PropTypes.bool,
|
|
351
|
+
/**
|
|
352
|
+
* The icon displayed next to an end node.
|
|
353
|
+
*/
|
|
354
|
+
endIcon: PropTypes.node,
|
|
355
|
+
/**
|
|
356
|
+
* The icon used to expand the node.
|
|
357
|
+
*/
|
|
358
|
+
expandIcon: PropTypes.node,
|
|
359
|
+
/**
|
|
360
|
+
* The icon to display next to the tree node's label.
|
|
361
|
+
*/
|
|
362
|
+
icon: PropTypes.node,
|
|
363
|
+
/**
|
|
364
|
+
* The tree node label.
|
|
365
|
+
*/
|
|
366
|
+
label: PropTypes.node,
|
|
367
|
+
/**
|
|
368
|
+
* The id of the node.
|
|
369
|
+
*/
|
|
370
|
+
nodeId: PropTypes.string.isRequired,
|
|
371
|
+
/**
|
|
372
|
+
* This prop isn't supported.
|
|
373
|
+
* Use the `onNodeFocus` callback on the tree if you need to monitor a node's focus.
|
|
374
|
+
*/
|
|
375
|
+
onFocus: unsupportedProp,
|
|
376
|
+
/**
|
|
377
|
+
* The system prop that allows defining system overrides as well as additional CSS styles.
|
|
378
|
+
*/
|
|
379
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
380
|
+
/**
|
|
381
|
+
* The component used for the transition.
|
|
382
|
+
* [Follow this guide](/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
|
|
383
|
+
* @default Collapse
|
|
384
|
+
*/
|
|
385
|
+
TransitionComponent: PropTypes.elementType,
|
|
386
|
+
/**
|
|
387
|
+
* Props applied to the transition element.
|
|
388
|
+
* By default, the element is based on this [`Transition`](http://reactcommunity.org/react-transition-group/transition/) component.
|
|
389
|
+
*/
|
|
390
|
+
TransitionProps: PropTypes.object
|
|
391
|
+
} : void 0;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["classes", "className", "displayIcon", "expansionIcon", "icon", "label", "nodeId", "onClick", "onMouseDown"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import clsx from 'clsx';
|
|
7
|
+
import { useTreeItem } from './useTreeItem';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
/**
|
|
11
|
+
* @ignore - internal component.
|
|
12
|
+
*/
|
|
13
|
+
var TreeItemContent = /*#__PURE__*/React.forwardRef(function TreeItemContent(props, ref) {
|
|
14
|
+
var classes = props.classes,
|
|
15
|
+
className = props.className,
|
|
16
|
+
displayIcon = props.displayIcon,
|
|
17
|
+
expansionIcon = props.expansionIcon,
|
|
18
|
+
iconProp = props.icon,
|
|
19
|
+
label = props.label,
|
|
20
|
+
nodeId = props.nodeId,
|
|
21
|
+
onClick = props.onClick,
|
|
22
|
+
onMouseDown = props.onMouseDown,
|
|
23
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
24
|
+
var _useTreeItem = useTreeItem(nodeId),
|
|
25
|
+
disabled = _useTreeItem.disabled,
|
|
26
|
+
expanded = _useTreeItem.expanded,
|
|
27
|
+
selected = _useTreeItem.selected,
|
|
28
|
+
focused = _useTreeItem.focused,
|
|
29
|
+
handleExpansion = _useTreeItem.handleExpansion,
|
|
30
|
+
handleSelection = _useTreeItem.handleSelection,
|
|
31
|
+
preventSelection = _useTreeItem.preventSelection;
|
|
32
|
+
var icon = iconProp || expansionIcon || displayIcon;
|
|
33
|
+
var handleMouseDown = function handleMouseDown(event) {
|
|
34
|
+
preventSelection(event);
|
|
35
|
+
if (onMouseDown) {
|
|
36
|
+
onMouseDown(event);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var handleClick = function handleClick(event) {
|
|
40
|
+
handleExpansion(event);
|
|
41
|
+
handleSelection(event);
|
|
42
|
+
if (onClick) {
|
|
43
|
+
onClick(event);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return (
|
|
47
|
+
/*#__PURE__*/
|
|
48
|
+
/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions -- Key event is handled by the TreeView */
|
|
49
|
+
_jsxs("div", _extends({}, other, {
|
|
50
|
+
className: clsx(className, classes.root, expanded && classes.expanded, selected && classes.selected, focused && classes.focused, disabled && classes.disabled),
|
|
51
|
+
onClick: handleClick,
|
|
52
|
+
onMouseDown: handleMouseDown,
|
|
53
|
+
ref: ref,
|
|
54
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
55
|
+
className: classes.iconContainer,
|
|
56
|
+
children: icon
|
|
57
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
58
|
+
className: classes.label,
|
|
59
|
+
children: label
|
|
60
|
+
})]
|
|
61
|
+
}))
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
process.env.NODE_ENV !== "production" ? TreeItemContent.propTypes = {
|
|
65
|
+
// ----------------------------- Warning --------------------------------
|
|
66
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
67
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
68
|
+
// ----------------------------------------------------------------------
|
|
69
|
+
/**
|
|
70
|
+
* Override or extend the styles applied to the component.
|
|
71
|
+
*/
|
|
72
|
+
classes: PropTypes.object.isRequired,
|
|
73
|
+
/**
|
|
74
|
+
* className applied to the root element.
|
|
75
|
+
*/
|
|
76
|
+
className: PropTypes.string,
|
|
77
|
+
/**
|
|
78
|
+
* The icon to display next to the tree node's label. Either a parent or end icon.
|
|
79
|
+
*/
|
|
80
|
+
displayIcon: PropTypes.node,
|
|
81
|
+
/**
|
|
82
|
+
* The icon to display next to the tree node's label. Either an expansion or collapse icon.
|
|
83
|
+
*/
|
|
84
|
+
expansionIcon: PropTypes.node,
|
|
85
|
+
/**
|
|
86
|
+
* The icon to display next to the tree node's label.
|
|
87
|
+
*/
|
|
88
|
+
icon: PropTypes.node,
|
|
89
|
+
/**
|
|
90
|
+
* The tree node label.
|
|
91
|
+
*/
|
|
92
|
+
label: PropTypes.node,
|
|
93
|
+
/**
|
|
94
|
+
* The id of the node.
|
|
95
|
+
*/
|
|
96
|
+
nodeId: PropTypes.string.isRequired
|
|
97
|
+
} : void 0;
|
|
98
|
+
export { TreeItemContent };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
2
|
+
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
3
|
+
export function getTreeItemUtilityClass(slot) {
|
|
4
|
+
return generateUtilityClass('MuiTreeItem', slot);
|
|
5
|
+
}
|
|
6
|
+
export var treeItemClasses = generateUtilityClasses('MuiTreeItem', ['root', 'group', 'content', 'expanded', 'selected', 'focused', 'disabled', 'iconContainer', 'label']);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TreeViewContext } from '../TreeView/TreeViewContext';
|
|
3
|
+
export function useTreeItem(nodeId) {
|
|
4
|
+
var _React$useContext = React.useContext(TreeViewContext),
|
|
5
|
+
focus = _React$useContext.focus,
|
|
6
|
+
isExpanded = _React$useContext.isExpanded,
|
|
7
|
+
isExpandable = _React$useContext.isExpandable,
|
|
8
|
+
isFocused = _React$useContext.isFocused,
|
|
9
|
+
isDisabled = _React$useContext.isDisabled,
|
|
10
|
+
isSelected = _React$useContext.isSelected,
|
|
11
|
+
multiSelect = _React$useContext.multiSelect,
|
|
12
|
+
selectNode = _React$useContext.selectNode,
|
|
13
|
+
selectRange = _React$useContext.selectRange,
|
|
14
|
+
toggleExpansion = _React$useContext.toggleExpansion;
|
|
15
|
+
var expandable = isExpandable ? isExpandable(nodeId) : false;
|
|
16
|
+
var expanded = isExpanded ? isExpanded(nodeId) : false;
|
|
17
|
+
var focused = isFocused ? isFocused(nodeId) : false;
|
|
18
|
+
var disabled = isDisabled ? isDisabled(nodeId) : false;
|
|
19
|
+
var selected = isSelected ? isSelected(nodeId) : false;
|
|
20
|
+
var handleExpansion = function handleExpansion(event) {
|
|
21
|
+
if (!disabled) {
|
|
22
|
+
if (!focused) {
|
|
23
|
+
focus(event, nodeId);
|
|
24
|
+
}
|
|
25
|
+
var multiple = multiSelect && (event.shiftKey || event.ctrlKey || event.metaKey);
|
|
26
|
+
|
|
27
|
+
// If already expanded and trying to toggle selection don't close
|
|
28
|
+
if (expandable && !(multiple && isExpanded(nodeId))) {
|
|
29
|
+
toggleExpansion(event, nodeId);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var handleSelection = function handleSelection(event) {
|
|
34
|
+
if (!disabled) {
|
|
35
|
+
if (!focused) {
|
|
36
|
+
focus(event, nodeId);
|
|
37
|
+
}
|
|
38
|
+
var multiple = multiSelect && (event.shiftKey || event.ctrlKey || event.metaKey);
|
|
39
|
+
if (multiple) {
|
|
40
|
+
if (event.shiftKey) {
|
|
41
|
+
selectRange(event, {
|
|
42
|
+
end: nodeId
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
selectNode(event, nodeId, true);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
selectNode(event, nodeId);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var preventSelection = function preventSelection(event) {
|
|
53
|
+
if (event.shiftKey || event.ctrlKey || event.metaKey || disabled) {
|
|
54
|
+
// Prevent text selection
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
disabled: disabled,
|
|
60
|
+
expanded: expanded,
|
|
61
|
+
selected: selected,
|
|
62
|
+
focused: focused,
|
|
63
|
+
handleExpansion: handleExpansion,
|
|
64
|
+
handleSelection: handleSelection,
|
|
65
|
+
preventSelection: preventSelection
|
|
66
|
+
};
|
|
67
|
+
}
|