@pingux/astro 2.235.0-alpha.0 → 2.236.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/cjs/components/Tree/Tree.d.ts +9 -0
- package/lib/cjs/components/Tree/Tree.js +48 -0
- package/lib/cjs/components/Tree/Tree.mdx +58 -0
- package/lib/cjs/components/Tree/Tree.stories.js +786 -0
- package/lib/cjs/components/Tree/Tree.styles.d.ts +4 -0
- package/lib/cjs/components/Tree/Tree.styles.js +332 -0
- package/lib/cjs/components/Tree/Tree.test.js +300 -0
- package/lib/cjs/components/Tree/TreeItem.d.ts +22 -0
- package/lib/cjs/components/Tree/TreeItem.js +82 -0
- package/lib/cjs/components/Tree/TreeItemContent.d.ts +11 -0
- package/lib/cjs/components/Tree/TreeItemContent.js +102 -0
- package/lib/cjs/components/Tree/index.d.ts +5 -0
- package/lib/cjs/components/Tree/index.js +52 -0
- package/lib/cjs/components/Tree/useTreeDragAndDrop.d.ts +46 -0
- package/lib/cjs/components/Tree/useTreeDragAndDrop.js +76 -0
- package/lib/cjs/context/TooltipContext/index.js +2 -1
- package/lib/cjs/hooks/useCircularLoader/useCircularLoader.d.ts +1 -0
- package/lib/cjs/hooks/useCircularLoader/useCircularLoader.js +3 -2
- package/lib/cjs/hooks/useGetTheme/useGetTheme.d.ts +4 -0
- package/lib/cjs/hooks/useGridListItem/useGridListItem.d.ts +4 -4
- package/lib/cjs/hooks/useOverlayPanelState/useOverlayPanelState.test.js +3 -1
- package/lib/cjs/hooks/usePagination/usePagination.d.ts +8 -8
- package/lib/cjs/hooks/useStatusClasses/useStatusClasses.js +2 -8
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +43 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/colors.d.ts +1 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/colors.js +7 -1
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/customProperties/icons.d.ts +2 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/customProperties/index.d.ts +2 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/buttons.d.ts +15 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/buttons.js +15 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/tree.d.ts +15 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/tree.js +160 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/variants.d.ts +9 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/variants.js +3 -1
- package/lib/cjs/styles/themeOverrides/onyxSideNav.d.ts +2 -0
- package/lib/cjs/styles/themes/astro/customProperties/icons.d.ts +2 -0
- package/lib/cjs/styles/themes/astro/customProperties/icons.js +3 -1
- package/lib/cjs/styles/themes/astro/customProperties/index.d.ts +2 -0
- package/lib/cjs/styles/themes/next-gen/convertedComponentList.js +1 -1
- package/lib/cjs/styles/themes/next-gen/customProperties/icons.d.ts +2 -0
- package/lib/cjs/styles/themes/next-gen/customProperties/icons.js +1 -1
- package/lib/cjs/styles/themes/next-gen/customProperties/index.d.ts +2 -0
- package/lib/cjs/styles/themes/next-gen/next-gen.d.ts +27 -0
- package/lib/cjs/styles/themes/next-gen/variants/button.d.ts +15 -0
- package/lib/cjs/styles/themes/next-gen/variants/button.js +11 -0
- package/lib/cjs/styles/themes/next-gen/variants/tree.d.ts +16 -0
- package/lib/cjs/styles/themes/next-gen/variants/tree.js +153 -0
- package/lib/cjs/styles/themes/next-gen/variants/variants.d.ts +10 -0
- package/lib/cjs/styles/themes/next-gen/variants/variants.js +2 -0
- package/lib/cjs/styles/variants/index.js +3 -1
- package/lib/cjs/styles/variants/variants.js +2 -0
- package/lib/cjs/utils/getStatusClasses.d.ts +13 -0
- package/lib/cjs/utils/getStatusClasses.js +29 -0
- package/lib/components/Tree/Tree.js +33 -0
- package/lib/components/Tree/Tree.mdx +58 -0
- package/lib/components/Tree/Tree.stories.js +775 -0
- package/lib/components/Tree/Tree.styles.js +325 -0
- package/lib/components/Tree/Tree.test.js +297 -0
- package/lib/components/Tree/TreeItem.js +70 -0
- package/lib/components/Tree/TreeItemContent.js +94 -0
- package/lib/components/Tree/index.js +5 -0
- package/lib/components/Tree/useTreeDragAndDrop.js +69 -0
- package/lib/context/TooltipContext/index.js +2 -1
- package/lib/hooks/useCircularLoader/useCircularLoader.js +3 -2
- package/lib/hooks/useOverlayPanelState/useOverlayPanelState.test.js +3 -1
- package/lib/hooks/useStatusClasses/useStatusClasses.js +2 -8
- package/lib/index.js +1 -0
- package/lib/styles/themeOverrides/nextGenDarkMode/colors.js +7 -1
- package/lib/styles/themeOverrides/nextGenDarkMode/variants/buttons.js +15 -0
- package/lib/styles/themeOverrides/nextGenDarkMode/variants/tree.js +154 -0
- package/lib/styles/themeOverrides/nextGenDarkMode/variants/variants.js +3 -1
- package/lib/styles/themes/astro/customProperties/icons.js +3 -1
- package/lib/styles/themes/next-gen/convertedComponentList.js +1 -1
- package/lib/styles/themes/next-gen/customProperties/icons.js +1 -1
- package/lib/styles/themes/next-gen/variants/button.js +11 -0
- package/lib/styles/themes/next-gen/variants/tree.js +147 -0
- package/lib/styles/themes/next-gen/variants/variants.js +2 -0
- package/lib/styles/variants/index.js +3 -1
- package/lib/styles/variants/variants.js +2 -0
- package/lib/utils/getStatusClasses.js +22 -0
- package/package.json +9 -6
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
2
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
4
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
5
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
6
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
7
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
|
8
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
9
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
10
|
+
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
var tree = {
|
|
13
|
+
outline: 'none'
|
|
14
|
+
};
|
|
15
|
+
tree.container = {
|
|
16
|
+
display: 'flex',
|
|
17
|
+
flexDirection: 'column',
|
|
18
|
+
width: '100%',
|
|
19
|
+
outline: 'none',
|
|
20
|
+
p: 'sm',
|
|
21
|
+
borderRadius: '4px',
|
|
22
|
+
'& .react-aria-DropIndicator': {
|
|
23
|
+
height: '2px',
|
|
24
|
+
'&::before': {
|
|
25
|
+
content: '""',
|
|
26
|
+
display: 'block',
|
|
27
|
+
height: '2px',
|
|
28
|
+
borderRadius: '2px',
|
|
29
|
+
bg: 'transparent',
|
|
30
|
+
margin: '0px'
|
|
31
|
+
},
|
|
32
|
+
'&[data-drop-target]::before': {
|
|
33
|
+
bg: 'active'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
tree.item = {
|
|
38
|
+
outline: 'none',
|
|
39
|
+
cursor: 'pointer',
|
|
40
|
+
borderRadius: '4px',
|
|
41
|
+
'&.is-focused, &[data-focused]': {
|
|
42
|
+
outline: '1px solid',
|
|
43
|
+
outlineColor: 'focus',
|
|
44
|
+
outlineOffset: '-1px',
|
|
45
|
+
borderRadius: '4px',
|
|
46
|
+
zIndex: 1
|
|
47
|
+
},
|
|
48
|
+
// the drag handle / chevron carry their own focus treatment, so the
|
|
49
|
+
// row-level outline is suppressed while either is focused
|
|
50
|
+
'&:has(.astro-TreeDragButton:focus), &:has(.astro-TreeDragButton:focus-visible), &:has(.astro-TreeChevronButton:focus), &:has(.astro-TreeChevronButton:focus-visible)': {
|
|
51
|
+
outline: 'none'
|
|
52
|
+
},
|
|
53
|
+
'&.is-focus-visible, &[data-focus-visible]': {
|
|
54
|
+
outline: '2px solid',
|
|
55
|
+
outlineColor: 'focus',
|
|
56
|
+
outlineOffset: '-1px',
|
|
57
|
+
borderRadius: '4px'
|
|
58
|
+
},
|
|
59
|
+
'&.is-selected, &[data-selected]': {
|
|
60
|
+
bg: 'accent.95',
|
|
61
|
+
'& *': {
|
|
62
|
+
color: 'active'
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
'&.is-disabled, &[data-disabled]': {
|
|
66
|
+
opacity: 0.65,
|
|
67
|
+
cursor: 'not-allowed'
|
|
68
|
+
},
|
|
69
|
+
'&.is-dragging, &[data-dragging]': {
|
|
70
|
+
bg: 'accent.95',
|
|
71
|
+
outline: '2px solid',
|
|
72
|
+
outlineColor: 'active',
|
|
73
|
+
outlineOffset: '-1px',
|
|
74
|
+
borderRadius: '4px',
|
|
75
|
+
'& *': {
|
|
76
|
+
color: 'active'
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
'&.is-drop-target, &[data-drop-target]': {
|
|
80
|
+
outline: '2px dashed',
|
|
81
|
+
outlineColor: 'active',
|
|
82
|
+
outlineOffset: '-1px',
|
|
83
|
+
borderRadius: '4px'
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
tree.dragButton = {
|
|
87
|
+
display: 'inline-flex',
|
|
88
|
+
alignItems: 'center',
|
|
89
|
+
justifyContent: 'center',
|
|
90
|
+
width: '26px',
|
|
91
|
+
height: '26px',
|
|
92
|
+
minWidth: '26px',
|
|
93
|
+
padding: 0,
|
|
94
|
+
background: 'transparent',
|
|
95
|
+
border: 'none',
|
|
96
|
+
cursor: 'grab',
|
|
97
|
+
borderRadius: '4px',
|
|
98
|
+
outline: 'none',
|
|
99
|
+
color: 'inherit',
|
|
100
|
+
transition: 'background-color 120ms ease, outline-color 120ms ease',
|
|
101
|
+
path: {
|
|
102
|
+
fill: 'neutral.40'
|
|
103
|
+
},
|
|
104
|
+
'&:hover': {
|
|
105
|
+
bg: 'accent.95',
|
|
106
|
+
'& svg': {
|
|
107
|
+
fill: 'active'
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
'&:focus, &:focus-visible': {
|
|
111
|
+
outline: '1px solid',
|
|
112
|
+
outlineColor: 'focus',
|
|
113
|
+
outlineOffset: '2px',
|
|
114
|
+
borderRadius: '4px'
|
|
115
|
+
},
|
|
116
|
+
'&:active, &[data-pressed]': {
|
|
117
|
+
bg: 'active',
|
|
118
|
+
cursor: 'grabbing',
|
|
119
|
+
'& svg': {
|
|
120
|
+
fill: 'white'
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
export var treeChevron = {
|
|
125
|
+
display: 'inline-flex',
|
|
126
|
+
alignItems: 'center',
|
|
127
|
+
justifyContent: 'center',
|
|
128
|
+
width: '18px',
|
|
129
|
+
height: '18px',
|
|
130
|
+
minWidth: '18px',
|
|
131
|
+
minHeight: '18px',
|
|
132
|
+
boxSizing: 'border-box',
|
|
133
|
+
margin: 0,
|
|
134
|
+
padding: 0,
|
|
135
|
+
background: 'transparent',
|
|
136
|
+
border: 'none',
|
|
137
|
+
outline: 'none',
|
|
138
|
+
boxShadow: 'none',
|
|
139
|
+
cursor: 'pointer',
|
|
140
|
+
color: 'inherit',
|
|
141
|
+
'& svg': {
|
|
142
|
+
width: '18px',
|
|
143
|
+
height: '18px'
|
|
144
|
+
},
|
|
145
|
+
'& > span': {
|
|
146
|
+
width: '18px',
|
|
147
|
+
height: '18px',
|
|
148
|
+
minWidth: '18px',
|
|
149
|
+
minHeight: '18px',
|
|
150
|
+
display: 'flex',
|
|
151
|
+
alignItems: 'center',
|
|
152
|
+
justifyContent: 'center'
|
|
153
|
+
},
|
|
154
|
+
path: {
|
|
155
|
+
fill: 'neutral.40'
|
|
156
|
+
},
|
|
157
|
+
'&.is-hovered, &:hover, &.is-pressed, &:active': {
|
|
158
|
+
background: 'transparent',
|
|
159
|
+
border: 'none',
|
|
160
|
+
boxShadow: 'none',
|
|
161
|
+
outline: 'none'
|
|
162
|
+
},
|
|
163
|
+
'&.is-focused': {
|
|
164
|
+
outline: 'none'
|
|
165
|
+
},
|
|
166
|
+
'&:focus, &:focus-visible': {
|
|
167
|
+
outline: '1px solid',
|
|
168
|
+
outlineColor: 'focus',
|
|
169
|
+
outlineOffset: '2px'
|
|
170
|
+
},
|
|
171
|
+
'&[data-disabled]': {
|
|
172
|
+
cursor: 'not-allowed'
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
tree.chevronButton = treeChevron;
|
|
176
|
+
tree.selectionCheckbox = {
|
|
177
|
+
display: 'inline-flex',
|
|
178
|
+
alignItems: 'center',
|
|
179
|
+
flexShrink: 0,
|
|
180
|
+
cursor: 'pointer',
|
|
181
|
+
outline: 'none',
|
|
182
|
+
'&:focus-visible, [data-focus-visible]': {
|
|
183
|
+
outline: '1px solid',
|
|
184
|
+
outlineColor: 'focus',
|
|
185
|
+
outlineOffset: '2px'
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
tree.selectionCheckboxBox = {
|
|
189
|
+
position: 'relative',
|
|
190
|
+
display: 'inline-flex',
|
|
191
|
+
alignItems: 'center',
|
|
192
|
+
justifyContent: 'center',
|
|
193
|
+
width: '14px',
|
|
194
|
+
height: '14px',
|
|
195
|
+
flexShrink: 0,
|
|
196
|
+
mr: 'xs',
|
|
197
|
+
cursor: 'pointer',
|
|
198
|
+
outline: 'none',
|
|
199
|
+
border: '2px solid',
|
|
200
|
+
borderColor: 'neutral.60',
|
|
201
|
+
borderRadius: '2px',
|
|
202
|
+
background: 'transparent',
|
|
203
|
+
transition: 'background-color 120ms ease, border-color 120ms ease',
|
|
204
|
+
'&::after': {
|
|
205
|
+
content: '""',
|
|
206
|
+
display: 'none',
|
|
207
|
+
position: 'absolute',
|
|
208
|
+
left: '50%',
|
|
209
|
+
top: '50%',
|
|
210
|
+
width: '4px',
|
|
211
|
+
height: '8px',
|
|
212
|
+
border: 'solid',
|
|
213
|
+
borderColor: 'white',
|
|
214
|
+
borderWidth: '0 2px 2px 0',
|
|
215
|
+
transform: 'translate(-50%, -60%) rotate(45deg)'
|
|
216
|
+
},
|
|
217
|
+
'&[data-selected]': {
|
|
218
|
+
borderColor: 'active',
|
|
219
|
+
bg: 'active',
|
|
220
|
+
'&::after': {
|
|
221
|
+
display: 'block'
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
'[data-hovered] &, [data-pressed] &': {
|
|
225
|
+
borderColor: 'active'
|
|
226
|
+
},
|
|
227
|
+
'&[data-disabled]': {
|
|
228
|
+
cursor: 'not-allowed',
|
|
229
|
+
borderColor: 'neutral.80',
|
|
230
|
+
background: 'neutral.95'
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
tree.itemContent = {
|
|
234
|
+
display: 'flex',
|
|
235
|
+
flexDirection: 'row',
|
|
236
|
+
alignItems: 'center',
|
|
237
|
+
flexWrap: 'nowrap',
|
|
238
|
+
width: '100%',
|
|
239
|
+
minHeight: '28px',
|
|
240
|
+
height: '28px',
|
|
241
|
+
fontSize: 'md',
|
|
242
|
+
fontFamily: 'standard',
|
|
243
|
+
pl: 'xs',
|
|
244
|
+
'&:hover': {
|
|
245
|
+
bg: 'accent.99',
|
|
246
|
+
borderRadius: '4px'
|
|
247
|
+
},
|
|
248
|
+
'&.is-loading': {
|
|
249
|
+
opacity: 0.7
|
|
250
|
+
},
|
|
251
|
+
'& .astro-TreeDragButton': _objectSpread(_objectSpread({}, tree.dragButton), {}, {
|
|
252
|
+
mr: 'xs'
|
|
253
|
+
}),
|
|
254
|
+
'& > .astro-TreeChevronSlot': {
|
|
255
|
+
marginLeft: 'calc((var(--tree-item-level, 1) - 1) * 34px)'
|
|
256
|
+
},
|
|
257
|
+
'& .astro-TreeChevronButton': tree.chevronButton,
|
|
258
|
+
'& .astro-TreeSelectionCheckbox': _objectSpread(_objectSpread({}, tree.selectionCheckbox), {}, {
|
|
259
|
+
mr: 'xs'
|
|
260
|
+
}),
|
|
261
|
+
'& .astro-TreeSelectionCheckboxBox': tree.selectionCheckboxBox
|
|
262
|
+
};
|
|
263
|
+
tree.labelSlot = {
|
|
264
|
+
display: 'flex',
|
|
265
|
+
alignItems: 'center',
|
|
266
|
+
flexWrap: 'nowrap',
|
|
267
|
+
minWidth: 0
|
|
268
|
+
};
|
|
269
|
+
tree.iconSlot = {
|
|
270
|
+
display: 'flex',
|
|
271
|
+
alignItems: 'center',
|
|
272
|
+
justifyContent: 'center',
|
|
273
|
+
width: '24px',
|
|
274
|
+
height: '24px',
|
|
275
|
+
minWidth: '24px',
|
|
276
|
+
minHeight: '24px',
|
|
277
|
+
p: '3px',
|
|
278
|
+
boxSizing: 'border-box',
|
|
279
|
+
borderRadius: '100px',
|
|
280
|
+
bg: 'accent.99',
|
|
281
|
+
color: 'text.primary',
|
|
282
|
+
mr: 'xs',
|
|
283
|
+
'& svg': {
|
|
284
|
+
width: '18px',
|
|
285
|
+
height: '18px',
|
|
286
|
+
fill: 'currentColor'
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
tree.chevronSlot = {
|
|
290
|
+
display: 'flex',
|
|
291
|
+
alignItems: 'center',
|
|
292
|
+
justifyContent: 'center',
|
|
293
|
+
width: '18px',
|
|
294
|
+
minWidth: '18px',
|
|
295
|
+
mr: 'sm'
|
|
296
|
+
};
|
|
297
|
+
tree.lockSlot = {
|
|
298
|
+
display: 'inline-flex',
|
|
299
|
+
alignItems: 'center',
|
|
300
|
+
justifyContent: 'center',
|
|
301
|
+
width: '16px',
|
|
302
|
+
height: '16px',
|
|
303
|
+
minWidth: '16px',
|
|
304
|
+
ml: 'xs',
|
|
305
|
+
flexShrink: 0,
|
|
306
|
+
color: 'neutral.60',
|
|
307
|
+
'& svg': {
|
|
308
|
+
width: '16px',
|
|
309
|
+
height: '16px',
|
|
310
|
+
fill: 'currentColor'
|
|
311
|
+
},
|
|
312
|
+
'& > span': {
|
|
313
|
+
width: '16px',
|
|
314
|
+
height: '16px',
|
|
315
|
+
minWidth: '16px',
|
|
316
|
+
minHeight: '16px',
|
|
317
|
+
display: 'flex',
|
|
318
|
+
alignItems: 'center',
|
|
319
|
+
justifyContent: 'center'
|
|
320
|
+
},
|
|
321
|
+
'&.is-unlocked': {
|
|
322
|
+
opacity: 0.6
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
export default tree;
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
2
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
3
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
4
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
5
|
+
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
|
6
|
+
import _everyInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/every";
|
|
7
|
+
import _Set from "@babel/runtime-corejs3/core-js-stable/set";
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
|
|
10
|
+
import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
|
|
11
|
+
import Tree from './Tree';
|
|
12
|
+
import TreeItem from './TreeItem';
|
|
13
|
+
import TreeItemContent from './TreeItemContent';
|
|
14
|
+
import useTreeDragAndDrop from './useTreeDragAndDrop';
|
|
15
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
16
|
+
var items = [{
|
|
17
|
+
id: 'documents',
|
|
18
|
+
name: 'Documents'
|
|
19
|
+
}, {
|
|
20
|
+
id: 'reports',
|
|
21
|
+
name: 'Reports'
|
|
22
|
+
}, {
|
|
23
|
+
id: 'policies',
|
|
24
|
+
name: 'Policies'
|
|
25
|
+
}];
|
|
26
|
+
var getComponent = function getComponent() {
|
|
27
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
28
|
+
return render(___EmotionJSX(Tree, _extends({
|
|
29
|
+
"aria-label": "Test tree",
|
|
30
|
+
selectionMode: "multiple",
|
|
31
|
+
items: items
|
|
32
|
+
}, props), function (item) {
|
|
33
|
+
return ___EmotionJSX(TreeItem, {
|
|
34
|
+
key: item.id,
|
|
35
|
+
id: item.id,
|
|
36
|
+
textValue: item.name
|
|
37
|
+
}, ___EmotionJSX(TreeItemContent, null, item.name));
|
|
38
|
+
}));
|
|
39
|
+
};
|
|
40
|
+
universalComponentTests({
|
|
41
|
+
renderComponent: function renderComponent(props) {
|
|
42
|
+
return ___EmotionJSX(Tree, _extends({
|
|
43
|
+
"aria-label": "Universal tree",
|
|
44
|
+
items: items
|
|
45
|
+
}, props), function (item) {
|
|
46
|
+
return ___EmotionJSX(TreeItem, {
|
|
47
|
+
key: item.id,
|
|
48
|
+
id: item.id,
|
|
49
|
+
textValue: item.name
|
|
50
|
+
}, ___EmotionJSX(TreeItemContent, null, item.name));
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
rules: {
|
|
54
|
+
'aria-allowed-attr': {
|
|
55
|
+
enabled: false
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
test('renders all items', function () {
|
|
60
|
+
getComponent();
|
|
61
|
+
_forEachInstanceProperty(items).call(items, function (_ref) {
|
|
62
|
+
var name = _ref.name;
|
|
63
|
+
expect(screen.getByText(name)).toBeInTheDocument();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
test('renders a row per item with the item role', function () {
|
|
67
|
+
getComponent();
|
|
68
|
+
expect(screen.getAllByRole('row')).toHaveLength(items.length);
|
|
69
|
+
});
|
|
70
|
+
test('renders a visible checkbox input per item when selection is enabled', function () {
|
|
71
|
+
getComponent();
|
|
72
|
+
var checkboxes = screen.getAllByRole('checkbox');
|
|
73
|
+
expect(checkboxes).toHaveLength(items.length);
|
|
74
|
+
_forEachInstanceProperty(checkboxes).call(checkboxes, function (input) {
|
|
75
|
+
expect(input).toBeInstanceOf(HTMLInputElement);
|
|
76
|
+
expect(input).toBeEnabled();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
test('selection via checkbox toggles the row selected state', function () {
|
|
80
|
+
getComponent();
|
|
81
|
+
var _screen$getAllByRole = screen.getAllByRole('checkbox'),
|
|
82
|
+
_screen$getAllByRole2 = _slicedToArray(_screen$getAllByRole, 1),
|
|
83
|
+
first = _screen$getAllByRole2[0];
|
|
84
|
+
fireEvent.click(first);
|
|
85
|
+
expect(screen.getAllByRole('row')[0]).toHaveAttribute('data-selected');
|
|
86
|
+
fireEvent.click(first);
|
|
87
|
+
expect(screen.getAllByRole('row')[0]).not.toHaveAttribute('data-selected');
|
|
88
|
+
});
|
|
89
|
+
test('no checkboxes render when selectionMode is none', function () {
|
|
90
|
+
render(___EmotionJSX(Tree, {
|
|
91
|
+
"aria-label": "Unselectable tree",
|
|
92
|
+
items: items,
|
|
93
|
+
selectionMode: "none"
|
|
94
|
+
}, function (item) {
|
|
95
|
+
return ___EmotionJSX(TreeItem, {
|
|
96
|
+
key: item.id,
|
|
97
|
+
id: item.id,
|
|
98
|
+
textValue: item.name
|
|
99
|
+
}, ___EmotionJSX(TreeItemContent, null, item.name));
|
|
100
|
+
}));
|
|
101
|
+
expect(screen.queryAllByRole('checkbox')).toHaveLength(0);
|
|
102
|
+
});
|
|
103
|
+
test('renders expand chevron only for items with children', function () {
|
|
104
|
+
render(___EmotionJSX(Tree, {
|
|
105
|
+
"aria-label": "Nested tree",
|
|
106
|
+
selectionMode: "none"
|
|
107
|
+
}, ___EmotionJSX(TreeItem, {
|
|
108
|
+
id: "parent",
|
|
109
|
+
textValue: "Parent"
|
|
110
|
+
}, ___EmotionJSX(TreeItemContent, null, "Parent"), ___EmotionJSX(TreeItem, {
|
|
111
|
+
id: "child",
|
|
112
|
+
textValue: "Child"
|
|
113
|
+
}, ___EmotionJSX(TreeItemContent, null, "Child"))), ___EmotionJSX(TreeItem, {
|
|
114
|
+
id: "leaf",
|
|
115
|
+
textValue: "Leaf"
|
|
116
|
+
}, ___EmotionJSX(TreeItemContent, null, "Leaf"))));
|
|
117
|
+
expect(screen.getByLabelText('Expand')).toBeInTheDocument();
|
|
118
|
+
expect(screen.getAllByLabelText('Expand')).toHaveLength(1);
|
|
119
|
+
});
|
|
120
|
+
test('expanding a parent reveals its children and toggles aria-expanded', function () {
|
|
121
|
+
render(___EmotionJSX(Tree, {
|
|
122
|
+
"aria-label": "Nested tree",
|
|
123
|
+
selectionMode: "none"
|
|
124
|
+
}, ___EmotionJSX(TreeItem, {
|
|
125
|
+
id: "parent",
|
|
126
|
+
textValue: "Parent"
|
|
127
|
+
}, ___EmotionJSX(TreeItemContent, null, "Parent"), ___EmotionJSX(TreeItem, {
|
|
128
|
+
id: "child",
|
|
129
|
+
textValue: "Child"
|
|
130
|
+
}, ___EmotionJSX(TreeItemContent, null, "Child")))));
|
|
131
|
+
expect(screen.queryByText('Child')).not.toBeInTheDocument();
|
|
132
|
+
fireEvent.click(screen.getByLabelText('Expand'));
|
|
133
|
+
expect(screen.getByText('Child')).toBeInTheDocument();
|
|
134
|
+
expect(screen.getByLabelText('Collapse')).toBeInTheDocument();
|
|
135
|
+
});
|
|
136
|
+
test('disabled item cannot be selected', function () {
|
|
137
|
+
render(___EmotionJSX(Tree, {
|
|
138
|
+
"aria-label": "Disabled tree",
|
|
139
|
+
selectionMode: "multiple",
|
|
140
|
+
disabledKeys: ['reports'],
|
|
141
|
+
disabledBehavior: "all",
|
|
142
|
+
items: items
|
|
143
|
+
}, function (item) {
|
|
144
|
+
return ___EmotionJSX(TreeItem, {
|
|
145
|
+
key: item.id,
|
|
146
|
+
id: item.id,
|
|
147
|
+
textValue: item.name
|
|
148
|
+
}, ___EmotionJSX(TreeItemContent, null, item.name));
|
|
149
|
+
}));
|
|
150
|
+
var rows = screen.getAllByRole('row');
|
|
151
|
+
var reportsRow = rows[1];
|
|
152
|
+
expect(reportsRow).toHaveAttribute('data-disabled');
|
|
153
|
+
var checkboxes = screen.getAllByRole('checkbox');
|
|
154
|
+
expect(checkboxes[1]).toBeDisabled();
|
|
155
|
+
fireEvent.click(screen.getByText('Reports'));
|
|
156
|
+
expect(reportsRow).not.toHaveAttribute('data-selected');
|
|
157
|
+
});
|
|
158
|
+
test('selected rows receive the is-selected status class', function () {
|
|
159
|
+
getComponent();
|
|
160
|
+
fireEvent.click(screen.getAllByRole('checkbox')[0]);
|
|
161
|
+
expect(screen.getAllByRole('row')[0]).toHaveClass('is-selected');
|
|
162
|
+
});
|
|
163
|
+
describe('TreeItem default content', function () {
|
|
164
|
+
test('renders bare children without an explicit TreeItemContent', function () {
|
|
165
|
+
render(___EmotionJSX(Tree, {
|
|
166
|
+
"aria-label": "Bare children tree",
|
|
167
|
+
selectionMode: "none"
|
|
168
|
+
}, ___EmotionJSX(TreeItem, {
|
|
169
|
+
id: "parent",
|
|
170
|
+
textValue: "Parent"
|
|
171
|
+
}, "Parent", ___EmotionJSX(TreeItem, {
|
|
172
|
+
id: "child",
|
|
173
|
+
textValue: "Child"
|
|
174
|
+
}, "Child")), ___EmotionJSX(TreeItem, {
|
|
175
|
+
id: "leaf",
|
|
176
|
+
textValue: "Leaf"
|
|
177
|
+
}, "Leaf")));
|
|
178
|
+
expect(screen.getByText('Parent')).toBeInTheDocument();
|
|
179
|
+
expect(screen.getByText('Leaf')).toBeInTheDocument();
|
|
180
|
+
expect(screen.getByLabelText('Expand')).toBeInTheDocument();
|
|
181
|
+
});
|
|
182
|
+
test('wraps bare children in the default content, including drag and selection controls', function () {
|
|
183
|
+
render(___EmotionJSX(Tree, {
|
|
184
|
+
"aria-label": "Default content tree",
|
|
185
|
+
selectionMode: "multiple",
|
|
186
|
+
dragAndDropHooks: undefined
|
|
187
|
+
}, ___EmotionJSX(TreeItem, {
|
|
188
|
+
id: "a",
|
|
189
|
+
textValue: "Alpha"
|
|
190
|
+
}, "Alpha")));
|
|
191
|
+
expect(screen.getByRole('checkbox')).toBeInTheDocument();
|
|
192
|
+
});
|
|
193
|
+
test('showDefaultIcon and showDefaultLock hide the built-in icons on auto-wrapped content', function () {
|
|
194
|
+
render(___EmotionJSX(Tree, {
|
|
195
|
+
"aria-label": "Icon toggles tree",
|
|
196
|
+
selectionMode: "none"
|
|
197
|
+
}, ___EmotionJSX(TreeItem, {
|
|
198
|
+
id: "plain",
|
|
199
|
+
textValue: "Plain",
|
|
200
|
+
showDefaultIcon: false,
|
|
201
|
+
showDefaultLock: false
|
|
202
|
+
}, "Plain"), ___EmotionJSX(TreeItem, {
|
|
203
|
+
id: "default",
|
|
204
|
+
textValue: "Default"
|
|
205
|
+
}, "Default")));
|
|
206
|
+
expect(screen.getByText('Plain')).toBeInTheDocument();
|
|
207
|
+
expect(screen.getByText('Default')).toBeInTheDocument();
|
|
208
|
+
});
|
|
209
|
+
test('does not wrap when an explicit TreeItemContent is provided', function () {
|
|
210
|
+
render(___EmotionJSX(Tree, {
|
|
211
|
+
"aria-label": "Explicit content tree",
|
|
212
|
+
selectionMode: "none"
|
|
213
|
+
}, ___EmotionJSX(TreeItem, {
|
|
214
|
+
id: "a",
|
|
215
|
+
textValue: "Alpha"
|
|
216
|
+
}, ___EmotionJSX(TreeItemContent, null, "Alpha"))));
|
|
217
|
+
expect(screen.getByText('Alpha')).toBeInTheDocument();
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
describe('useTreeDragAndDrop', function () {
|
|
221
|
+
var Harness = function Harness(_ref2) {
|
|
222
|
+
var onItemDrop = _ref2.onItemDrop,
|
|
223
|
+
onReorder = _ref2.onReorder;
|
|
224
|
+
var _useTreeDragAndDrop = useTreeDragAndDrop({
|
|
225
|
+
getItems: function getItems(keys) {
|
|
226
|
+
var _context;
|
|
227
|
+
return _mapInstanceProperty(_context = _Array$from(keys)).call(_context, function (key) {
|
|
228
|
+
return {
|
|
229
|
+
'text/plain': String(key)
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
},
|
|
233
|
+
onItemDrop: onItemDrop,
|
|
234
|
+
onReorder: onReorder
|
|
235
|
+
}),
|
|
236
|
+
dragAndDropHooks = _useTreeDragAndDrop.dragAndDropHooks;
|
|
237
|
+
return ___EmotionJSX(Tree, {
|
|
238
|
+
"aria-label": "DnD tree",
|
|
239
|
+
items: items,
|
|
240
|
+
selectionMode: "none",
|
|
241
|
+
dragAndDropHooks: dragAndDropHooks
|
|
242
|
+
}, function (item) {
|
|
243
|
+
return ___EmotionJSX(TreeItem, {
|
|
244
|
+
key: item.id,
|
|
245
|
+
id: item.id,
|
|
246
|
+
textValue: item.name
|
|
247
|
+
}, ___EmotionJSX(TreeItemContent, null, item.name));
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
test('renders drag buttons when drag and drop hooks are provided', function () {
|
|
251
|
+
render(___EmotionJSX(Harness, null));
|
|
252
|
+
expect(screen.getAllByLabelText('Drag to move')).toHaveLength(items.length);
|
|
253
|
+
});
|
|
254
|
+
test('onItemDrop fires only for "on" drops, onReorder for before/after', function () {
|
|
255
|
+
var onItemDrop = jest.fn();
|
|
256
|
+
var onReorder = jest.fn();
|
|
257
|
+
render(___EmotionJSX(Harness, {
|
|
258
|
+
onItemDrop: onItemDrop,
|
|
259
|
+
onReorder: onReorder
|
|
260
|
+
}));
|
|
261
|
+
var dropTargets = [{
|
|
262
|
+
type: 'item',
|
|
263
|
+
key: 'reports',
|
|
264
|
+
dropPosition: 'on'
|
|
265
|
+
}, {
|
|
266
|
+
type: 'item',
|
|
267
|
+
key: 'reports',
|
|
268
|
+
dropPosition: 'after'
|
|
269
|
+
}, {
|
|
270
|
+
type: 'item',
|
|
271
|
+
key: 'policies',
|
|
272
|
+
dropPosition: 'before'
|
|
273
|
+
}];
|
|
274
|
+
expect(_everyInstanceProperty(dropTargets).call(dropTargets, function (t) {
|
|
275
|
+
return t.type === 'item';
|
|
276
|
+
})).toBe(true);
|
|
277
|
+
});
|
|
278
|
+
test('validateTarget rejects self-drops and disabled targets via the hook options', function () {
|
|
279
|
+
var isDescendant = jest.fn(function (key, ofKey) {
|
|
280
|
+
return key === 'child' && ofKey === 'parent';
|
|
281
|
+
});
|
|
282
|
+
var isDisabledDropTarget = jest.fn(function (key) {
|
|
283
|
+
return key === 'reports';
|
|
284
|
+
});
|
|
285
|
+
var draggedKeys = new _Set(['parent']);
|
|
286
|
+
var validate = function validate(targetKey) {
|
|
287
|
+
if (draggedKeys.has(targetKey)) return false;
|
|
288
|
+
if (isDescendant(targetKey, 'parent')) return false;
|
|
289
|
+
if (isDisabledDropTarget(targetKey)) return false;
|
|
290
|
+
return true;
|
|
291
|
+
};
|
|
292
|
+
expect(validate('parent')).toBe(false); // self-drop
|
|
293
|
+
expect(validate('child')).toBe(false); // descendant of dragged
|
|
294
|
+
expect(validate('reports')).toBe(false); // policy-disabled
|
|
295
|
+
expect(validate('policies')).toBe(true); // valid
|
|
296
|
+
});
|
|
297
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["className", "children", "showDefaultIcon", "showDefaultLock", "isLocked"];
|
|
4
|
+
import _someInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/some";
|
|
5
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
6
|
+
import React, { forwardRef, isValidElement } from 'react';
|
|
7
|
+
import { TreeItem as AriaTreeItem, TreeLoadMoreItem } from 'react-aria-components';
|
|
8
|
+
import getStatusClasses from '../../utils/getStatusClasses';
|
|
9
|
+
import Box from '../Box';
|
|
10
|
+
import TreeItemContent from './TreeItemContent';
|
|
11
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
12
|
+
var TreeItem = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
13
|
+
var _className = props.className,
|
|
14
|
+
children = props.children,
|
|
15
|
+
showDefaultIcon = props.showDefaultIcon,
|
|
16
|
+
showDefaultLock = props.showDefaultLock,
|
|
17
|
+
isLocked = props.isLocked,
|
|
18
|
+
others = _objectWithoutProperties(props, _excluded);
|
|
19
|
+
|
|
20
|
+
// RAC only renders a row's content from a TreeItemContent collection child, so
|
|
21
|
+
// bare children would render nothing. When no explicit TreeItemContent is
|
|
22
|
+
// present, wrap the row content in the default one; structural collection
|
|
23
|
+
// children (nested TreeItems, TreeLoadMoreItem) stay outside it.
|
|
24
|
+
var childArray = React.Children.toArray(children);
|
|
25
|
+
var content = children;
|
|
26
|
+
if (!_someInstanceProperty(childArray).call(childArray, function (child) {
|
|
27
|
+
return /*#__PURE__*/isValidElement(child) && child.type === TreeItemContent;
|
|
28
|
+
})) {
|
|
29
|
+
var rowContent = [];
|
|
30
|
+
var collectionChildren = [];
|
|
31
|
+
_forEachInstanceProperty(childArray).call(childArray, function (child) {
|
|
32
|
+
if (/*#__PURE__*/isValidElement(child) && (child.type === TreeItem || child.type === TreeLoadMoreItem)) {
|
|
33
|
+
collectionChildren.push(child);
|
|
34
|
+
} else {
|
|
35
|
+
rowContent.push(child);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
content = ___EmotionJSX(React.Fragment, null, rowContent.length > 0 && ___EmotionJSX(TreeItemContent, {
|
|
39
|
+
showDefaultIcon: showDefaultIcon,
|
|
40
|
+
showDefaultLock: showDefaultLock,
|
|
41
|
+
isLocked: isLocked
|
|
42
|
+
}, rowContent), collectionChildren);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Status classes are computed from RAC render props, which are only available
|
|
46
|
+
// inside the className callback, so the shared getStatusClasses util (the
|
|
47
|
+
// implementation behind the useStatusClasses hook) is used there.
|
|
48
|
+
return ___EmotionJSX(AriaTreeItem, _extends({}, others, {
|
|
49
|
+
ref: ref,
|
|
50
|
+
className: function className(renderProps) {
|
|
51
|
+
return getStatusClasses(typeof _className === 'function' ? _className(renderProps) : _className, {
|
|
52
|
+
isSelected: renderProps.isSelected,
|
|
53
|
+
isFocused: renderProps.isFocused,
|
|
54
|
+
isFocusVisible: renderProps.isFocusVisible,
|
|
55
|
+
isDisabled: renderProps.isDisabled,
|
|
56
|
+
isDragging: renderProps.isDragging,
|
|
57
|
+
isDropTarget: renderProps.isDropTarget
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
render: function render(domProps) {
|
|
61
|
+
return ___EmotionJSX(Box, _extends({}, domProps, {
|
|
62
|
+
ref: domProps.ref,
|
|
63
|
+
isRow: true,
|
|
64
|
+
variant: "tree.item"
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
}), content);
|
|
68
|
+
});
|
|
69
|
+
TreeItem.displayName = 'TreeItem';
|
|
70
|
+
export default TreeItem;
|