@pingux/astro 2.20.0-alpha.0 → 2.20.0-alpha.10
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/{experimental → components}/ButtonBar/ButtonBar.js +6 -9
- package/lib/{experimental → cjs/components}/ButtonBar/ButtonBar.mdx +1 -2
- package/lib/cjs/{experimental → components}/ButtonBar/ButtonBar.stories.js +22 -9
- package/lib/cjs/components/ButtonBar/ButtonBar.styles.js +33 -0
- package/lib/cjs/{experimental → components}/ButtonBar/ButtonBar.test.js +5 -5
- package/lib/cjs/components/ColorField/ColorField.js +4 -1
- package/lib/cjs/components/ListView/ListView.js +8 -2
- package/lib/cjs/components/TreeView/TreeView.js +100 -0
- package/lib/cjs/components/TreeView/TreeView.mdx +16 -0
- package/lib/cjs/components/TreeView/TreeView.stories.js +89 -0
- package/lib/cjs/components/TreeView/TreeView.styles.js +32 -0
- package/lib/cjs/components/TreeView/TreeView.test.js +124 -0
- package/lib/cjs/components/TreeView/TreeViewItem.js +74 -0
- package/lib/cjs/components/TreeView/TreeViewRow.js +147 -0
- package/lib/cjs/components/TreeView/TreeViewSection.js +88 -0
- package/lib/cjs/components/TreeView/index.js +28 -0
- package/lib/cjs/context/TreeViewContext/index.js +14 -0
- package/lib/cjs/index.d.ts +4 -2
- package/lib/cjs/index.js +32 -6
- package/lib/cjs/recipes/CountryPicker.stories.js +11 -2
- package/lib/cjs/recipes/{EditableInput.stories.js → InlineEditing.stories.js} +12 -2
- package/lib/cjs/recipes/OneWayToBidirectionalArrow.stories.js +8 -1
- package/lib/cjs/styles/variants/variants.js +5 -1
- package/lib/cjs/utils/designUtils/figmaLinks.js +13 -0
- package/lib/{experimental → components}/ButtonBar/ButtonBar.js +6 -9
- package/lib/{cjs/experimental → components}/ButtonBar/ButtonBar.mdx +1 -2
- package/lib/{experimental → components}/ButtonBar/ButtonBar.stories.js +15 -2
- package/lib/components/ButtonBar/ButtonBar.styles.js +25 -0
- package/lib/{experimental → components}/ButtonBar/ButtonBar.test.js +1 -1
- package/lib/components/ColorField/ColorField.js +4 -1
- package/lib/components/ListView/ListView.js +8 -2
- package/lib/components/TreeView/TreeView.js +89 -0
- package/lib/components/TreeView/TreeView.mdx +16 -0
- package/lib/components/TreeView/TreeView.stories.js +79 -0
- package/lib/components/TreeView/TreeView.styles.js +24 -0
- package/lib/components/TreeView/TreeView.test.js +121 -0
- package/lib/components/TreeView/TreeViewItem.js +60 -0
- package/lib/components/TreeView/TreeViewRow.js +135 -0
- package/lib/components/TreeView/TreeViewSection.js +74 -0
- package/lib/components/TreeView/index.js +3 -0
- package/lib/context/TreeViewContext/index.js +5 -0
- package/lib/index.js +4 -2
- package/lib/recipes/CountryPicker.stories.js +10 -1
- package/lib/recipes/{EditableInput.stories.js → InlineEditing.stories.js} +10 -1
- package/lib/recipes/OneWayToBidirectionalArrow.stories.js +7 -0
- package/lib/styles/variants/variants.js +5 -1
- package/lib/utils/designUtils/figmaLinks.js +13 -0
- package/package.json +1 -1
- package/lib/cjs/recipes/RowLineChart.stories.js +0 -578
- package/lib/recipes/RowLineChart.stories.js +0 -565
- /package/lib/cjs/{experimental → components}/ButtonBar/index.js +0 -0
- /package/lib/{experimental → components}/ButtonBar/index.js +0 -0
@@ -24,6 +24,10 @@ var FIGMA_LINKS = {
|
|
24
24
|
button: {
|
25
25
|
"default": 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?type=design&node-id=0-1&t=8Wwd3tIBh3GEjCJB-0'
|
26
26
|
},
|
27
|
+
buttonBar: {
|
28
|
+
"default": 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?node-id=3660%3A20551&mode=dev',
|
29
|
+
rightAligned: 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?node-id=3660%3A20657&mode=dev'
|
30
|
+
},
|
27
31
|
calendar: {
|
28
32
|
"default": 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?type=design&node-id=6373%3A25490&t=BoHXzVpQq9Lf7MaU-1'
|
29
33
|
},
|
@@ -46,6 +50,9 @@ var FIGMA_LINKS = {
|
|
46
50
|
copyText: {
|
47
51
|
"default": 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?type=design&node-id=218-1442&t=8Wwd3tIBh3GEjCJB-0'
|
48
52
|
},
|
53
|
+
countryPicker: {
|
54
|
+
"default": 'https://www.figma.com/file/Oa6VYtJcUJzEJuuRp0p4ls/Astro?type=design&node-id=4568-7532&mode=design&t=eSfQYHRFNPf37J4C-0'
|
55
|
+
},
|
49
56
|
helpHint: {
|
50
57
|
"default": 'https://www.figma.com/file/Oa6VYtJcUJzEJuuRp0p4ls/Astro?type=design&node-id=0%3A4534&t=We3h7LaaFJQnxdSy-1',
|
51
58
|
withLink: 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?type=design&node-id=28958%3A40081&mode=design&t=WmSYPx1hR8kxFiXf-1'
|
@@ -59,6 +66,9 @@ var FIGMA_LINKS = {
|
|
59
66
|
iconButton: {
|
60
67
|
"default": 'https://www.figma.com/file/Oa6VYtJcUJzEJuuRp0p4ls/Astro?type=design&node-id=0%3A2520&t=We3h7LaaFJQnxdSy-1'
|
61
68
|
},
|
69
|
+
inlineEditing: {
|
70
|
+
"default": 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?type=design&node-id=5244-14864&mode=design&t=1pPbrQvGkdMYBNqk-0'
|
71
|
+
},
|
62
72
|
link: {
|
63
73
|
"default": 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?type=design&node-id=8708-29543&t=8Wwd3tIBh3GEjCJB-0'
|
64
74
|
},
|
@@ -86,6 +96,9 @@ var FIGMA_LINKS = {
|
|
86
96
|
navBar: {
|
87
97
|
"default": 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?type=design&node-id=548-3473&t=8Wwd3tIBh3GEjCJB-0'
|
88
98
|
},
|
99
|
+
OnewayToBidirectionalArrow: {
|
100
|
+
"default": 'https://www.figma.com/file/bpbEw54gTTcdIiZs4PKK1p/Astro-Specs?type=design&node-id=43504-1214&mode=design&t=R4kdj0liRHxsqbV5-0'
|
101
|
+
},
|
89
102
|
popoverMenu: {
|
90
103
|
"default": 'https://www.figma.com/file/Oa6VYtJcUJzEJuuRp0p4ls/Astro?type=design&node-id=0%3A3073&t=We3h7LaaFJQnxdSy-1'
|
91
104
|
},
|
@@ -6,22 +6,19 @@ import PropTypes from 'prop-types';
|
|
6
6
|
import { Box } from '../../index';
|
7
7
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
8
8
|
var ButtonBar = function ButtonBar(props) {
|
9
|
-
var
|
10
|
-
align = _props$align === void 0 ? 'left' : _props$align,
|
9
|
+
var align = props.align,
|
11
10
|
children = props.children,
|
12
11
|
others = _objectWithoutProperties(props, _excluded);
|
13
12
|
return ___EmotionJSX(Box, _extends({
|
14
13
|
isRow: true,
|
15
|
-
|
16
|
-
sx: {
|
17
|
-
bg: 'white',
|
18
|
-
px: 'lg',
|
19
|
-
py: 'md',
|
20
|
-
justifyContent: align === 'right' ? 'right' : 'left'
|
21
|
-
}
|
14
|
+
variant: align === 'right' ? 'buttonBar.justifyRightContainer' : 'buttonBar.container'
|
22
15
|
}, others), children);
|
23
16
|
};
|
24
17
|
ButtonBar.propTypes = {
|
18
|
+
/** Justifies the component's children. */
|
25
19
|
align: PropTypes.oneOf(['left', 'right'])
|
26
20
|
};
|
21
|
+
ButtonBar.defaultProps = {
|
22
|
+
align: 'left'
|
23
|
+
};
|
27
24
|
export default ButtonBar;
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import { Meta } from '@storybook/addon-docs';
|
2
2
|
|
3
|
-
<Meta title="
|
3
|
+
<Meta title="Components/ButtonBar/ButtonBar" />
|
4
4
|
|
5
5
|
# ButtonBar
|
6
6
|
|
7
7
|
This is a composed component that renders children in a simplified, organized and consistent manner.
|
8
8
|
|
9
|
-
If the **align** prop is set to right it will justify the children to the right. Default is left justification.
|
@@ -1,10 +1,11 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
3
|
-
import { Button, ButtonBar } from '
|
3
|
+
import { Button, ButtonBar } from '../../index';
|
4
|
+
import { FIGMA_LINKS } from '../../utils/designUtils/figmaLinks';
|
4
5
|
import ButtonBarReadme from './ButtonBar.mdx';
|
5
6
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
6
7
|
export default {
|
7
|
-
title: '
|
8
|
+
title: 'Components/ButtonBar',
|
8
9
|
component: ButtonBar,
|
9
10
|
parameters: {
|
10
11
|
docs: {
|
@@ -39,6 +40,12 @@ export var Default = function Default(args) {
|
|
39
40
|
}
|
40
41
|
}, "Cancel"));
|
41
42
|
};
|
43
|
+
Default.parameters = {
|
44
|
+
design: {
|
45
|
+
type: 'figma',
|
46
|
+
url: FIGMA_LINKS.buttonBar["default"]
|
47
|
+
}
|
48
|
+
};
|
42
49
|
export var RightAligned = function RightAligned() {
|
43
50
|
return ___EmotionJSX(ButtonBar, {
|
44
51
|
align: "right"
|
@@ -55,4 +62,10 @@ export var RightAligned = function RightAligned() {
|
|
55
62
|
return alert('Cancel button pressed');
|
56
63
|
}
|
57
64
|
}, "Cancel"));
|
65
|
+
};
|
66
|
+
RightAligned.parameters = {
|
67
|
+
design: {
|
68
|
+
type: 'figma',
|
69
|
+
url: FIGMA_LINKS.buttonBar.rightAligned
|
70
|
+
}
|
58
71
|
};
|
@@ -0,0 +1,25 @@
|
|
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(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; }
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
12
|
+
var container = {
|
13
|
+
bg: 'white',
|
14
|
+
gap: 'md',
|
15
|
+
justifyContent: 'left',
|
16
|
+
px: 'lg',
|
17
|
+
py: 'md'
|
18
|
+
};
|
19
|
+
var justifyRightContainer = _objectSpread(_objectSpread({}, container), {}, {
|
20
|
+
justifyContent: 'right'
|
21
|
+
});
|
22
|
+
export default {
|
23
|
+
container: container,
|
24
|
+
justifyRightContainer: justifyRightContainer
|
25
|
+
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
2
|
import React from 'react';
|
3
|
-
import { Button, ButtonBar } from '
|
3
|
+
import { Button, ButtonBar } from '../../index';
|
4
4
|
import axeTest from '../../utils/testUtils/testAxe';
|
5
5
|
import { render, screen } from '../../utils/testUtils/testWrapper';
|
6
6
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
@@ -98,7 +98,10 @@ var ColorField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
98
98
|
ref: triggerRef,
|
99
99
|
variant: "forms.colorField.container"
|
100
100
|
}, mergeProps(buttonProps, ariaProps, triggerProps))), ___EmotionJSX(Box, fieldControlWrapperProps, ___EmotionJSX(Input, _extends({}, visuallyHiddenProps, fieldControlInputProps, {
|
101
|
-
ref: colorRef
|
101
|
+
ref: colorRef,
|
102
|
+
sx: {
|
103
|
+
display: 'none'
|
104
|
+
}
|
102
105
|
}))), helperText && ___EmotionJSX(FieldHelperText, {
|
103
106
|
status: status
|
104
107
|
}, helperText), ___EmotionJSX(PopoverContainer, _extends({
|
@@ -10,7 +10,7 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
10
10
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
11
11
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
12
12
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
13
|
-
var _excluded = ["disabledKeys", "isHoverable", "loadingState", "onLoadMore", "onSelectionChange", "selectedKeys", "selectionMode", "selectionStyle"];
|
13
|
+
var _excluded = ["disabledKeys", "isHoverable", "loadingState", "onLoadMore", "onSelectionChange", "selectedKeys", "selectionMode", "selectionStyle", "items"];
|
14
14
|
import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
|
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 _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
@@ -63,6 +63,7 @@ var ListView = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
63
63
|
selectedKeys = props.selectedKeys,
|
64
64
|
selectionMode = props.selectionMode,
|
65
65
|
selectionStyle = props.selectionStyle,
|
66
|
+
items = props.items,
|
66
67
|
others = _objectWithoutProperties(props, _excluded);
|
67
68
|
var _useState = useState(null),
|
68
69
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -106,6 +107,9 @@ var ListView = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
106
107
|
layout.isLoading = isLoading;
|
107
108
|
var focusedKey = selectionManager.focusedKey;
|
108
109
|
delete gridProps.onMouseDown;
|
110
|
+
if (!items) {
|
111
|
+
delete others['aria-label'];
|
112
|
+
}
|
109
113
|
var onFocus = function onFocus(e) {
|
110
114
|
gridProps.onFocus(e);
|
111
115
|
if (others.onFocus) {
|
@@ -121,7 +125,9 @@ var ListView = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
121
125
|
value: {
|
122
126
|
state: state
|
123
127
|
}
|
124
|
-
}, ___EmotionJSX(Virtualizer, _extends({}, gridProps
|
128
|
+
}, ___EmotionJSX(Virtualizer, _extends({}, items ? gridProps : {
|
129
|
+
role: 'presentation'
|
130
|
+
}, {
|
125
131
|
onLoadMore: onLoadMore,
|
126
132
|
ref: listViewRef,
|
127
133
|
focusedKey: focusedKey,
|
@@ -0,0 +1,89 @@
|
|
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 _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
10
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
11
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
+
var _excluded = ["tree", "onExpandedChange"];
|
13
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
14
|
+
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
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
|
+
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';
|
18
|
+
import { useTreeState } from 'react-stately';
|
19
|
+
import PropTypes from 'prop-types';
|
20
|
+
import { TreeViewContext } from '../../context/TreeViewContext';
|
21
|
+
import { Box, TreeViewItem, TreeViewSection } from '../../index';
|
22
|
+
import { isIterableProp } from '../../utils/devUtils/props/isIterable';
|
23
|
+
|
24
|
+
// split out and exported for ease of use across components
|
25
|
+
// and to facilitate easier testing (eliminates redundant conditional renders)
|
26
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
27
|
+
export var SectionOrItemRender = function SectionOrItemRender(condition, SectionComponent, ItemComponent) {
|
28
|
+
if (condition) {
|
29
|
+
return SectionComponent;
|
30
|
+
}
|
31
|
+
return ItemComponent;
|
32
|
+
};
|
33
|
+
var TreeView = /*#__PURE__*/forwardRef(function (props, ref) {
|
34
|
+
var _labelRef$current, _context;
|
35
|
+
var tree = props.tree,
|
36
|
+
onExpandedChange = props.onExpandedChange,
|
37
|
+
others = _objectWithoutProperties(props, _excluded);
|
38
|
+
var labelRef = useRef();
|
39
|
+
var treeViewRef = useRef();
|
40
|
+
/* istanbul ignore next */
|
41
|
+
useImperativeHandle(ref, function () {
|
42
|
+
return treeViewRef.current;
|
43
|
+
});
|
44
|
+
var state = useTreeState(_objectSpread({
|
45
|
+
onExpandedChange: onExpandedChange
|
46
|
+
}, others));
|
47
|
+
return ___EmotionJSX(TreeViewContext.Provider, {
|
48
|
+
value: {
|
49
|
+
state: state,
|
50
|
+
tree: tree
|
51
|
+
}
|
52
|
+
}, ___EmotionJSX(Box, _extends({
|
53
|
+
as: "ul",
|
54
|
+
role: "tree",
|
55
|
+
ref: treeViewRef,
|
56
|
+
"aria-labelledby": labelRef === null || labelRef === void 0 || (_labelRef$current = labelRef.current) === null || _labelRef$current === void 0 ? void 0 : _labelRef$current.id,
|
57
|
+
sx: {
|
58
|
+
overflow: 'hidden'
|
59
|
+
}
|
60
|
+
}, others), _mapInstanceProperty(_context = _Array$from(state.collection)).call(_context, function (item) {
|
61
|
+
return SectionOrItemRender(item.type === 'section', ___EmotionJSX(TreeViewSection, {
|
62
|
+
item: item,
|
63
|
+
items: item.props.items,
|
64
|
+
title: item.props.title,
|
65
|
+
key: item.props.title
|
66
|
+
}), ___EmotionJSX(TreeViewItem, {
|
67
|
+
item: item,
|
68
|
+
title: item.value.value.title,
|
69
|
+
key: item.value.value.title
|
70
|
+
}));
|
71
|
+
})));
|
72
|
+
});
|
73
|
+
TreeView.defaultProps = {
|
74
|
+
'aria-label': 'tree'
|
75
|
+
};
|
76
|
+
TreeView.propTypes = {
|
77
|
+
/** data object prop that is required to make the tree function
|
78
|
+
this is returned from the useTreeData hook in React-Aria */
|
79
|
+
tree: PropTypes.shape({}).isRequired,
|
80
|
+
/** The currently disabled keys in the collection. */
|
81
|
+
disabledKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object])),
|
82
|
+
/** Callback function that is called when items are expanded or collapsed. */
|
83
|
+
onExpandedChange: PropTypes.func,
|
84
|
+
/** The list of TreeView items. */
|
85
|
+
items: isIterableProp,
|
86
|
+
/** String that describes the treeview when using a screen reader. */
|
87
|
+
'aria-label': PropTypes.string
|
88
|
+
};
|
89
|
+
export default TreeView;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { Meta } from '@storybook/addon-docs';
|
2
|
+
|
3
|
+
<Meta title="Experimental/TreeView/TreeView" />
|
4
|
+
|
5
|
+
# TreeView
|
6
|
+
|
7
|
+
The TreeView component represents a nested structure of data.
|
8
|
+
|
9
|
+
### Required components
|
10
|
+
|
11
|
+
This component requires the the use of Item and Section, both exported from [react-stately/collections](https://react-spectrum.adobe.com/react-stately/collections.html).
|
12
|
+
This component will also require the use of the [useTreeData](https://react-spectrum.adobe.com/react-stately/useTreeData.html) hook, which is exported through react-stately.
|
13
|
+
|
14
|
+
### Accessibility
|
15
|
+
|
16
|
+
This component should adhere to the [WAI-ARIA TreeView](https://www.w3.org/WAI/ARIA/apg/patterns/treeview/) accessibility guidelines.
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import React from 'react';
|
3
|
+
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
4
|
+
import { Item, Section, TreeView, useTreeData } from '../../index';
|
5
|
+
import { SectionOrItemRender } from './TreeView';
|
6
|
+
import TreeViewReadMe from './TreeView.mdx';
|
7
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
8
|
+
export default {
|
9
|
+
title: 'Experimental/TreeView',
|
10
|
+
component: TreeView,
|
11
|
+
parameters: {
|
12
|
+
docs: {
|
13
|
+
page: function page() {
|
14
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(TreeViewReadMe, null), ___EmotionJSX(DocsLayout, null));
|
15
|
+
},
|
16
|
+
source: {
|
17
|
+
type: 'code'
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
};
|
22
|
+
var data = [{
|
23
|
+
title: 'Policies',
|
24
|
+
items: [{
|
25
|
+
title: 'Registration',
|
26
|
+
items: [{
|
27
|
+
title: 'Registration A'
|
28
|
+
}, {
|
29
|
+
title: 'Registration B',
|
30
|
+
items: [{
|
31
|
+
title: 'Registration B1'
|
32
|
+
}, {
|
33
|
+
title: 'Registration B2'
|
34
|
+
}]
|
35
|
+
}, {
|
36
|
+
title: 'Registration C'
|
37
|
+
}, {
|
38
|
+
title: 'Registration D'
|
39
|
+
}]
|
40
|
+
}, {
|
41
|
+
title: 'Authentication',
|
42
|
+
items: [{
|
43
|
+
title: 'Authentication A'
|
44
|
+
}, {
|
45
|
+
title: 'Authentication B'
|
46
|
+
}]
|
47
|
+
}]
|
48
|
+
}, {
|
49
|
+
title: 'Other',
|
50
|
+
items: [{
|
51
|
+
title: 'Other A'
|
52
|
+
}]
|
53
|
+
}, {
|
54
|
+
title: 'Single Item'
|
55
|
+
}];
|
56
|
+
export var Default = function Default(args) {
|
57
|
+
var tree = useTreeData({
|
58
|
+
initialItems: data,
|
59
|
+
getKey: function getKey(item) {
|
60
|
+
return item.title;
|
61
|
+
},
|
62
|
+
getChildren: function getChildren(item) {
|
63
|
+
return item.items;
|
64
|
+
}
|
65
|
+
});
|
66
|
+
return ___EmotionJSX(TreeView, _extends({}, args, {
|
67
|
+
items: tree.items,
|
68
|
+
tree: tree
|
69
|
+
}), function (section) {
|
70
|
+
return SectionOrItemRender(section.children.length > 0, ___EmotionJSX(Section, {
|
71
|
+
key: section.key,
|
72
|
+
items: section.children,
|
73
|
+
title: section.value.title
|
74
|
+
}), ___EmotionJSX(Item, {
|
75
|
+
key: section.key,
|
76
|
+
title: section.title
|
77
|
+
}));
|
78
|
+
});
|
79
|
+
};
|
@@ -0,0 +1,24 @@
|
|
1
|
+
var treeRow = {
|
2
|
+
flexGrow: 1,
|
3
|
+
cursor: 'pointer',
|
4
|
+
height: '31px',
|
5
|
+
outline: 'none',
|
6
|
+
'&.is-selected, &.is-hovered, &.is-focused': {
|
7
|
+
backgroundColor: 'active',
|
8
|
+
'& span': {
|
9
|
+
color: 'white'
|
10
|
+
},
|
11
|
+
'& svg': {
|
12
|
+
fill: 'white'
|
13
|
+
},
|
14
|
+
'& button': {
|
15
|
+
fill: 'white'
|
16
|
+
}
|
17
|
+
},
|
18
|
+
'&.is-expanded': {
|
19
|
+
marginBottom: 'xs'
|
20
|
+
}
|
21
|
+
};
|
22
|
+
export default {
|
23
|
+
treeRow: treeRow
|
24
|
+
};
|
@@ -0,0 +1,121 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import React from 'react';
|
3
|
+
import { useTreeData } from 'react-stately';
|
4
|
+
import { Item, Section } from '../../index';
|
5
|
+
import { fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
|
6
|
+
import { SectionOrItemRender } from './TreeView';
|
7
|
+
import TreeView from '.';
|
8
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
9
|
+
var testId = 'test-TreeView';
|
10
|
+
var defaultProps = {
|
11
|
+
'data-testid': testId
|
12
|
+
};
|
13
|
+
var data = [{
|
14
|
+
title: 'People',
|
15
|
+
items: [{
|
16
|
+
title: 'David',
|
17
|
+
customProp: 1
|
18
|
+
}, {
|
19
|
+
title: 'Sam'
|
20
|
+
}, {
|
21
|
+
title: 'Jane'
|
22
|
+
}]
|
23
|
+
}, {
|
24
|
+
title: 'Animals',
|
25
|
+
items: [{
|
26
|
+
title: 'Bears',
|
27
|
+
items: [{
|
28
|
+
title: 'Black Bear'
|
29
|
+
}, {
|
30
|
+
title: 'Brown Bear'
|
31
|
+
}]
|
32
|
+
}, {
|
33
|
+
title: 'Kangaroo'
|
34
|
+
}, {
|
35
|
+
title: 'Snake'
|
36
|
+
}]
|
37
|
+
}, {
|
38
|
+
title: 'Plant'
|
39
|
+
}];
|
40
|
+
var TreeViewComponent = function TreeViewComponent(props) {
|
41
|
+
var tree = useTreeData({
|
42
|
+
initialItems: data,
|
43
|
+
getKey: function getKey(item) {
|
44
|
+
return item.title;
|
45
|
+
},
|
46
|
+
getChildren: function getChildren(item) {
|
47
|
+
return item.items;
|
48
|
+
}
|
49
|
+
});
|
50
|
+
return ___EmotionJSX(TreeView, _extends({}, defaultProps, props, {
|
51
|
+
items: tree.items,
|
52
|
+
tree: tree
|
53
|
+
}), function (section) {
|
54
|
+
var _section$children;
|
55
|
+
return SectionOrItemRender(((_section$children = section.children) === null || _section$children === void 0 ? void 0 : _section$children.length) > 0, ___EmotionJSX(Section, {
|
56
|
+
key: section.key,
|
57
|
+
items: section.children,
|
58
|
+
title: section.key,
|
59
|
+
customProp: {
|
60
|
+
testp: 1
|
61
|
+
}
|
62
|
+
}), ___EmotionJSX(Item, {
|
63
|
+
key: section.key,
|
64
|
+
title: section.key
|
65
|
+
}));
|
66
|
+
});
|
67
|
+
};
|
68
|
+
test('Can select an Item using the mouse', function () {
|
69
|
+
render(___EmotionJSX(TreeViewComponent, null));
|
70
|
+
var element = screen.getByTestId(testId);
|
71
|
+
expect(element).toBeInTheDocument();
|
72
|
+
var peopleElement = screen.getByText('People');
|
73
|
+
expect(peopleElement).not.toHaveClass('is-selected');
|
74
|
+
fireEvent.click(peopleElement);
|
75
|
+
expect(peopleElement).toHaveClass('is-selected');
|
76
|
+
});
|
77
|
+
test('Renders both Sections and Items', function () {
|
78
|
+
render(___EmotionJSX(TreeViewComponent, null));
|
79
|
+
var peopleElement = screen.getByText('People');
|
80
|
+
expect(peopleElement).toBeInTheDocument();
|
81
|
+
var plantElement = screen.getByText('Plant');
|
82
|
+
expect(plantElement).toBeInTheDocument();
|
83
|
+
var allListItems = screen.getAllByRole('treeitem');
|
84
|
+
expect(allListItems).toHaveLength(3);
|
85
|
+
});
|
86
|
+
test('Can expand an Item using the mouse', function () {
|
87
|
+
render(___EmotionJSX(TreeViewComponent, null));
|
88
|
+
|
89
|
+
// The children of collapsed sections will not
|
90
|
+
// be rendered by default.
|
91
|
+
expect(screen.queryByText(data[0].items[0].title)).not.toBeInTheDocument();
|
92
|
+
|
93
|
+
// Clicking the dropdown icon, renders the children
|
94
|
+
// of the collapsed section.
|
95
|
+
var buttons = screen.queryAllByRole('button');
|
96
|
+
fireEvent.click(buttons[0]);
|
97
|
+
expect(screen.queryByText(data[0].items[0].title)).toBeInTheDocument();
|
98
|
+
});
|
99
|
+
test('onExpandedChange change prop calls when used', function () {
|
100
|
+
var onPress = jest.fn();
|
101
|
+
render(___EmotionJSX(TreeViewComponent, {
|
102
|
+
onExpandedChange: onPress
|
103
|
+
}));
|
104
|
+
expect(onPress).not.toHaveBeenCalled();
|
105
|
+
var buttons = screen.queryAllByRole('button');
|
106
|
+
fireEvent.click(buttons[0]);
|
107
|
+
expect(onPress).toHaveBeenCalled();
|
108
|
+
});
|
109
|
+
test('disabledKeys prop disables items in the tree -- rendering them unclickable', function () {
|
110
|
+
render(___EmotionJSX(TreeViewComponent, {
|
111
|
+
disabledKeys: ['Plant']
|
112
|
+
}));
|
113
|
+
var listItems = screen.getAllByRole('treeitem');
|
114
|
+
var thisItem = listItems[2];
|
115
|
+
expect(thisItem).not.toHaveClass('is-selected');
|
116
|
+
expect(thisItem).toHaveAttribute('aria-disabled', 'true');
|
117
|
+
fireEvent.mouseDown(thisItem);
|
118
|
+
fireEvent.mouseUp(thisItem);
|
119
|
+
expect(thisItem).not.toHaveClass('is-selected');
|
120
|
+
expect(thisItem).toHaveAttribute('aria-selected', 'false');
|
121
|
+
});
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
2
|
+
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
3
|
+
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
|
4
|
+
import FileIcon from '@pingux/mdi-react/FileIcon';
|
5
|
+
import PropTypes from 'prop-types';
|
6
|
+
import { useTreeViewContext } from '../../context/TreeViewContext';
|
7
|
+
import { Box } from '../../index';
|
8
|
+
import TreeViewRow from './TreeViewRow';
|
9
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
10
|
+
var TreeViewItem = /*#__PURE__*/forwardRef(function (props, ref) {
|
11
|
+
var _context, _context2, _context3;
|
12
|
+
var item = props.item,
|
13
|
+
title = props.title;
|
14
|
+
var treeItemRef = useRef();
|
15
|
+
/* istanbul ignore next */
|
16
|
+
useImperativeHandle(ref, function () {
|
17
|
+
return treeItemRef.current;
|
18
|
+
});
|
19
|
+
var _useTreeViewContext = useTreeViewContext(),
|
20
|
+
state = _useTreeViewContext.state,
|
21
|
+
tree = _useTreeViewContext.tree;
|
22
|
+
var isExpanded = _includesInstanceProperty(_context = _Array$from(state.expandedKeys)).call(_context, item.key);
|
23
|
+
var isSelected = _includesInstanceProperty(_context2 = _Array$from(tree.selectedKeys)).call(_context2, item.key);
|
24
|
+
var isDisabled = _includesInstanceProperty(_context3 = _Array$from(state.disabledKeys)).call(_context3, item.key);
|
25
|
+
|
26
|
+
// this component may seem unnecessary, but it will be where the
|
27
|
+
// useOption and dragAndDrop stuff will go
|
28
|
+
// this comment will be removed at that time.
|
29
|
+
|
30
|
+
return ___EmotionJSX(Box, {
|
31
|
+
as: "li",
|
32
|
+
isRow: true,
|
33
|
+
ref: treeItemRef,
|
34
|
+
role: "treeitem",
|
35
|
+
"aria-selected": isSelected,
|
36
|
+
"aria-disabled": isDisabled,
|
37
|
+
sx: {
|
38
|
+
width: '100%',
|
39
|
+
ml: '36px',
|
40
|
+
':not(:last-child)': {
|
41
|
+
pb: 'sm'
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}, ___EmotionJSX(TreeViewRow, {
|
45
|
+
item: item,
|
46
|
+
title: title,
|
47
|
+
mainIcon: FileIcon,
|
48
|
+
isSelected: isSelected,
|
49
|
+
isExpanded: isExpanded,
|
50
|
+
isDisabled: isDisabled
|
51
|
+
}));
|
52
|
+
});
|
53
|
+
TreeViewItem.propTypes = {
|
54
|
+
item: PropTypes.shape({
|
55
|
+
key: PropTypes.string
|
56
|
+
}),
|
57
|
+
name: PropTypes.string,
|
58
|
+
title: PropTypes.string
|
59
|
+
};
|
60
|
+
export default TreeViewItem;
|