@automattic/vip-design-system 0.23.7 → 0.25.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/build/system/Accordion/Accordion.js +246 -0
- package/build/system/Accordion/Accordion.stories.js +83 -0
- package/build/system/Accordion/Accordion.test.js +129 -0
- package/build/system/Accordion/index.js +12 -0
- package/build/system/NewForm/FormAutocomplete.js +206 -0
- package/build/system/NewForm/FormAutocomplete.stories.js +127 -0
- package/build/system/NewForm/FormAutocomplete.test.js +69 -0
- package/build/system/NewForm/index.js +5 -1
- package/build/system/index.js +4 -0
- package/build/system/theme/getColor.js +21 -2
- package/build/system/theme/index.js +5 -0
- package/package.json +6 -1
- package/src/system/Accordion/Accordion.js +198 -0
- package/src/system/Accordion/Accordion.stories.jsx +55 -0
- package/src/system/Accordion/Accordion.test.js +61 -0
- package/src/system/Accordion/index.js +6 -0
- package/src/system/NewForm/FormAutocomplete.css +166 -0
- package/src/system/NewForm/FormAutocomplete.js +182 -0
- package/src/system/NewForm/FormAutocomplete.stories.jsx +89 -0
- package/src/system/NewForm/FormAutocomplete.test.js +32 -0
- package/src/system/NewForm/FormSelect.stories.jsx +1 -1
- package/src/system/NewForm/index.js +3 -1
- package/src/system/index.js +2 -0
- package/src/system/theme/getColor.js +14 -0
- package/src/system/theme/index.js +7 -1
- package/test/fileMock.js +1 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.TriggerWithIcon = exports.Trigger = exports.Root = exports.Item = exports.Content = void 0;
|
|
7
|
+
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
|
|
10
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
|
|
14
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
+
|
|
16
|
+
var _md = require("react-icons/md");
|
|
17
|
+
|
|
18
|
+
var AccordionPrimitive = _interopRequireWildcard(require("@radix-ui/react-accordion"));
|
|
19
|
+
|
|
20
|
+
var _react2 = require("@emotion/react");
|
|
21
|
+
|
|
22
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
23
|
+
|
|
24
|
+
var _Heading = require("../Heading");
|
|
25
|
+
|
|
26
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
27
|
+
|
|
28
|
+
var _excluded = ["children"],
|
|
29
|
+
_excluded2 = ["children", "headingVariant"],
|
|
30
|
+
_excluded3 = ["children", "icon"],
|
|
31
|
+
_excluded4 = ["children", "sx"];
|
|
32
|
+
|
|
33
|
+
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); }
|
|
34
|
+
|
|
35
|
+
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; }
|
|
36
|
+
|
|
37
|
+
var slideDown = (0, _react2.keyframes)({
|
|
38
|
+
from: {
|
|
39
|
+
height: 0
|
|
40
|
+
},
|
|
41
|
+
to: {
|
|
42
|
+
height: 'var(--radix-accordion-content-height)'
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
var slideUp = (0, _react2.keyframes)({
|
|
46
|
+
from: {
|
|
47
|
+
height: 'var(--radix-accordion-content-height)'
|
|
48
|
+
},
|
|
49
|
+
to: {
|
|
50
|
+
height: 0
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
var Item = function Item(_ref) {
|
|
55
|
+
var children = _ref.children,
|
|
56
|
+
props = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
|
|
57
|
+
return (0, _jsxRuntime.jsx)(AccordionPrimitive.Item, (0, _extends2["default"])({}, props, {
|
|
58
|
+
sx: {
|
|
59
|
+
overflow: 'hidden',
|
|
60
|
+
borderWidth: '0 1px 1px 1px',
|
|
61
|
+
borderStyle: 'solid',
|
|
62
|
+
borderColor: 'border',
|
|
63
|
+
'&:first-of-type': {
|
|
64
|
+
borderTopWidth: '1px',
|
|
65
|
+
borderTopLeftRadius: 4,
|
|
66
|
+
borderTopRightRadius: 4
|
|
67
|
+
},
|
|
68
|
+
'&:last-child': {
|
|
69
|
+
borderBottomLeftRadius: 4,
|
|
70
|
+
borderBottomRightRadius: 4
|
|
71
|
+
},
|
|
72
|
+
'&:focus-within': function focusWithin(theme) {
|
|
73
|
+
return theme.outline;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
children: children
|
|
77
|
+
}));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
exports.Item = Item;
|
|
81
|
+
Item.displayName = 'Accordion.Item';
|
|
82
|
+
Item.propTypes = {
|
|
83
|
+
children: _propTypes["default"].node.isRequired
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
var Trigger = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, forwardedRef) {
|
|
87
|
+
var children = _ref2.children,
|
|
88
|
+
_ref2$headingVariant = _ref2.headingVariant,
|
|
89
|
+
headingVariant = _ref2$headingVariant === void 0 ? 'h3' : _ref2$headingVariant,
|
|
90
|
+
props = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, _excluded2);
|
|
91
|
+
return (0, _jsxRuntime.jsx)(_Heading.Heading, {
|
|
92
|
+
sx: {
|
|
93
|
+
all: 'unset',
|
|
94
|
+
display: 'flex'
|
|
95
|
+
},
|
|
96
|
+
variant: headingVariant,
|
|
97
|
+
children: (0, _jsxRuntime.jsxs)(AccordionPrimitive.Trigger, (0, _extends2["default"])({
|
|
98
|
+
sx: {
|
|
99
|
+
color: 'heading',
|
|
100
|
+
cursor: 'pointer',
|
|
101
|
+
all: 'unset',
|
|
102
|
+
fontFamily: 'inherit',
|
|
103
|
+
px: 3,
|
|
104
|
+
height: 45,
|
|
105
|
+
flex: 1,
|
|
106
|
+
display: 'flex',
|
|
107
|
+
alignItems: 'center',
|
|
108
|
+
justifyContent: 'space-between',
|
|
109
|
+
fontSize: 1,
|
|
110
|
+
fontWeight: 600,
|
|
111
|
+
textTransform: 'uppercase',
|
|
112
|
+
'&[data-state="closed"]': {
|
|
113
|
+
backgroundColor: 'transparent'
|
|
114
|
+
},
|
|
115
|
+
'&[data-state="open"]': {
|
|
116
|
+
backgroundColor: 'backgroundSecondary',
|
|
117
|
+
borderBottom: function borderBottom(theme) {
|
|
118
|
+
return "1px solid " + theme.colors.border;
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
'&:hover': {
|
|
122
|
+
backgroundColor: 'backgroundSecondary'
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, props, {
|
|
126
|
+
ref: forwardedRef,
|
|
127
|
+
children: [children, (0, _jsxRuntime.jsx)(_md.MdChevronRight, {
|
|
128
|
+
sx: {
|
|
129
|
+
fontSize: 3,
|
|
130
|
+
color: 'text',
|
|
131
|
+
transform: 'rotate(90deg)',
|
|
132
|
+
transition: 'transform 300ms cubic-bezier(0.87, 0, 0.13, 1)',
|
|
133
|
+
'[data-state=open] &': {
|
|
134
|
+
transform: 'rotate(270deg)'
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
"aria-hidden": true
|
|
138
|
+
})]
|
|
139
|
+
}))
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
exports.Trigger = Trigger;
|
|
144
|
+
Trigger.displayName = 'Accordion.Trigger';
|
|
145
|
+
Trigger.propTypes = {
|
|
146
|
+
children: _propTypes["default"].node.isRequired,
|
|
147
|
+
headingVariant: _propTypes["default"].string
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
var TriggerWithIcon = /*#__PURE__*/_react["default"].forwardRef(function (_ref3, forwardedRef) {
|
|
151
|
+
var children = _ref3.children,
|
|
152
|
+
icon = _ref3.icon,
|
|
153
|
+
props = (0, _objectWithoutPropertiesLoose2["default"])(_ref3, _excluded3);
|
|
154
|
+
return (0, _jsxRuntime.jsxs)(Trigger, (0, _extends2["default"])({}, props, {
|
|
155
|
+
ref: forwardedRef,
|
|
156
|
+
children: [(0, _jsxRuntime.jsx)("span", {
|
|
157
|
+
sx: {
|
|
158
|
+
color: 'text',
|
|
159
|
+
fontSize: 3
|
|
160
|
+
},
|
|
161
|
+
children: icon
|
|
162
|
+
}), (0, _jsxRuntime.jsx)("div", {
|
|
163
|
+
sx: {
|
|
164
|
+
color: 'heading',
|
|
165
|
+
flexGrow: 1,
|
|
166
|
+
textAlign: 'left',
|
|
167
|
+
ml: 3
|
|
168
|
+
},
|
|
169
|
+
children: children
|
|
170
|
+
})]
|
|
171
|
+
}));
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
exports.TriggerWithIcon = TriggerWithIcon;
|
|
175
|
+
TriggerWithIcon.displayName = 'Accordion.TriggerWithIcon';
|
|
176
|
+
TriggerWithIcon.propTypes = {
|
|
177
|
+
children: _propTypes["default"].node.isRequired,
|
|
178
|
+
icon: _propTypes["default"].node.isRequired
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
var Content = /*#__PURE__*/_react["default"].forwardRef(function (_ref4, forwardedRef) {
|
|
182
|
+
var children = _ref4.children,
|
|
183
|
+
_ref4$sx = _ref4.sx,
|
|
184
|
+
sx = _ref4$sx === void 0 ? {} : _ref4$sx,
|
|
185
|
+
props = (0, _objectWithoutPropertiesLoose2["default"])(_ref4, _excluded4);
|
|
186
|
+
return (0, _jsxRuntime.jsx)(AccordionPrimitive.Content, (0, _extends2["default"])({
|
|
187
|
+
sx: (0, _extends2["default"])({
|
|
188
|
+
backgroundColor: 'transparent',
|
|
189
|
+
color: 'text',
|
|
190
|
+
fontSize: 2,
|
|
191
|
+
overflow: 'hidden',
|
|
192
|
+
'&[data-state="open"]': {
|
|
193
|
+
animation: slideDown + " 300ms cubic-bezier(0.87, 0, 0.13, 1)"
|
|
194
|
+
},
|
|
195
|
+
'&[data-state="closed"]': {
|
|
196
|
+
animation: slideUp + " 300ms cubic-bezier(0.87, 0, 0.13, 1)"
|
|
197
|
+
}
|
|
198
|
+
}, sx)
|
|
199
|
+
}, props, {
|
|
200
|
+
ref: forwardedRef,
|
|
201
|
+
children: (0, _jsxRuntime.jsx)("div", {
|
|
202
|
+
sx: {
|
|
203
|
+
px: 3,
|
|
204
|
+
py: 2
|
|
205
|
+
},
|
|
206
|
+
children: children
|
|
207
|
+
})
|
|
208
|
+
}));
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
exports.Content = Content;
|
|
212
|
+
Content.displayName = 'Accordion.Content';
|
|
213
|
+
Content.propTypes = {
|
|
214
|
+
children: _propTypes["default"].node.isRequired,
|
|
215
|
+
sx: _propTypes["default"].object
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
var Root = /*#__PURE__*/_react["default"].forwardRef(function (_ref5, forwardRef) {
|
|
219
|
+
var _ref5$sx = _ref5.sx,
|
|
220
|
+
sx = _ref5$sx === void 0 ? {} : _ref5$sx,
|
|
221
|
+
defaultValue = _ref5.defaultValue,
|
|
222
|
+
type = _ref5.type,
|
|
223
|
+
children = _ref5.children,
|
|
224
|
+
className = _ref5.className;
|
|
225
|
+
return (0, _jsxRuntime.jsx)(AccordionPrimitive.Root, {
|
|
226
|
+
className: (0, _classnames["default"])('vip-accordion-component', className),
|
|
227
|
+
collapsible: true,
|
|
228
|
+
defaultValue: defaultValue,
|
|
229
|
+
ref: forwardRef,
|
|
230
|
+
sx: (0, _extends2["default"])({
|
|
231
|
+
borderRadius: 6
|
|
232
|
+
}, sx),
|
|
233
|
+
type: type,
|
|
234
|
+
children: children
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
exports.Root = Root;
|
|
239
|
+
Root.displayName = 'Accordion';
|
|
240
|
+
Root.propTypes = {
|
|
241
|
+
children: _propTypes["default"].node,
|
|
242
|
+
className: _propTypes["default"].any,
|
|
243
|
+
defaultValue: _propTypes["default"].any,
|
|
244
|
+
sx: _propTypes["default"].object,
|
|
245
|
+
type: _propTypes["default"].oneOf(['single', 'multiple'])
|
|
246
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports["default"] = exports.Default = void 0;
|
|
5
|
+
|
|
6
|
+
var _ri = require("react-icons/ri");
|
|
7
|
+
|
|
8
|
+
var _bi = require("react-icons/bi");
|
|
9
|
+
|
|
10
|
+
var _ = require("..");
|
|
11
|
+
|
|
12
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
13
|
+
|
|
14
|
+
/** @jsxImportSource theme-ui */
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* External dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
var _default = {
|
|
24
|
+
title: 'Accordion',
|
|
25
|
+
component: _.Accordion
|
|
26
|
+
};
|
|
27
|
+
exports["default"] = _default;
|
|
28
|
+
|
|
29
|
+
var ExampleContent = function ExampleContent() {
|
|
30
|
+
return (0, _jsxRuntime.jsxs)(_.Box, {
|
|
31
|
+
children: [(0, _jsxRuntime.jsx)("p", {
|
|
32
|
+
sx: {
|
|
33
|
+
mt: 0
|
|
34
|
+
},
|
|
35
|
+
children: "Add your key team members to the VIP Dashboard."
|
|
36
|
+
}), (0, _jsxRuntime.jsx)("p", {
|
|
37
|
+
children: "Add developers to GitHub."
|
|
38
|
+
}), (0, _jsxRuntime.jsx)("p", {
|
|
39
|
+
sx: {
|
|
40
|
+
mb: 0
|
|
41
|
+
},
|
|
42
|
+
children: "Add content editors and developers to WordPress admin."
|
|
43
|
+
})]
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
var Default = function Default() {
|
|
48
|
+
return (0, _jsxRuntime.jsx)(_.Box, {
|
|
49
|
+
children: (0, _jsxRuntime.jsxs)(_.Accordion.Root, {
|
|
50
|
+
defaultValue: "teamPermissions",
|
|
51
|
+
sx: {
|
|
52
|
+
width: '450px'
|
|
53
|
+
},
|
|
54
|
+
children: [(0, _jsxRuntime.jsxs)(_.Accordion.Item, {
|
|
55
|
+
value: "teamPermissions",
|
|
56
|
+
children: [(0, _jsxRuntime.jsx)(_.Accordion.TriggerWithIcon, {
|
|
57
|
+
icon: (0, _jsxRuntime.jsx)(_ri.RiUserAddLine, {}),
|
|
58
|
+
children: "Team & Permissions"
|
|
59
|
+
}), (0, _jsxRuntime.jsx)(_.Accordion.Content, {
|
|
60
|
+
children: (0, _jsxRuntime.jsx)(ExampleContent, {})
|
|
61
|
+
})]
|
|
62
|
+
}), (0, _jsxRuntime.jsxs)(_.Accordion.Item, {
|
|
63
|
+
value: "addContentMedia",
|
|
64
|
+
children: [(0, _jsxRuntime.jsx)(_.Accordion.TriggerWithIcon, {
|
|
65
|
+
icon: (0, _jsxRuntime.jsx)(_bi.BiBookContent, {}),
|
|
66
|
+
children: "Add Content & Media"
|
|
67
|
+
}), (0, _jsxRuntime.jsx)(_.Accordion.Content, {
|
|
68
|
+
children: (0, _jsxRuntime.jsx)(ExampleContent, {})
|
|
69
|
+
})]
|
|
70
|
+
}), (0, _jsxRuntime.jsxs)(_.Accordion.Item, {
|
|
71
|
+
value: "addCode",
|
|
72
|
+
children: [(0, _jsxRuntime.jsx)(_.Accordion.TriggerWithIcon, {
|
|
73
|
+
icon: (0, _jsxRuntime.jsx)(_ri.RiCodeSSlashFill, {}),
|
|
74
|
+
children: "Add Code"
|
|
75
|
+
}), (0, _jsxRuntime.jsx)(_.Accordion.Content, {
|
|
76
|
+
children: (0, _jsxRuntime.jsx)(ExampleContent, {})
|
|
77
|
+
})]
|
|
78
|
+
})]
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
exports.Default = Default;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
6
|
+
|
|
7
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
8
|
+
|
|
9
|
+
var _react = require("@testing-library/react");
|
|
10
|
+
|
|
11
|
+
var _jestAxe = require("jest-axe");
|
|
12
|
+
|
|
13
|
+
var _themeUi = require("theme-ui");
|
|
14
|
+
|
|
15
|
+
var Accordion = _interopRequireWildcard(require("./Accordion"));
|
|
16
|
+
|
|
17
|
+
var _ = require("../");
|
|
18
|
+
|
|
19
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
20
|
+
|
|
21
|
+
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); }
|
|
22
|
+
|
|
23
|
+
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; }
|
|
24
|
+
|
|
25
|
+
/** @jsxImportSource theme-ui */
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* External dependencies
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Internal dependencies
|
|
33
|
+
*/
|
|
34
|
+
var renderWithTheme = function renderWithTheme(children) {
|
|
35
|
+
return (0, _react.render)((0, _jsxRuntime.jsx)(_themeUi.ThemeProvider, {
|
|
36
|
+
theme: _.theme,
|
|
37
|
+
children: children
|
|
38
|
+
}));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var renderComponent = function renderComponent() {
|
|
42
|
+
return renderWithTheme((0, _jsxRuntime.jsxs)(Accordion.Root, {
|
|
43
|
+
defaultValue: "one",
|
|
44
|
+
sx: {
|
|
45
|
+
width: '400px'
|
|
46
|
+
},
|
|
47
|
+
children: [(0, _jsxRuntime.jsxs)(Accordion.Item, {
|
|
48
|
+
value: "one",
|
|
49
|
+
children: [(0, _jsxRuntime.jsx)(Accordion.Trigger, {
|
|
50
|
+
children: "trigger one"
|
|
51
|
+
}), (0, _jsxRuntime.jsx)(Accordion.Content, {
|
|
52
|
+
children: "content one"
|
|
53
|
+
})]
|
|
54
|
+
}), (0, _jsxRuntime.jsxs)(Accordion.Item, {
|
|
55
|
+
value: "two",
|
|
56
|
+
children: [(0, _jsxRuntime.jsx)(Accordion.Trigger, {
|
|
57
|
+
children: "trigger two"
|
|
58
|
+
}), (0, _jsxRuntime.jsx)(Accordion.Content, {
|
|
59
|
+
children: "content two"
|
|
60
|
+
})]
|
|
61
|
+
})]
|
|
62
|
+
}));
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
describe('<Accordion />', function () {
|
|
66
|
+
it('renders the Accordion component with default value visible', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
67
|
+
var _renderComponent, container;
|
|
68
|
+
|
|
69
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
70
|
+
while (1) {
|
|
71
|
+
switch (_context.prev = _context.next) {
|
|
72
|
+
case 0:
|
|
73
|
+
_renderComponent = renderComponent(), container = _renderComponent.container; // Should find the open content
|
|
74
|
+
|
|
75
|
+
expect(_react.screen.getByText('content one')).toBeInTheDocument(); // Should not find the closed content
|
|
76
|
+
|
|
77
|
+
expect(_react.screen.queryByText('content two')).toBeNull(); // Check for accessibility issues
|
|
78
|
+
|
|
79
|
+
_context.t0 = expect;
|
|
80
|
+
_context.next = 6;
|
|
81
|
+
return (0, _jestAxe.axe)(container);
|
|
82
|
+
|
|
83
|
+
case 6:
|
|
84
|
+
_context.t1 = _context.sent;
|
|
85
|
+
_context.next = 9;
|
|
86
|
+
return (0, _context.t0)(_context.t1).toHaveNoViolations();
|
|
87
|
+
|
|
88
|
+
case 9:
|
|
89
|
+
case "end":
|
|
90
|
+
return _context.stop();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}, _callee);
|
|
94
|
+
})));
|
|
95
|
+
it('should open the content when clicking on its trigger', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
96
|
+
var _renderComponent2, container;
|
|
97
|
+
|
|
98
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
99
|
+
while (1) {
|
|
100
|
+
switch (_context2.prev = _context2.next) {
|
|
101
|
+
case 0:
|
|
102
|
+
_renderComponent2 = renderComponent(), container = _renderComponent2.container;
|
|
103
|
+
|
|
104
|
+
_react.fireEvent.click(_react.screen.getByRole('button', {
|
|
105
|
+
name: 'trigger two'
|
|
106
|
+
})); // Should find the open content
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
expect(_react.screen.queryByText('content one')).toBeNull(); // Should not find the closed content
|
|
110
|
+
|
|
111
|
+
expect(_react.screen.queryByText('content two')).toBeInTheDocument(); // Check for accessibility issues
|
|
112
|
+
|
|
113
|
+
_context2.t0 = expect;
|
|
114
|
+
_context2.next = 7;
|
|
115
|
+
return (0, _jestAxe.axe)(container);
|
|
116
|
+
|
|
117
|
+
case 7:
|
|
118
|
+
_context2.t1 = _context2.sent;
|
|
119
|
+
_context2.next = 10;
|
|
120
|
+
return (0, _context2.t0)(_context2.t1).toHaveNoViolations();
|
|
121
|
+
|
|
122
|
+
case 10:
|
|
123
|
+
case "end":
|
|
124
|
+
return _context2.stop();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}, _callee2);
|
|
128
|
+
})));
|
|
129
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.Accordion = void 0;
|
|
5
|
+
|
|
6
|
+
var Accordion = _interopRequireWildcard(require("./Accordion"));
|
|
7
|
+
|
|
8
|
+
exports.Accordion = Accordion;
|
|
9
|
+
|
|
10
|
+
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); }
|
|
11
|
+
|
|
12
|
+
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; }
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.FormAutocomplete = void 0;
|
|
7
|
+
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
|
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
+
|
|
14
|
+
var _Label = require("../Form/Label");
|
|
15
|
+
|
|
16
|
+
var _react2 = _interopRequireDefault(require("accessible-autocomplete/react"));
|
|
17
|
+
|
|
18
|
+
var _FormAutocomplete = _interopRequireDefault(require("./FormAutocomplete.css"));
|
|
19
|
+
|
|
20
|
+
exports.css = _FormAutocomplete["default"];
|
|
21
|
+
|
|
22
|
+
var _FormSelectContent = require("./FormSelectContent");
|
|
23
|
+
|
|
24
|
+
var _FormSelectArrow = require("./FormSelectArrow");
|
|
25
|
+
|
|
26
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
27
|
+
|
|
28
|
+
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); }
|
|
29
|
+
|
|
30
|
+
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
|
+
|
|
32
|
+
/** @jsxImportSource theme-ui */
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* External dependencies
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Internal dependencies
|
|
40
|
+
*/
|
|
41
|
+
var defaultStyles = {
|
|
42
|
+
width: '100%',
|
|
43
|
+
py: 0,
|
|
44
|
+
borderWidth: '1px',
|
|
45
|
+
borderStyle: 'solid',
|
|
46
|
+
borderColor: 'border',
|
|
47
|
+
borderRadius: 1,
|
|
48
|
+
backgroundColor: 'background',
|
|
49
|
+
color: 'text',
|
|
50
|
+
minHeight: '36px',
|
|
51
|
+
lineHeight: '36px',
|
|
52
|
+
'&:focus': function focus(theme) {
|
|
53
|
+
return theme.outline;
|
|
54
|
+
},
|
|
55
|
+
'&:focus-visible': function focusVisible(theme) {
|
|
56
|
+
return theme.outline;
|
|
57
|
+
},
|
|
58
|
+
'&:focus-within': function focusWithin(theme) {
|
|
59
|
+
return theme.outline;
|
|
60
|
+
},
|
|
61
|
+
'&.autocomplete__input--focused': function autocomplete__inputFocused(theme) {
|
|
62
|
+
return theme.outline;
|
|
63
|
+
},
|
|
64
|
+
'& .autocomplete__input': {
|
|
65
|
+
width: '100%',
|
|
66
|
+
paddingLeft: 3,
|
|
67
|
+
py: 0,
|
|
68
|
+
borderWidth: 0,
|
|
69
|
+
color: 'text',
|
|
70
|
+
minHeight: '36px',
|
|
71
|
+
lineHeight: '36px',
|
|
72
|
+
'&:focus': {
|
|
73
|
+
outlineWidth: 0,
|
|
74
|
+
boxShadow: 'none'
|
|
75
|
+
},
|
|
76
|
+
'&:focus-visible': {
|
|
77
|
+
outlineWidth: 0,
|
|
78
|
+
boxShadow: 'none'
|
|
79
|
+
},
|
|
80
|
+
'&:focus-within': {
|
|
81
|
+
outlineWidth: 0,
|
|
82
|
+
boxShadow: 'none'
|
|
83
|
+
},
|
|
84
|
+
'&.autocomplete__input--focused': {
|
|
85
|
+
outlineWidth: 0,
|
|
86
|
+
boxShadow: 'none'
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
'& .autocomplete__menu': {
|
|
90
|
+
borderWidth: '1px',
|
|
91
|
+
borderStyle: 'solid',
|
|
92
|
+
borderColor: 'border',
|
|
93
|
+
borderRadius: 1,
|
|
94
|
+
backgroundColor: 'background',
|
|
95
|
+
color: 'text'
|
|
96
|
+
},
|
|
97
|
+
'& .autocomplete__hint, & .autocomplete__input, & .autocomplete__option': {
|
|
98
|
+
fontSize: 'inherit'
|
|
99
|
+
},
|
|
100
|
+
'& .autocomplete__wrapper': {
|
|
101
|
+
width: '100%',
|
|
102
|
+
paddingRight: '40px'
|
|
103
|
+
},
|
|
104
|
+
'& .autocomplete__input--show-all-values': {
|
|
105
|
+
paddingRight: 0
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var inlineStyles = {
|
|
109
|
+
borderWidth: 0
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref, forwardRef) {
|
|
113
|
+
var isInline = _ref.isInline,
|
|
114
|
+
forLabel = _ref.forLabel,
|
|
115
|
+
options = _ref.options,
|
|
116
|
+
label = _ref.label,
|
|
117
|
+
getOptionValue = _ref.getOptionValue,
|
|
118
|
+
onChange = _ref.onChange,
|
|
119
|
+
value = _ref.value,
|
|
120
|
+
_ref$showAllValues = _ref.showAllValues,
|
|
121
|
+
showAllValues = _ref$showAllValues === void 0 ? true : _ref$showAllValues,
|
|
122
|
+
_ref$displayMenu = _ref.displayMenu,
|
|
123
|
+
displayMenu = _ref$displayMenu === void 0 ? 'overlay' : _ref$displayMenu,
|
|
124
|
+
_ref$id = _ref.id,
|
|
125
|
+
id = _ref$id === void 0 ? 'vip-autocomplete' : _ref$id;
|
|
126
|
+
|
|
127
|
+
var SelectLabel = function SelectLabel() {
|
|
128
|
+
return (0, _jsxRuntime.jsx)(_Label.Label, {
|
|
129
|
+
htmlFor: forLabel || id,
|
|
130
|
+
children: label
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
var inlineLabel = !!(isInline && label);
|
|
135
|
+
var optionValue = (0, _react.useCallback)(function (option) {
|
|
136
|
+
return getOptionValue ? getOptionValue(option) : option.value;
|
|
137
|
+
}, [getOptionValue]);
|
|
138
|
+
var getAllOptions = (0, _react.useMemo)(function () {
|
|
139
|
+
return [].concat(options.filter(function (option) {
|
|
140
|
+
return !option.options;
|
|
141
|
+
}), options.filter(function (option) {
|
|
142
|
+
return option.options;
|
|
143
|
+
}).map(function (option) {
|
|
144
|
+
return option.options;
|
|
145
|
+
})).reduce(function (a, b) {
|
|
146
|
+
return a.concat(b);
|
|
147
|
+
}, []);
|
|
148
|
+
}, [options]);
|
|
149
|
+
var getOptionByValue = (0, _react.useCallback)(function (inputValue) {
|
|
150
|
+
return getAllOptions.find(function (option) {
|
|
151
|
+
return "" + optionValue(option) === "" + inputValue;
|
|
152
|
+
});
|
|
153
|
+
}, [getAllOptions, optionValue]);
|
|
154
|
+
var onValueChange = (0, _react.useCallback)(function (inputValue) {
|
|
155
|
+
if (onChange) {
|
|
156
|
+
onChange(getOptionByValue(inputValue));
|
|
157
|
+
}
|
|
158
|
+
}, [onChange, getOptionByValue]);
|
|
159
|
+
var suggest = (0, _react.useCallback)(function (query, populateResults) {
|
|
160
|
+
var data = options.filter(function (option) {
|
|
161
|
+
return option.label.toLowerCase().indexOf(query.toLowerCase()) >= 0;
|
|
162
|
+
});
|
|
163
|
+
populateResults(data.map(function (option) {
|
|
164
|
+
return option.label;
|
|
165
|
+
}));
|
|
166
|
+
}, [options]);
|
|
167
|
+
(0, _react.useEffect)(function () {
|
|
168
|
+
global.document.querySelector('.autocomplete__input').setAttribute('aria-activedescendant', '');
|
|
169
|
+
}, []);
|
|
170
|
+
(0, _react.useEffect)(function () {
|
|
171
|
+
global.document.querySelector('.autocomplete__menu').setAttribute('aria-label', label + " list");
|
|
172
|
+
}, [label]);
|
|
173
|
+
return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
174
|
+
children: [label && !isInline && (0, _jsxRuntime.jsx)(SelectLabel, {}), (0, _jsxRuntime.jsx)("div", {
|
|
175
|
+
sx: (0, _extends2["default"])({}, defaultStyles, isInline && inlineStyles),
|
|
176
|
+
children: (0, _jsxRuntime.jsxs)(_FormSelectContent.FormSelectContent, {
|
|
177
|
+
isInline: inlineLabel,
|
|
178
|
+
label: inlineLabel ? (0, _jsxRuntime.jsx)(SelectLabel, {}) : null,
|
|
179
|
+
children: [(0, _jsxRuntime.jsx)(_react2["default"], {
|
|
180
|
+
id: id,
|
|
181
|
+
showAllValues: showAllValues,
|
|
182
|
+
ref: forwardRef,
|
|
183
|
+
source: suggest,
|
|
184
|
+
defaultValue: value,
|
|
185
|
+
displayMenu: displayMenu,
|
|
186
|
+
onConfirm: onValueChange
|
|
187
|
+
}), (0, _jsxRuntime.jsx)(_FormSelectArrow.FormSelectArrow, {})]
|
|
188
|
+
})
|
|
189
|
+
})]
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
exports.FormAutocomplete = FormAutocomplete;
|
|
194
|
+
FormAutocomplete.propTypes = {
|
|
195
|
+
id: _propTypes["default"].string,
|
|
196
|
+
showAllValues: _propTypes["default"].bool,
|
|
197
|
+
isInline: _propTypes["default"].bool,
|
|
198
|
+
forLabel: _propTypes["default"].string,
|
|
199
|
+
value: _propTypes["default"].string,
|
|
200
|
+
displayMenu: _propTypes["default"].string,
|
|
201
|
+
label: _propTypes["default"].string,
|
|
202
|
+
options: _propTypes["default"].array,
|
|
203
|
+
getOptionValue: _propTypes["default"].func,
|
|
204
|
+
onChange: _propTypes["default"].func
|
|
205
|
+
};
|
|
206
|
+
FormAutocomplete.displayName = 'FormAutocomplete';
|