@pingux/astro 2.27.0 → 2.27.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/TreeView/TreeView.js +44 -12
- package/lib/cjs/components/TreeView/TreeView.stories.js +9 -10
- package/lib/cjs/components/TreeView/TreeView.test.js +82 -39
- package/lib/cjs/components/TreeView/TreeViewItem.js +17 -18
- package/lib/cjs/components/TreeView/TreeViewSection.js +19 -13
- package/lib/cjs/recipes/TrialExperienceStatusBar.stories.js +66 -95
- package/lib/cjs/utils/designUtils/figmaLinks.js +3 -0
- package/lib/components/TreeView/TreeView.js +44 -13
- package/lib/components/TreeView/TreeView.stories.js +8 -9
- package/lib/components/TreeView/TreeView.test.js +83 -40
- package/lib/components/TreeView/TreeViewItem.js +17 -18
- package/lib/components/TreeView/TreeViewSection.js +19 -13
- package/lib/recipes/TrialExperienceStatusBar.stories.js +64 -94
- package/lib/utils/designUtils/figmaLinks.js +3 -0
- package/package.json +1 -1
@@ -1,35 +1,24 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _typeof = require("@babel/runtime-corejs3/helpers/typeof");
|
4
|
-
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
5
|
-
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
6
|
-
var _filterInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
7
|
-
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
8
|
-
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
9
|
-
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
10
|
-
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
11
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
12
4
|
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
13
7
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
14
8
|
_Object$defineProperty(exports, "__esModule", {
|
15
9
|
value: true
|
16
10
|
});
|
17
11
|
exports["default"] = exports.Default = void 0;
|
18
|
-
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
19
|
-
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
20
|
-
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
21
12
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
22
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
23
13
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
24
14
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
25
15
|
var _react = _interopRequireWildcard(require("react"));
|
26
16
|
var _CheckCircleIcon = _interopRequireDefault(require("@pingux/mdi-react/CheckCircleIcon"));
|
27
17
|
var _index = require("../index");
|
18
|
+
var _figmaLinks = require("../utils/designUtils/figmaLinks.js");
|
28
19
|
var _react2 = require("@emotion/react");
|
29
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
30
21
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
31
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty2(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
33
22
|
var _default = {
|
34
23
|
title: 'Recipes/Trial Experience Nav'
|
35
24
|
};
|
@@ -79,36 +68,53 @@ var EarthCircleIcon = function EarthCircleIcon() {
|
|
79
68
|
};
|
80
69
|
var RadioButtonIcon = function RadioButtonIcon(props) {
|
81
70
|
return (0, _react2.jsx)("svg", (0, _extends2["default"])({
|
82
|
-
|
71
|
+
viewBox: "0 0 22 22",
|
72
|
+
fill: "none",
|
83
73
|
xmlns: "http://www.w3.org/2000/svg",
|
84
|
-
viewBox: "0 0 17.5 17.5",
|
85
74
|
"aria-labelledby": "radio-button-icon-title"
|
86
75
|
}, props), (0, _react2.jsx)("title", {
|
87
76
|
id: "radio-button-icon-title"
|
88
77
|
}, "Radio Button Icon"), (0, _react2.jsx)("path", {
|
89
|
-
|
90
|
-
fill: "#B3BEE8"
|
91
|
-
d: "M9,18.25A8.75,8.75,0,1,1,17.75,9.5,8.76,8.76,0,0,1,9,18.25ZM9,1.75A7.75,7.75,0,1,0,16.75,9.5,7.76,7.76,0,0,0,9,1.75Z",
|
92
|
-
transform: "translate(-0.25 -0.75)"
|
78
|
+
d: "M11 18.3333C9.05508 18.3333 7.18982 17.5607 5.81455 16.1854C4.43928 14.8102 3.66667 12.9449 3.66667 11C3.66667 9.05507 4.43928 7.18981 5.81455 5.81455C7.18982 4.43928 9.05508 3.66666 11 3.66666C12.9449 3.66666 14.8102 4.43928 16.1854 5.81455C17.5607 7.18981 18.3333 9.05507 18.3333 11C18.3333 12.9449 17.5607 14.8102 16.1854 16.1854C14.8102 17.5607 12.9449 18.3333 11 18.3333ZM11 1.83333C9.79621 1.83333 8.60422 2.07043 7.49207 2.5311C6.37992 2.99177 5.36939 3.66698 4.51819 4.51818C2.7991 6.23727 1.83333 8.56884 1.83333 11C1.83333 13.4311 2.7991 15.7627 4.51819 17.4818C5.36939 18.333 6.37992 19.0082 7.49207 19.4689C8.60422 19.9296 9.79621 20.1667 11 20.1667C13.4311 20.1667 15.7627 19.2009 17.4818 17.4818C19.2009 15.7627 20.1667 13.4311 20.1667 11C20.1667 9.79621 19.9296 8.60421 19.4689 7.49206C19.0082 6.37991 18.333 5.36939 17.4818 4.51818C16.6306 3.66698 15.6201 2.99177 14.5079 2.5311C13.3958 2.07043 12.2038 1.83333 11 1.83333Z",
|
79
|
+
fill: "#B3BEE8"
|
93
80
|
}), (0, _react2.jsx)("circle", {
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
r: "8.05",
|
81
|
+
cx: "11",
|
82
|
+
cy: "11",
|
83
|
+
r: "8",
|
98
84
|
fill: "white"
|
99
85
|
}));
|
100
86
|
};
|
87
|
+
var IntegrateYourAppIcon = function IntegrateYourAppIcon(props) {
|
88
|
+
return (0, _react2.jsx)("svg", (0, _extends2["default"])({
|
89
|
+
width: "24",
|
90
|
+
height: "24",
|
91
|
+
viewBox: "0 0 24 24",
|
92
|
+
fill: "none",
|
93
|
+
xmlns: "http://www.w3.org/2000/svg",
|
94
|
+
"aria-labelledby": "integrate-your-app-icon-title"
|
95
|
+
}, props), (0, _react2.jsx)("title", {
|
96
|
+
id: "integrate-your-app-icon-title"
|
97
|
+
}, "Integrate Your App Icon"), (0, _react2.jsx)("path", {
|
98
|
+
d: "M2 5H5V8H2V5ZM8.98124 9.18922C8.40906 8.51487 7.5878 8 6 8V5C8.4122 5 10.0909 5.86013 11.2688 7.24828C12.3198 8.48703 12.8987 10.0806 13.3691 11.3758L13.4097 11.4874C13.9318 12.9231 14.3502 14.0229 15.0188 14.8108C15.5909 15.4851 16.4122 16 18 16V19H6V16H11.0563C10.9745 15.8905 10.8976 15.7846 10.8245 15.6841L10.7869 15.6323C10.2778 14.9323 9.93844 14.4905 9.36346 14.1517C8.79448 13.8164 7.83564 13.5 6 13.5V10.5C7.7039 10.5 9.02155 10.73 10.0813 11.1674C9.7558 10.3671 9.42315 9.71004 8.98124 9.18922ZM5 10.5H2V13.5H5V10.5ZM2 16H5V19H2V16ZM22 16H19V19H22V16Z",
|
99
|
+
fill: "#FF8324"
|
100
|
+
}));
|
101
|
+
};
|
101
102
|
var data = [{
|
102
103
|
title: 'Design a Solution',
|
103
104
|
icon: ArtIcon,
|
104
105
|
iconTitle: 'Art Icon',
|
105
106
|
key: 0,
|
106
107
|
links: [{
|
108
|
+
isLinkSelected: true,
|
107
109
|
title: 'Registration'
|
108
110
|
}, {
|
111
|
+
isLinkSelected: true,
|
109
112
|
title: 'Authentication'
|
110
113
|
}, {
|
114
|
+
isLinkSelected: true,
|
111
115
|
title: 'Profile management'
|
116
|
+
}, {
|
117
|
+
title: 'Account recovery'
|
112
118
|
}, {
|
113
119
|
title: 'Experience your solution'
|
114
120
|
}]
|
@@ -132,6 +138,9 @@ var data = [{
|
|
132
138
|
iconTitle: 'Earth Circle Icon',
|
133
139
|
key: 2,
|
134
140
|
links: [{
|
141
|
+
customIcon: IntegrateYourAppIcon,
|
142
|
+
title: 'Integrate your app'
|
143
|
+
}, {
|
135
144
|
title: 'Learn about DaVinci'
|
136
145
|
}, {
|
137
146
|
title: 'View a workflow'
|
@@ -144,7 +153,11 @@ var sx = {
|
|
144
153
|
justifyContent: 'center',
|
145
154
|
mr: 'sm',
|
146
155
|
borderRadius: '50%',
|
147
|
-
zIndex: 3
|
156
|
+
zIndex: 3,
|
157
|
+
'& > svg ': {
|
158
|
+
width: '28px',
|
159
|
+
height: '28px'
|
160
|
+
}
|
148
161
|
},
|
149
162
|
headingSeparator: {
|
150
163
|
flexGrow: 1,
|
@@ -159,7 +172,7 @@ var sx = {
|
|
159
172
|
color: 'accent.30',
|
160
173
|
lineHeight: '18px',
|
161
174
|
fontWeight: '3',
|
162
|
-
m: '12px 0px 28px
|
175
|
+
m: '12px 0px 28px 0px',
|
163
176
|
maxWidth: '195px'
|
164
177
|
},
|
165
178
|
linkRowIconButton: {
|
@@ -187,19 +200,12 @@ var sx = {
|
|
187
200
|
fill: 'accent.80'
|
188
201
|
}
|
189
202
|
},
|
190
|
-
linkRowSeparator: {
|
191
|
-
flexGrow: 1,
|
192
|
-
backgroundColor: 'accent.30',
|
193
|
-
width: '1px !important',
|
194
|
-
zIndex: 2,
|
195
|
-
m: '-4px 5px -5px 11.5px !important'
|
196
|
-
},
|
197
203
|
linkRowText: {
|
198
204
|
fontSize: 'md',
|
199
205
|
color: '#163CE3',
|
200
206
|
lineHeight: '18px',
|
201
207
|
fontWeight: '0',
|
202
|
-
m: '3px 0px
|
208
|
+
m: '3px 0px 15px 10px',
|
203
209
|
maxWidth: '140px'
|
204
210
|
},
|
205
211
|
container: {
|
@@ -217,26 +223,11 @@ var Stage = function Stage(_ref) {
|
|
217
223
|
iconTitle = _ref.iconTitle,
|
218
224
|
links = _ref.links,
|
219
225
|
isLastStage = _ref.isLastStage;
|
220
|
-
var _useState = (0, _react.useState)([]),
|
221
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
222
|
-
selectedLinks = _useState2[0],
|
223
|
-
updateSelectedLinks = _useState2[1];
|
224
|
-
var onSelectionChange = function onSelectionChange(thisIndex) {
|
225
|
-
var _context2;
|
226
|
-
var newArray = [];
|
227
|
-
if ((0, _includes["default"])(selectedLinks).call(selectedLinks, thisIndex)) {
|
228
|
-
newArray = (0, _filter["default"])(selectedLinks).call(selectedLinks, function (link) {
|
229
|
-
return link !== thisIndex;
|
230
|
-
});
|
231
|
-
} else {
|
232
|
-
var _context;
|
233
|
-
newArray = (0, _concat["default"])(_context = []).call(_context, selectedLinks, [thisIndex]);
|
234
|
-
}
|
235
|
-
updateSelectedLinks((0, _concat["default"])(_context2 = []).call(_context2, newArray));
|
236
|
-
};
|
237
226
|
return (0, _react2.jsx)(_index.Box, {
|
238
227
|
isRow: true
|
239
|
-
}, (0, _react2.jsx)(_index.Box,
|
228
|
+
}, (0, _react2.jsx)(_index.Box, {
|
229
|
+
mr: "xs"
|
230
|
+
}, (0, _react2.jsx)(_index.Box, {
|
240
231
|
minWidth: "39.5px",
|
241
232
|
minHeight: "39.5px",
|
242
233
|
sx: sx.iconContainer
|
@@ -246,7 +237,7 @@ var Stage = function Stage(_ref) {
|
|
246
237
|
name: iconTitle
|
247
238
|
},
|
248
239
|
color: "accent.40",
|
249
|
-
size: "
|
240
|
+
size: "15px",
|
250
241
|
sx: {
|
251
242
|
zIndex: 3
|
252
243
|
}
|
@@ -258,66 +249,40 @@ var Stage = function Stage(_ref) {
|
|
258
249
|
}, title), (0, _react2.jsx)(_index.Box, {
|
259
250
|
pl: "0px",
|
260
251
|
mb: "25px"
|
261
|
-
}, (0, _map["default"])(links).call(links, function (link
|
252
|
+
}, (0, _map["default"])(links).call(links, function (link) {
|
262
253
|
return (0, _react2.jsx)(LinkRow, (0, _extends2["default"])({}, link, {
|
263
|
-
onSelectionChange: onSelectionChange,
|
264
|
-
index: index,
|
265
|
-
isLinkSelected: selectedLinks.length !== 0,
|
266
|
-
isLastLink: index === links.length - 1,
|
267
254
|
key: link.title
|
268
255
|
}));
|
269
256
|
}))));
|
270
257
|
};
|
271
258
|
var LinkRow = function LinkRow(_ref2) {
|
272
|
-
var
|
273
|
-
isLastLink = _ref2.isLastLink,
|
259
|
+
var title = _ref2.title,
|
274
260
|
isLinkSelected = _ref2.isLinkSelected,
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
handleSelectionChange = _useState4[1];
|
281
|
-
var _useState5 = (0, _react.useState)(0),
|
282
|
-
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
283
|
-
verticalSeparatorHeight = _useState6[0],
|
284
|
-
setVerticalSeparatorHeight = _useState6[1];
|
285
|
-
var iconRef = (0, _react.useRef)();
|
286
|
-
var rowRef = (0, _react.useRef)();
|
287
|
-
(0, _react.useEffect)(function () {
|
288
|
-
var _rowRef$current$getBo = rowRef.current.getBoundingClientRect(),
|
289
|
-
height = _rowRef$current$getBo.height;
|
290
|
-
var _iconRef$current$getB = iconRef.current.getBoundingClientRect(),
|
291
|
-
iconRefHeight = _iconRef$current$getB.height;
|
292
|
-
var marginAccommodation = 4;
|
293
|
-
var halfIconHeight = iconRefHeight / 2;
|
294
|
-
setVerticalSeparatorHeight(height - halfIconHeight - marginAccommodation);
|
295
|
-
}, [iconRef, rowRef]);
|
261
|
+
customIcon = _ref2.customIcon;
|
262
|
+
var _useState = (0, _react.useState)(isLinkSelected),
|
263
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
264
|
+
isSelected = _useState2[0],
|
265
|
+
handleSelectionChange = _useState2[1];
|
296
266
|
var onIconPress = function onIconPress() {
|
297
267
|
handleSelectionChange(!isSelected);
|
298
|
-
onSelectionChange(index);
|
299
268
|
};
|
300
269
|
return (0, _react2.jsx)(_index.Box, {
|
301
|
-
isRow: true
|
302
|
-
|
303
|
-
|
270
|
+
isRow: true
|
271
|
+
}, (0, _react2.jsx)(_index.Box, null, customIcon ? (0, _react2.jsx)(_index.Icon, {
|
272
|
+
icon: customIcon,
|
273
|
+
size: "22px"
|
274
|
+
}) : (0, _react2.jsx)(_index.IconButton, {
|
304
275
|
"aria-label": "completed step icon indicator",
|
305
276
|
onPress: onIconPress,
|
306
|
-
ref: iconRef,
|
307
277
|
sx: sx.linkRowIconButton
|
308
278
|
}, (0, _react2.jsx)(_index.Icon, {
|
309
279
|
icon: isSelected ? _CheckCircleIcon["default"] : RadioButtonIcon,
|
310
|
-
size: "
|
311
|
-
sx: isSelected ? sx.
|
280
|
+
size: "22px",
|
281
|
+
sx: isSelected ? sx.linkRowIconSelected : sx.linkRowIconNotSelected,
|
312
282
|
title: {
|
313
283
|
name: 'Check Circle Icon'
|
314
284
|
}
|
315
|
-
})),
|
316
|
-
orientation: "vertical",
|
317
|
-
sx: _objectSpread(_objectSpread({}, sx.linkRowSeparator), {}, {
|
318
|
-
maxHeight: verticalSeparatorHeight
|
319
|
-
})
|
320
|
-
})), (0, _react2.jsx)(_index.Link, {
|
285
|
+
}))), (0, _react2.jsx)(_index.Link, {
|
321
286
|
href: "https://www.pingidentity.com",
|
322
287
|
sx: sx.linkRowText,
|
323
288
|
target: "_blank"
|
@@ -341,4 +306,10 @@ var Default = function Default() {
|
|
341
306
|
});
|
342
307
|
})));
|
343
308
|
};
|
344
|
-
exports.Default = Default;
|
309
|
+
exports.Default = Default;
|
310
|
+
Default.parameters = {
|
311
|
+
design: {
|
312
|
+
type: 'figma',
|
313
|
+
url: _figmaLinks.FIGMA_LINKS.trialExperienceNav["default"]
|
314
|
+
}
|
315
|
+
};
|
@@ -121,6 +121,9 @@ var FIGMA_LINKS = {
|
|
121
121
|
slider: {
|
122
122
|
"default": 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?node-id=43112%3A1773&mode=dev'
|
123
123
|
},
|
124
|
+
trialExperienceNav: {
|
125
|
+
"default": 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?node-id=43368%3A159&mode=dev'
|
126
|
+
},
|
124
127
|
trialExperienceButtons: {
|
125
128
|
"default": 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?node-id=43369%3A445'
|
126
129
|
},
|
@@ -9,13 +9,16 @@ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object
|
|
9
9
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
10
10
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
var _excluded = ["tree", "onExpandedChange"];
|
12
|
+
var _excluded = ["tree", "disabledKeys", "onExpandedChange"];
|
13
13
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
14
14
|
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
15
15
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
16
16
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
17
|
-
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
|
17
|
+
import React, { forwardRef, useImperativeHandle, useMemo, useRef } from 'react';
|
18
18
|
import { useTreeState } from 'react-stately';
|
19
|
+
import { useCollator } from '@react-aria/i18n';
|
20
|
+
import { useListBox } from '@react-aria/listbox';
|
21
|
+
import { ListLayout } from '@react-stately/layout';
|
19
22
|
import PropTypes from 'prop-types';
|
20
23
|
import { TreeViewContext } from '../../context/TreeViewContext';
|
21
24
|
import { Box, TreeViewItem, TreeViewSection } from '../../index';
|
@@ -30,35 +33,64 @@ export var SectionOrItemRender = function SectionOrItemRender(condition, Section
|
|
30
33
|
}
|
31
34
|
return ItemComponent;
|
32
35
|
};
|
36
|
+
export function useTreeViewLayout(state) {
|
37
|
+
var collator = useCollator({
|
38
|
+
usage: 'search',
|
39
|
+
sensitivity: 'base'
|
40
|
+
});
|
41
|
+
var layout = useMemo(function () {
|
42
|
+
return new ListLayout();
|
43
|
+
}, [collator]);
|
44
|
+
layout.collection = state.collection;
|
45
|
+
layout.disabledKeys = state.disabledKeys;
|
46
|
+
return layout;
|
47
|
+
}
|
33
48
|
var TreeView = /*#__PURE__*/forwardRef(function (props, ref) {
|
34
|
-
var
|
49
|
+
var _context;
|
35
50
|
var tree = props.tree,
|
51
|
+
disabledKeys = props.disabledKeys,
|
36
52
|
onExpandedChange = props.onExpandedChange,
|
37
53
|
others = _objectWithoutProperties(props, _excluded);
|
38
|
-
var labelRef = useRef();
|
39
54
|
var treeViewRef = useRef();
|
55
|
+
var selectedKeys = tree.selectedKeys;
|
56
|
+
|
40
57
|
/* istanbul ignore next */
|
41
58
|
useImperativeHandle(ref, function () {
|
42
59
|
return treeViewRef.current;
|
43
60
|
});
|
44
61
|
var state = useTreeState(_objectSpread({
|
45
|
-
onExpandedChange: onExpandedChange
|
62
|
+
onExpandedChange: onExpandedChange,
|
63
|
+
disabledKeys: disabledKeys,
|
64
|
+
selectedKeys: selectedKeys,
|
65
|
+
selectionMode: 'single',
|
66
|
+
disallowEmptySelection: true
|
46
67
|
}, others));
|
68
|
+
var ariaLabel = props['aria-label'];
|
69
|
+
var listBoxOptions = {
|
70
|
+
disabledKeys: disabledKeys,
|
71
|
+
'aria-label': ariaLabel
|
72
|
+
};
|
73
|
+
var layout = useTreeViewLayout(state);
|
74
|
+
var _useListBox = useListBox(_objectSpread(_objectSpread({}, listBoxOptions), {}, {
|
75
|
+
keyboardDelegate: layout
|
76
|
+
}), state, treeViewRef),
|
77
|
+
listBoxProps = _useListBox.listBoxProps;
|
47
78
|
return ___EmotionJSX(TreeViewContext.Provider, {
|
48
79
|
value: {
|
49
80
|
state: state,
|
50
81
|
tree: tree
|
51
82
|
}
|
52
83
|
}, ___EmotionJSX(Box, _extends({
|
53
|
-
as: "ul"
|
54
|
-
|
84
|
+
as: "ul"
|
85
|
+
}, listBoxProps, {
|
55
86
|
ref: treeViewRef,
|
56
|
-
"aria-
|
87
|
+
"aria-label": ariaLabel,
|
88
|
+
role: "treegrid",
|
57
89
|
sx: {
|
58
90
|
overflow: 'hidden'
|
59
91
|
}
|
60
92
|
}, others), _mapInstanceProperty(_context = _Array$from(state.collection)).call(_context, function (item) {
|
61
|
-
return SectionOrItemRender(item.
|
93
|
+
return SectionOrItemRender(item.props.items.length > 0, ___EmotionJSX(TreeViewSection, {
|
62
94
|
item: item,
|
63
95
|
items: item.props.items,
|
64
96
|
title: item.props.title,
|
@@ -70,13 +102,12 @@ var TreeView = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
70
102
|
}));
|
71
103
|
})));
|
72
104
|
});
|
73
|
-
TreeView.defaultProps = {
|
74
|
-
'aria-label': 'tree'
|
75
|
-
};
|
76
105
|
TreeView.propTypes = {
|
77
106
|
/** data object prop that is required to make the tree function
|
78
107
|
this is returned from the useTreeData hook in React-Aria */
|
79
|
-
tree: PropTypes.shape({
|
108
|
+
tree: PropTypes.shape({
|
109
|
+
selectedKeys: isIterableProp
|
110
|
+
}).isRequired,
|
80
111
|
/** The currently disabled keys in the collection. */
|
81
112
|
disabledKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object])),
|
82
113
|
/** Callback function that is called when items are expanded or collapsed. */
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
2
|
import React from 'react';
|
3
3
|
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
4
|
-
import { Item,
|
5
|
-
import { SectionOrItemRender } from './TreeView';
|
4
|
+
import { Item, TreeView, useTreeData } from '../../index';
|
6
5
|
import TreeViewReadMe from './TreeView.mdx';
|
7
6
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
8
7
|
export default {
|
@@ -65,15 +64,15 @@ export var Default = function Default(args) {
|
|
65
64
|
});
|
66
65
|
return ___EmotionJSX(TreeView, _extends({}, args, {
|
67
66
|
items: tree.items,
|
68
|
-
tree: tree
|
67
|
+
tree: tree,
|
68
|
+
"aria-label": "Example Tree",
|
69
|
+
disabledKeys: ['Single Item']
|
69
70
|
}), function (section) {
|
70
|
-
|
71
|
+
var _section$value;
|
72
|
+
return ___EmotionJSX(Item, {
|
71
73
|
key: section.key,
|
72
74
|
items: section.children,
|
73
|
-
title: section.value.title
|
74
|
-
})
|
75
|
-
key: section.key,
|
76
|
-
title: section.title
|
77
|
-
}));
|
75
|
+
title: (_section$value = section.value) === null || _section$value === void 0 ? void 0 : _section$value.title
|
76
|
+
});
|
78
77
|
});
|
79
78
|
};
|
@@ -1,41 +1,44 @@
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
2
|
import React from 'react';
|
3
3
|
import { useTreeData } from 'react-stately';
|
4
|
-
import { Item
|
4
|
+
import { Item } from '../../index';
|
5
5
|
import { fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
|
6
6
|
import { SectionOrItemRender } from './TreeView';
|
7
7
|
import TreeView from '.';
|
8
8
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
9
9
|
var testId = 'test-TreeView';
|
10
10
|
var defaultProps = {
|
11
|
-
'data-testid': testId
|
11
|
+
'data-testid': testId,
|
12
|
+
label: 'example tree'
|
12
13
|
};
|
13
14
|
var data = [{
|
14
|
-
title: '
|
15
|
+
title: 'Policies',
|
15
16
|
items: [{
|
16
|
-
title: '
|
17
|
-
customProp: 1
|
18
|
-
}, {
|
19
|
-
title: 'Sam'
|
20
|
-
}, {
|
21
|
-
title: 'Jane'
|
22
|
-
}]
|
23
|
-
}, {
|
24
|
-
title: 'Animals',
|
25
|
-
items: [{
|
26
|
-
title: 'Bears',
|
17
|
+
title: 'Registration',
|
27
18
|
items: [{
|
28
|
-
title: '
|
19
|
+
title: 'Registration A'
|
20
|
+
}, {
|
21
|
+
title: 'Registration B'
|
22
|
+
}, {
|
23
|
+
title: 'Registration C'
|
29
24
|
}, {
|
30
|
-
title: '
|
25
|
+
title: 'Registration D'
|
31
26
|
}]
|
32
27
|
}, {
|
33
|
-
title: '
|
34
|
-
|
35
|
-
|
28
|
+
title: 'Authentication',
|
29
|
+
items: [{
|
30
|
+
title: 'Authentication A'
|
31
|
+
}, {
|
32
|
+
title: 'Authentication B'
|
33
|
+
}]
|
34
|
+
}]
|
35
|
+
}, {
|
36
|
+
title: 'Other',
|
37
|
+
items: [{
|
38
|
+
title: 'Other A'
|
36
39
|
}]
|
37
40
|
}, {
|
38
|
-
title: '
|
41
|
+
title: 'Single Item'
|
39
42
|
}];
|
40
43
|
var TreeViewComponent = function TreeViewComponent(props) {
|
41
44
|
var tree = useTreeData({
|
@@ -49,36 +52,62 @@ var TreeViewComponent = function TreeViewComponent(props) {
|
|
49
52
|
});
|
50
53
|
return ___EmotionJSX(TreeView, _extends({}, defaultProps, props, {
|
51
54
|
items: tree.items,
|
52
|
-
tree: tree
|
53
|
-
|
54
|
-
|
55
|
-
return
|
56
|
-
key:
|
57
|
-
items:
|
58
|
-
title:
|
59
|
-
|
60
|
-
testp: 1
|
61
|
-
}
|
62
|
-
}), ___EmotionJSX(Item, {
|
63
|
-
key: section.key,
|
64
|
-
title: section.key
|
65
|
-
}));
|
55
|
+
tree: tree,
|
56
|
+
"aria-label": "Example Tree"
|
57
|
+
}), function (item) {
|
58
|
+
return ___EmotionJSX(Item, {
|
59
|
+
key: item.key,
|
60
|
+
items: item.children,
|
61
|
+
title: item.key
|
62
|
+
});
|
66
63
|
});
|
67
64
|
};
|
65
|
+
var offsetWidth;
|
66
|
+
var offsetHeight;
|
67
|
+
var scrollHeight;
|
68
|
+
var onSelectionChange = jest.fn();
|
69
|
+
beforeAll(function () {
|
70
|
+
offsetWidth = jest.spyOn(window.HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(function () {
|
71
|
+
return 1000;
|
72
|
+
});
|
73
|
+
offsetHeight = jest.spyOn(window.HTMLElement.prototype, 'clientHeight', 'get').mockImplementation(function () {
|
74
|
+
return 1000;
|
75
|
+
});
|
76
|
+
scrollHeight = jest.spyOn(window.HTMLElement.prototype, 'scrollHeight', 'get').mockImplementation(function () {
|
77
|
+
return 48;
|
78
|
+
});
|
79
|
+
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(function (cb) {
|
80
|
+
return cb();
|
81
|
+
});
|
82
|
+
jest.useFakeTimers();
|
83
|
+
});
|
84
|
+
afterEach(function () {
|
85
|
+
onSelectionChange.mockClear();
|
86
|
+
});
|
87
|
+
afterAll(function () {
|
88
|
+
offsetWidth.mockReset();
|
89
|
+
offsetHeight.mockReset();
|
90
|
+
scrollHeight.mockReset();
|
91
|
+
});
|
92
|
+
test('TreeView component does load', function () {
|
93
|
+
render(___EmotionJSX(TreeViewComponent, null));
|
94
|
+
var element = screen.queryByRole('treegrid');
|
95
|
+
expect(element).toBeInTheDocument();
|
96
|
+
});
|
68
97
|
test('Can select an Item using the mouse', function () {
|
69
98
|
render(___EmotionJSX(TreeViewComponent, null));
|
70
|
-
var element = screen.
|
99
|
+
var element = screen.queryByRole('treegrid');
|
71
100
|
expect(element).toBeInTheDocument();
|
72
|
-
var peopleElement = screen.
|
101
|
+
var peopleElement = screen.queryByText('Single Item');
|
73
102
|
expect(peopleElement).not.toHaveClass('is-selected');
|
74
103
|
fireEvent.click(peopleElement);
|
75
104
|
expect(peopleElement).toHaveClass('is-selected');
|
76
105
|
});
|
77
106
|
test('Renders both Sections and Items', function () {
|
78
107
|
render(___EmotionJSX(TreeViewComponent, null));
|
79
|
-
var peopleElement = screen.getByText('
|
108
|
+
var peopleElement = screen.getByText('Single Item');
|
80
109
|
expect(peopleElement).toBeInTheDocument();
|
81
|
-
var plantElement = screen.getByText('
|
110
|
+
var plantElement = screen.getByText('Other');
|
82
111
|
expect(plantElement).toBeInTheDocument();
|
83
112
|
var allListItems = screen.getAllByRole('treeitem');
|
84
113
|
expect(allListItems).toHaveLength(3);
|
@@ -108,9 +137,9 @@ test('onExpandedChange change prop calls when used', function () {
|
|
108
137
|
});
|
109
138
|
test('disabledKeys prop disables items in the tree -- rendering them unclickable', function () {
|
110
139
|
render(___EmotionJSX(TreeViewComponent, {
|
111
|
-
disabledKeys: ['
|
140
|
+
disabledKeys: ['Single Item']
|
112
141
|
}));
|
113
|
-
var listItems = screen.
|
142
|
+
var listItems = screen.queryAllByRole('treeitem');
|
114
143
|
var thisItem = listItems[2];
|
115
144
|
expect(thisItem).not.toHaveClass('is-selected');
|
116
145
|
expect(thisItem).toHaveAttribute('aria-disabled', 'true');
|
@@ -118,4 +147,18 @@ test('disabledKeys prop disables items in the tree -- rendering them unclickable
|
|
118
147
|
fireEvent.mouseUp(thisItem);
|
119
148
|
expect(thisItem).not.toHaveClass('is-selected');
|
120
149
|
expect(thisItem).toHaveAttribute('aria-selected', 'false');
|
150
|
+
});
|
151
|
+
var firstJSX = ___EmotionJSX("p", null, "first");
|
152
|
+
var secondJSX = ___EmotionJSX("p", null, "second");
|
153
|
+
test('Section or Item Render renders first item if condition is true', function () {
|
154
|
+
render(___EmotionJSX("div", null, SectionOrItemRender(true, firstJSX, secondJSX)));
|
155
|
+
var thisItem = screen.getByText('first');
|
156
|
+
expect(thisItem).toBeInTheDocument();
|
157
|
+
expect(screen.queryByText('second')).not.toBeInTheDocument();
|
158
|
+
});
|
159
|
+
test('Section or Item Render renders second item if condition is false', function () {
|
160
|
+
render(___EmotionJSX("div", null, SectionOrItemRender(false, firstJSX, secondJSX)));
|
161
|
+
var thisItem = screen.getByText('second');
|
162
|
+
expect(thisItem).toBeInTheDocument();
|
163
|
+
expect(screen.queryByText('first')).not.toBeInTheDocument();
|
121
164
|
});
|