@pingux/astro 1.1.1-alpha.5 → 1.2.0-alpha.3
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/Breadcrumbs/BreadcrumbItem.js +3 -0
- package/lib/cjs/components/Breadcrumbs/Breadcrumbs.js +24 -14
- package/lib/cjs/components/Breadcrumbs/Breadcrumbs.test.js +9 -0
- package/lib/cjs/components/CopyText/CopyButton.js +9 -2
- package/lib/cjs/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.js +338 -0
- package/lib/cjs/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.stories.js +295 -0
- package/lib/cjs/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.test.js +287 -0
- package/lib/cjs/components/EnvironmentBreadcrumb/index.js +18 -0
- package/lib/cjs/components/Messages/Messages.reducer.js +2 -1
- package/lib/cjs/components/Messages/Messages.stories.js +10 -10
- package/lib/cjs/components/Messages/Messages.test.js +15 -1
- package/lib/cjs/components/Messages/index.js +21 -2
- package/lib/cjs/components/TextField/TextField.stories.js +79 -2
- package/lib/cjs/index.js +10 -0
- package/lib/cjs/styles/variants/boxes.js +13 -0
- package/lib/cjs/styles/variants/buttons.js +23 -0
- package/lib/cjs/styles/variants/text.js +9 -0
- package/lib/cjs/utils/devUtils/constants/animals.js +11 -0
- package/lib/cjs/utils/devUtils/constants/firstNames.js +11 -0
- package/lib/cjs/utils/devUtils/createMockData.js +96 -0
- package/lib/components/Breadcrumbs/BreadcrumbItem.js +4 -1
- package/lib/components/Breadcrumbs/Breadcrumbs.js +24 -15
- package/lib/components/Breadcrumbs/Breadcrumbs.test.js +9 -0
- package/lib/components/CopyText/CopyButton.js +7 -2
- package/lib/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.js +296 -0
- package/lib/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.stories.js +256 -0
- package/lib/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.test.js +246 -0
- package/lib/components/EnvironmentBreadcrumb/index.js +1 -0
- package/lib/components/Messages/Messages.reducer.js +1 -1
- package/lib/components/Messages/Messages.stories.js +1 -1
- package/lib/components/Messages/Messages.test.js +11 -1
- package/lib/components/Messages/index.js +2 -1
- package/lib/components/TextField/TextField.stories.js +72 -0
- package/lib/index.js +1 -0
- package/lib/styles/variants/boxes.js +13 -0
- package/lib/styles/variants/buttons.js +23 -0
- package/lib/styles/variants/text.js +9 -0
- package/lib/utils/devUtils/constants/animals.js +1 -0
- package/lib/utils/devUtils/constants/firstNames.js +1 -0
- package/lib/utils/devUtils/createMockData.js +68 -0
- package/package.json +1 -1
@@ -0,0 +1,296 @@
|
|
1
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
2
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
3
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
4
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
5
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
6
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
7
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
8
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
9
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
10
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
11
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
12
|
+
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
13
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
14
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
15
|
+
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
17
|
+
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context2; _forEachInstanceProperty(_context2 = ownKeys(Object(source), true)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
19
|
+
|
20
|
+
import React, { forwardRef, useCallback, useImperativeHandle, useRef, useState } from 'react';
|
21
|
+
import { useFilter } from '@react-aria/i18n';
|
22
|
+
import ChevronRightIcon from 'mdi-react/ChevronRightIcon';
|
23
|
+
import HomeIcon from 'mdi-react/HomeIcon';
|
24
|
+
import PropTypes from 'prop-types';
|
25
|
+
import { useOverlayTriggerState } from '@react-stately/overlays';
|
26
|
+
import { useOverlayPosition, useOverlayTrigger } from '@react-aria/overlays';
|
27
|
+
import ArrowDropUpIcon from 'mdi-react/ArrowDropUpIcon';
|
28
|
+
import ArrowDropDownIcon from 'mdi-react/ArrowDropDownIcon';
|
29
|
+
import { FocusScope } from '@react-aria/focus';
|
30
|
+
import { useListState } from '@react-stately/list';
|
31
|
+
import ListBox from '../ListBox';
|
32
|
+
import { isIterableProp } from '../../utils/devUtils/props/isIterable';
|
33
|
+
import { Breadcrumbs, Button, Icon, Item, PopoverContainer, ScrollBox, SearchField, Text } from '../../index';
|
34
|
+
/** The Environment Picker with Search and Sections support */
|
35
|
+
|
36
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
37
|
+
var EnvironmentBreadcrumb = /*#__PURE__*/forwardRef(function (props, ref) {
|
38
|
+
var children = props.children,
|
39
|
+
imperativeDisabledKeys = props.disabledKeys,
|
40
|
+
emptySearchText = props.emptySearchText,
|
41
|
+
items = props.items,
|
42
|
+
imperativeItemsFilter = props.itemsFilter,
|
43
|
+
onNamePress = props.onNamePress,
|
44
|
+
imperativeOnPopoverClose = props.onPopoverClose,
|
45
|
+
imperativeOnPopoverOpen = props.onPopoverOpen,
|
46
|
+
onSelectionChange = props.onSelectionChange,
|
47
|
+
name = props.name,
|
48
|
+
searchProps = props.searchProps,
|
49
|
+
selectedItem = props.selectedItem,
|
50
|
+
others = _objectWithoutProperties(props, ["children", "disabledKeys", "emptySearchText", "items", "itemsFilter", "onNamePress", "onPopoverClose", "onPopoverOpen", "onSelectionChange", "name", "searchProps", "selectedItem"]);
|
51
|
+
|
52
|
+
var _useState = useState(''),
|
53
|
+
_useState2 = _slicedToArray(_useState, 2),
|
54
|
+
searchValue = _useState2[0],
|
55
|
+
setSearchValue = _useState2[1];
|
56
|
+
|
57
|
+
var breadcrumbsRef = useRef();
|
58
|
+
var overlayRef = React.useRef();
|
59
|
+
var triggerRef = React.useRef();
|
60
|
+
var scrollBoxRef = React.useRef();
|
61
|
+
/* istanbul ignore next */
|
62
|
+
|
63
|
+
useImperativeHandle(ref, function () {
|
64
|
+
return breadcrumbsRef.current;
|
65
|
+
});
|
66
|
+
|
67
|
+
var _useFilter = useFilter({
|
68
|
+
sensitivity: 'base'
|
69
|
+
}),
|
70
|
+
contains = _useFilter.contains;
|
71
|
+
|
72
|
+
var filterNodesWithChildren = function filterNodesWithChildren(iterableNode) {
|
73
|
+
var nodeArr = _Array$from(iterableNode); // with this function we are filtering child items if they have sections
|
74
|
+
// we can't filter items because if it would be a section - we can't change childNodes
|
75
|
+
// eslint-disable-next-line array-callback-return,consistent-return
|
76
|
+
|
77
|
+
|
78
|
+
var filteredSections = _mapInstanceProperty(nodeArr).call(nodeArr, function f(nodeItem) {
|
79
|
+
if ((nodeItem === null || nodeItem === void 0 ? void 0 : nodeItem.type) === 'item') {
|
80
|
+
var _nodeItem$value;
|
81
|
+
|
82
|
+
return contains(nodeItem === null || nodeItem === void 0 ? void 0 : (_nodeItem$value = nodeItem.value) === null || _nodeItem$value === void 0 ? void 0 : _nodeItem$value.name, searchValue) ? nodeItem : null;
|
83
|
+
}
|
84
|
+
|
85
|
+
if ((nodeItem === null || nodeItem === void 0 ? void 0 : nodeItem.type) === 'section') {
|
86
|
+
var _context;
|
87
|
+
|
88
|
+
return _objectSpread(_objectSpread({}, nodeItem), {}, {
|
89
|
+
childNodes: _filterInstanceProperty(_context = _Array$from(nodeItem.childNodes)).call(_context, f)
|
90
|
+
});
|
91
|
+
}
|
92
|
+
}); // we are filtering null items here since we were not able to filter them in previous function
|
93
|
+
|
94
|
+
|
95
|
+
return _filterInstanceProperty(filteredSections).call(filteredSections, function (item) {
|
96
|
+
return item;
|
97
|
+
});
|
98
|
+
};
|
99
|
+
|
100
|
+
var popoverState = useOverlayTriggerState({});
|
101
|
+
var handlePopoverClose = useCallback(function () {
|
102
|
+
if (imperativeOnPopoverClose) {
|
103
|
+
imperativeOnPopoverClose();
|
104
|
+
}
|
105
|
+
|
106
|
+
setSearchValue('');
|
107
|
+
popoverState.close();
|
108
|
+
}, [imperativeOnPopoverClose, popoverState]);
|
109
|
+
var handleSelectionChange = useCallback(function (selectedItemSet) {
|
110
|
+
var _selectedItemSet = _slicedToArray(selectedItemSet, 1),
|
111
|
+
selectedItemKey = _selectedItemSet[0];
|
112
|
+
|
113
|
+
onSelectionChange(selectedItemKey);
|
114
|
+
handlePopoverClose();
|
115
|
+
}, [handlePopoverClose, onSelectionChange]);
|
116
|
+
var listBoxProps = {
|
117
|
+
children: children,
|
118
|
+
disabledKeys: imperativeDisabledKeys,
|
119
|
+
items: items,
|
120
|
+
filter: imperativeItemsFilter || filterNodesWithChildren,
|
121
|
+
onSelectionChange: handleSelectionChange,
|
122
|
+
selectedKeys: [],
|
123
|
+
selectionMode: 'single',
|
124
|
+
disallowEmptySelection: false
|
125
|
+
};
|
126
|
+
var listBoxState = useListState(listBoxProps); // this function is recursively going through the children to see
|
127
|
+
// whether there are some items so that means that the array isn't empty
|
128
|
+
|
129
|
+
var checkIfListEmpty = useCallback(function () {
|
130
|
+
// from the beginning we are assuming that the list is empty
|
131
|
+
// variable is not isListEmpty because checks below if(isListHasItems) is clearer
|
132
|
+
// to read than if(!isListEmpty) IMO
|
133
|
+
var isListHasItems = false; // eslint-disable-next-line consistent-return
|
134
|
+
|
135
|
+
(function f(listState) {
|
136
|
+
var _listState$collection;
|
137
|
+
|
138
|
+
// if the list has items - we don't need to go deeper into the recursion
|
139
|
+
if (isListHasItems) {
|
140
|
+
return;
|
141
|
+
} // here we are checking where are listItems array is stored
|
142
|
+
|
143
|
+
|
144
|
+
var listItemsArr = (listState === null || listState === void 0 ? void 0 : (_listState$collection = listState.collection) === null || _listState$collection === void 0 ? void 0 : _listState$collection.iterable) || (listState === null || listState === void 0 ? void 0 : listState.childNodes);
|
145
|
+
|
146
|
+
if ((listItemsArr === null || listItemsArr === void 0 ? void 0 : listItemsArr.length) > 0) {
|
147
|
+
// if there are a few listItems we are checking their types (can be sections) - if we have
|
148
|
+
// a few of 'items' type - we know that the list is not empty
|
149
|
+
if (listItemsArr[0].type === 'item') {
|
150
|
+
isListHasItems = true;
|
151
|
+
} else {
|
152
|
+
// this path will be taken if there are a few 'sections'
|
153
|
+
// - we need to go check them recursively
|
154
|
+
_forEachInstanceProperty(listItemsArr).call(listItemsArr, function (item) {
|
155
|
+
return f(item);
|
156
|
+
});
|
157
|
+
}
|
158
|
+
}
|
159
|
+
})(listBoxState);
|
160
|
+
|
161
|
+
return !isListHasItems;
|
162
|
+
}, [listBoxState]);
|
163
|
+
|
164
|
+
var _useOverlayTrigger = useOverlayTrigger({
|
165
|
+
type: 'listbox'
|
166
|
+
}, popoverState, triggerRef),
|
167
|
+
triggerProps = _useOverlayTrigger.triggerProps,
|
168
|
+
overlayProps = _useOverlayTrigger.overlayProps;
|
169
|
+
|
170
|
+
var handlePopoverOpen = function handlePopoverOpen() {
|
171
|
+
if (imperativeOnPopoverOpen) {
|
172
|
+
imperativeOnPopoverOpen();
|
173
|
+
}
|
174
|
+
|
175
|
+
popoverState.open();
|
176
|
+
};
|
177
|
+
|
178
|
+
var _useOverlayPosition = useOverlayPosition({
|
179
|
+
isOpen: popoverState.isOpen,
|
180
|
+
offset: 6,
|
181
|
+
onClose: handlePopoverClose,
|
182
|
+
overlayRef: overlayRef,
|
183
|
+
scrollRef: scrollBoxRef,
|
184
|
+
shouldUpdatePosition: true,
|
185
|
+
targetRef: triggerRef
|
186
|
+
}),
|
187
|
+
positionProps = _useOverlayPosition.overlayProps;
|
188
|
+
|
189
|
+
var EmptyListState = ___EmotionJSX(Text, {
|
190
|
+
py: 10,
|
191
|
+
px: 15
|
192
|
+
}, emptySearchText);
|
193
|
+
|
194
|
+
var ItemsSelect = ___EmotionJSX(React.Fragment, null, ___EmotionJSX(Button, _extends({}, triggerProps, {
|
195
|
+
onPress: handlePopoverOpen,
|
196
|
+
ref: triggerRef,
|
197
|
+
variant: "environmentBreadcrumb.current",
|
198
|
+
"aria-label": "".concat(typeof selectedItem === 'string' ? selectedItem : 'Selected Item')
|
199
|
+
}), selectedItem, ___EmotionJSX(Icon, {
|
200
|
+
icon: popoverState.isOpen ? ArrowDropUpIcon : ArrowDropDownIcon
|
201
|
+
})), ___EmotionJSX(PopoverContainer, _extends({}, overlayProps, positionProps, {
|
202
|
+
ref: overlayRef,
|
203
|
+
isOpen: popoverState.isOpen,
|
204
|
+
scrollRef: scrollBoxRef,
|
205
|
+
onClose: handlePopoverClose,
|
206
|
+
hasNoArrow: true,
|
207
|
+
isDismissable: true,
|
208
|
+
p: 10
|
209
|
+
}), ___EmotionJSX(FocusScope, {
|
210
|
+
restoreFocus: true,
|
211
|
+
autoFocus: true,
|
212
|
+
contain: true
|
213
|
+
}, ___EmotionJSX(ScrollBox, {
|
214
|
+
ref: scrollBoxRef
|
215
|
+
}, ___EmotionJSX(SearchField, _extends({
|
216
|
+
placeholder: "Search",
|
217
|
+
"aria-label": "Items Search",
|
218
|
+
"data-testid": "Environment-Breadcrumb-Search",
|
219
|
+
containerProps: {
|
220
|
+
// this one is needed to cancel default scrollBox items behavior
|
221
|
+
sx: {
|
222
|
+
overflow: 'visible'
|
223
|
+
}
|
224
|
+
},
|
225
|
+
onChange: setSearchValue
|
226
|
+
}, searchProps)), checkIfListEmpty() ? EmptyListState : ___EmotionJSX(ListBox, {
|
227
|
+
state: listBoxState,
|
228
|
+
"aria-label": "Items List"
|
229
|
+
})))));
|
230
|
+
|
231
|
+
var handleOnAction = useCallback(function (actionKey) {
|
232
|
+
if (actionKey === 'name' && onNamePress) {
|
233
|
+
onNamePress();
|
234
|
+
}
|
235
|
+
}, [onNamePress]);
|
236
|
+
return ___EmotionJSX(Breadcrumbs, _extends({
|
237
|
+
icon: ChevronRightIcon,
|
238
|
+
ref: breadcrumbsRef,
|
239
|
+
onAction: handleOnAction,
|
240
|
+
iconProps: {
|
241
|
+
color: 'neutral.70',
|
242
|
+
mx: 10
|
243
|
+
}
|
244
|
+
}, others), ___EmotionJSX(Item, {
|
245
|
+
key: "name",
|
246
|
+
variant: "environmentBreadcrumb.current",
|
247
|
+
"data-testid": "name",
|
248
|
+
"aria-label": name
|
249
|
+
}, ___EmotionJSX(Icon, {
|
250
|
+
icon: HomeIcon,
|
251
|
+
mr: 7
|
252
|
+
}), name), selectedItem && ___EmotionJSX(Item, {
|
253
|
+
key: "itemsSelect",
|
254
|
+
elementType: "Fragment"
|
255
|
+
}, ItemsSelect));
|
256
|
+
});
|
257
|
+
export default EnvironmentBreadcrumb;
|
258
|
+
EnvironmentBreadcrumb.propTypes = {
|
259
|
+
/** Callback function that fires when the selected key changes. */
|
260
|
+
onSelectionChange: PropTypes.func,
|
261
|
+
|
262
|
+
/** Current environment */
|
263
|
+
selectedItem: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
264
|
+
|
265
|
+
/** Displayed name */
|
266
|
+
name: PropTypes.string,
|
267
|
+
|
268
|
+
/** Callback function that fires when name pressed */
|
269
|
+
onNamePress: PropTypes.func,
|
270
|
+
|
271
|
+
/** The list of environments. */
|
272
|
+
items: isIterableProp,
|
273
|
+
|
274
|
+
/** Filter function to generate a filtered list of nodes.
|
275
|
+
* (nodes: Iterable<Node>) => Iterable<Node>
|
276
|
+
* */
|
277
|
+
itemsFilter: PropTypes.func,
|
278
|
+
|
279
|
+
/** Callback function that fires when the dropdown is opened. */
|
280
|
+
onPopoverOpen: PropTypes.func,
|
281
|
+
|
282
|
+
/** Callback function that fires when the dropdown is closed. */
|
283
|
+
onPopoverClose: PropTypes.func,
|
284
|
+
|
285
|
+
/** Props object that is spread directly into the SearchField element. */
|
286
|
+
searchProps: PropTypes.shape({}),
|
287
|
+
|
288
|
+
/** Array of keys to disable within the options list. */
|
289
|
+
disabledKeys: PropTypes.arrayOf(PropTypes.string),
|
290
|
+
|
291
|
+
/** Text that will be shown if no search results found. */
|
292
|
+
emptySearchText: PropTypes.string
|
293
|
+
};
|
294
|
+
EnvironmentBreadcrumb.defaultProps = {
|
295
|
+
emptySearchText: 'No Search Result'
|
296
|
+
};
|
@@ -0,0 +1,256 @@
|
|
1
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
2
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
3
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
4
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
5
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
6
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
7
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
8
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
9
|
+
import _indexOfInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/index-of";
|
10
|
+
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
11
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
12
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
13
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
14
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
15
|
+
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
16
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
17
|
+
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
19
|
+
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context6; _forEachInstanceProperty(_context6 = ownKeys(Object(source), true)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context7; _forEachInstanceProperty(_context7 = ownKeys(Object(source))).call(_context7, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
21
|
+
|
22
|
+
import React, { useState } from 'react';
|
23
|
+
import EnvironmentBreadcrumb from './EnvironmentBreadcrumb';
|
24
|
+
import { Item, Section, OverlayProvider, Chip, Box, Text } from '../../index';
|
25
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
26
|
+
export default {
|
27
|
+
title: 'EnvironmentBreadcrumb',
|
28
|
+
component: EnvironmentBreadcrumb
|
29
|
+
};
|
30
|
+
var defaultEnvironments = [{
|
31
|
+
name: 'Default'
|
32
|
+
}, {
|
33
|
+
name: 'Kangaroo'
|
34
|
+
}, {
|
35
|
+
name: 'Snake'
|
36
|
+
}, {
|
37
|
+
name: 'Snail'
|
38
|
+
}, {
|
39
|
+
name: 'Slug'
|
40
|
+
}, {
|
41
|
+
name: 'Crow'
|
42
|
+
}, {
|
43
|
+
name: 'Dog'
|
44
|
+
}, {
|
45
|
+
name: 'Crab',
|
46
|
+
isSandbox: true
|
47
|
+
}, {
|
48
|
+
name: 'Fish'
|
49
|
+
}, {
|
50
|
+
name: 'Turtle'
|
51
|
+
}, {
|
52
|
+
name: 'Mouse'
|
53
|
+
}, {
|
54
|
+
name: 'Banana'
|
55
|
+
}, {
|
56
|
+
name: 'Shark'
|
57
|
+
}, {
|
58
|
+
name: 'Gorilla'
|
59
|
+
}, {
|
60
|
+
name: 'Goat'
|
61
|
+
}];
|
62
|
+
var environmentsWithSections = [{
|
63
|
+
name: 'Recent',
|
64
|
+
options: [{
|
65
|
+
name: 'Default'
|
66
|
+
}, {
|
67
|
+
name: 'Consumer Banking Prod'
|
68
|
+
}, {
|
69
|
+
name: 'Custom 360 Test'
|
70
|
+
}]
|
71
|
+
}, {
|
72
|
+
name: 'All',
|
73
|
+
options: [{
|
74
|
+
name: 'Consumer Banking Prod'
|
75
|
+
}, {
|
76
|
+
name: 'Custom 360 Test'
|
77
|
+
}, {
|
78
|
+
name: 'Default'
|
79
|
+
}, {
|
80
|
+
name: 'Great New One',
|
81
|
+
isSandbox: true
|
82
|
+
}, {
|
83
|
+
name: 'Jeff’s Workforce'
|
84
|
+
}, {
|
85
|
+
name: 'Lindemuller Prod'
|
86
|
+
}, {
|
87
|
+
name: 'Mine'
|
88
|
+
}]
|
89
|
+
}];
|
90
|
+
export var Default = function Default(args) {
|
91
|
+
var _useState = useState({
|
92
|
+
name: 'Snail',
|
93
|
+
isSandbox: true
|
94
|
+
}),
|
95
|
+
_useState2 = _slicedToArray(_useState, 2),
|
96
|
+
selectedEnvironment = _useState2[0],
|
97
|
+
setSelectedEnvironment = _useState2[1];
|
98
|
+
|
99
|
+
var envNode = ___EmotionJSX(Box, {
|
100
|
+
isRow: true
|
101
|
+
}, ___EmotionJSX(Text, {
|
102
|
+
color: "inherit"
|
103
|
+
}, selectedEnvironment.name), selectedEnvironment.isSandbox ? ___EmotionJSX(Chip, {
|
104
|
+
label: "SANDBOX",
|
105
|
+
variant: "boxes.environmentChip",
|
106
|
+
bg: "neutral.40"
|
107
|
+
}) : null);
|
108
|
+
|
109
|
+
var findEnvObj = function findEnvObj(envName) {
|
110
|
+
return _findInstanceProperty(defaultEnvironments).call(defaultEnvironments, function (_ref) {
|
111
|
+
var name = _ref.name;
|
112
|
+
return name === envName;
|
113
|
+
});
|
114
|
+
};
|
115
|
+
|
116
|
+
var handleSelectionChange = function handleSelectionChange(newEnvName) {
|
117
|
+
var envObj = findEnvObj(newEnvName);
|
118
|
+
setSelectedEnvironment(_objectSpread({}, envObj));
|
119
|
+
};
|
120
|
+
|
121
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(EnvironmentBreadcrumb, _extends({}, args, {
|
122
|
+
items: defaultEnvironments,
|
123
|
+
name: "Globochem",
|
124
|
+
selectedItem: envNode,
|
125
|
+
onSelectionChange: handleSelectionChange
|
126
|
+
}), function (_ref2) {
|
127
|
+
var name = _ref2.name,
|
128
|
+
isSandbox = _ref2.isSandbox;
|
129
|
+
return ___EmotionJSX(Item, {
|
130
|
+
key: name,
|
131
|
+
textValue: name
|
132
|
+
}, name, isSandbox ? ___EmotionJSX(Chip, {
|
133
|
+
label: "SANDBOX",
|
134
|
+
variant: "boxes.environmentChip",
|
135
|
+
bg: "neutral.40"
|
136
|
+
}) : null);
|
137
|
+
}));
|
138
|
+
};
|
139
|
+
export var WithSections = function WithSections() {
|
140
|
+
var _useState3 = useState(environmentsWithSections),
|
141
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
142
|
+
environments = _useState4[0],
|
143
|
+
setEnvironments = _useState4[1];
|
144
|
+
|
145
|
+
var _useState5 = useState({
|
146
|
+
name: 'Consumer Banking Prod'
|
147
|
+
}),
|
148
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
149
|
+
selectedEnvironment = _useState6[0],
|
150
|
+
setSelectedEnvironment = _useState6[1];
|
151
|
+
|
152
|
+
var recentEnvShown = 3;
|
153
|
+
|
154
|
+
var getUpdatedRecentEnvs = function getUpdatedRecentEnvs(envObj, prevEnvs) {
|
155
|
+
var _context3;
|
156
|
+
|
157
|
+
var envName = envObj.name;
|
158
|
+
var isDuplicate = _filterInstanceProperty(prevEnvs).call(prevEnvs, function (prevEnv) {
|
159
|
+
return prevEnv.name === envName;
|
160
|
+
}).length > 0;
|
161
|
+
|
162
|
+
if (isDuplicate) {
|
163
|
+
var _context;
|
164
|
+
|
165
|
+
return _concatInstanceProperty(_context = [_objectSpread({}, envObj)]).call(_context, _filterInstanceProperty(prevEnvs).call(prevEnvs, function (prevEnv) {
|
166
|
+
return prevEnv.name !== envName;
|
167
|
+
}));
|
168
|
+
}
|
169
|
+
|
170
|
+
if (prevEnvs.length >= recentEnvShown) {
|
171
|
+
var _context2;
|
172
|
+
|
173
|
+
return _concatInstanceProperty(_context2 = [_objectSpread({}, envObj)]).call(_context2, _sliceInstanceProperty(prevEnvs).call(prevEnvs, 0, recentEnvShown - 1));
|
174
|
+
}
|
175
|
+
|
176
|
+
return _concatInstanceProperty(_context3 = [_objectSpread({}, envObj)]).call(_context3, prevEnvs);
|
177
|
+
};
|
178
|
+
|
179
|
+
var findEnvObj = function findEnvObj(envName) {
|
180
|
+
var _context4;
|
181
|
+
|
182
|
+
return _findInstanceProperty(_context4 = _findInstanceProperty(environments).call(environments, function (section) {
|
183
|
+
return section.name === 'All';
|
184
|
+
}).options).call(_context4, function (option) {
|
185
|
+
return option.name === envName;
|
186
|
+
});
|
187
|
+
};
|
188
|
+
|
189
|
+
var handleEnvPress = function handleEnvPress(newEnv) {
|
190
|
+
var sectionPrefixIndex = _indexOfInstanceProperty(newEnv).call(newEnv, '-');
|
191
|
+
|
192
|
+
var envKey = newEnv.substr(sectionPrefixIndex + 1);
|
193
|
+
|
194
|
+
var recentEnvironments = _findInstanceProperty(environments).call(environments, function (envSection) {
|
195
|
+
return envSection.name === 'Recent';
|
196
|
+
}).options;
|
197
|
+
|
198
|
+
var envObj = findEnvObj(envKey);
|
199
|
+
var updatedRecentEnvironments = getUpdatedRecentEnvs(envObj, recentEnvironments);
|
200
|
+
setEnvironments(function (prevEnvs) {
|
201
|
+
return _mapInstanceProperty(prevEnvs).call(prevEnvs, function (section) {
|
202
|
+
return section.name === 'Recent' ? _objectSpread(_objectSpread({}, section), {}, {
|
203
|
+
options: updatedRecentEnvironments
|
204
|
+
}) : section;
|
205
|
+
});
|
206
|
+
});
|
207
|
+
setSelectedEnvironment(_objectSpread({}, envObj));
|
208
|
+
};
|
209
|
+
|
210
|
+
var envNode = ___EmotionJSX(Box, {
|
211
|
+
isRow: true
|
212
|
+
}, ___EmotionJSX(Text, {
|
213
|
+
color: "inherit"
|
214
|
+
}, selectedEnvironment.name), selectedEnvironment.isSandbox ? ___EmotionJSX(Chip, {
|
215
|
+
label: "SANDBOX",
|
216
|
+
variant: "boxes.environmentChip",
|
217
|
+
bg: "neutral.40"
|
218
|
+
}) : null);
|
219
|
+
|
220
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(EnvironmentBreadcrumb, {
|
221
|
+
items: environments,
|
222
|
+
name: "Globochem",
|
223
|
+
selectedItem: envNode,
|
224
|
+
onSelectionChange: handleEnvPress
|
225
|
+
}, function (_ref3) {
|
226
|
+
var sectionName = _ref3.name,
|
227
|
+
sectionOptions = _ref3.options;
|
228
|
+
return ___EmotionJSX(Section, {
|
229
|
+
key: sectionName,
|
230
|
+
title: sectionName,
|
231
|
+
items: sectionOptions
|
232
|
+
}, function (_ref4) {
|
233
|
+
var _context5;
|
234
|
+
|
235
|
+
var itemName = _ref4.name,
|
236
|
+
itemOptions = _ref4.options,
|
237
|
+
isSandbox = _ref4.isSandbox;
|
238
|
+
return ___EmotionJSX(Item, {
|
239
|
+
key: _concatInstanceProperty(_context5 = "".concat(sectionName, "-")).call(_context5, itemName),
|
240
|
+
childItems: itemOptions,
|
241
|
+
textValue: itemName
|
242
|
+
}, ___EmotionJSX(Box, {
|
243
|
+
isRow: true
|
244
|
+
}, itemName, isSandbox ? ___EmotionJSX(Chip, {
|
245
|
+
label: "SANDBOX",
|
246
|
+
variant: "boxes.environmentChip",
|
247
|
+
bg: "neutral.40"
|
248
|
+
}) : null));
|
249
|
+
});
|
250
|
+
}));
|
251
|
+
};
|
252
|
+
export var OrgLevel = function OrgLevel() {
|
253
|
+
return ___EmotionJSX(EnvironmentBreadcrumb, {
|
254
|
+
name: "Globochem"
|
255
|
+
});
|
256
|
+
};
|