@automattic/vip-design-system 0.23.7 → 0.24.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/Form/MultiSelect.js +38 -0
- package/build/system/ResourceList/ResourceList.js +1 -1
- package/build/system/UsageChart/UsageChart.js +60 -0
- package/build/system/UsageChart/index.js +7 -0
- 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 +2 -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/index.js +2 -0
- package/src/system/theme/getColor.js +14 -0
- package/src/system/theme/index.js +7 -1
|
@@ -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,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.MultiSelect = void 0;
|
|
5
|
+
|
|
6
|
+
var _reactSelect = _interopRequireDefault(require("react-select"));
|
|
7
|
+
|
|
8
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
12
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
13
|
+
|
|
14
|
+
var vipGold = '#c29c69'; // hardcoding for now
|
|
15
|
+
|
|
16
|
+
var vipGrey2 = '#d7dee2';
|
|
17
|
+
var customStyles = {
|
|
18
|
+
control: function control(styles) {
|
|
19
|
+
return _extends({}, styles, {
|
|
20
|
+
border: "1px solid " + vipGrey2,
|
|
21
|
+
boxShadow: 'none',
|
|
22
|
+
'&:hover': {
|
|
23
|
+
border: "1px solid " + vipGold
|
|
24
|
+
},
|
|
25
|
+
'&:focus': {
|
|
26
|
+
border: "1px solid " + vipGold
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
var MultiSelect = function MultiSelect(props) {
|
|
33
|
+
return (0, _jsxRuntime.jsx)(_reactSelect["default"], _extends({}, props, {
|
|
34
|
+
styles: customStyles
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.MultiSelect = MultiSelect;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.UsageChart = void 0;
|
|
5
|
+
|
|
6
|
+
var _framerMotion = require("framer-motion");
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* External dependencies
|
|
16
|
+
*/
|
|
17
|
+
var UsageChart = function UsageChart(_ref) {
|
|
18
|
+
var total = _ref.total,
|
|
19
|
+
max = _ref.max,
|
|
20
|
+
_ref$variant = _ref.variant,
|
|
21
|
+
variant = _ref$variant === void 0 ? 'primary' : _ref$variant;
|
|
22
|
+
var width = total / max * 100 + '%';
|
|
23
|
+
var formattedTotal = total;
|
|
24
|
+
|
|
25
|
+
if (total > 1000000) {
|
|
26
|
+
formattedTotal = (total / 1000000).toFixed(2) + "M";
|
|
27
|
+
} else if (total > 1000) {
|
|
28
|
+
formattedTotal = (total / 1000).toFixed(2) + "K";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (0, _jsxRuntime.jsx)("div", {
|
|
32
|
+
sx: {
|
|
33
|
+
height: variant === 'primary' ? 32 : 8,
|
|
34
|
+
overflow: 'hidden',
|
|
35
|
+
backgroundColor: variant === 'primary' ? 'border' : 'transparent'
|
|
36
|
+
},
|
|
37
|
+
children: (0, _jsxRuntime.jsx)(_framerMotion.motion.div, {
|
|
38
|
+
initial: {
|
|
39
|
+
width: 0
|
|
40
|
+
},
|
|
41
|
+
animate: {
|
|
42
|
+
width: width
|
|
43
|
+
},
|
|
44
|
+
transition: {
|
|
45
|
+
duration: 0.7
|
|
46
|
+
},
|
|
47
|
+
sx: {
|
|
48
|
+
height: '100%',
|
|
49
|
+
backgroundColor: variant === 'primary' ? 'primary' : 'grey.40'
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
exports.UsageChart = UsageChart;
|
|
56
|
+
UsageChart.propTypes = {
|
|
57
|
+
total: _propTypes["default"].number,
|
|
58
|
+
max: _propTypes["default"].number,
|
|
59
|
+
variant: _propTypes["default"].string
|
|
60
|
+
};
|
package/build/system/index.js
CHANGED
|
@@ -81,6 +81,10 @@ exports.Select = _Form.Select;
|
|
|
81
81
|
exports.Textarea = _Form.Textarea;
|
|
82
82
|
exports.Checkbox = _Form.Checkbox;
|
|
83
83
|
|
|
84
|
+
var _Accordion = require("./Accordion");
|
|
85
|
+
|
|
86
|
+
exports.Accordion = _Accordion.Accordion;
|
|
87
|
+
|
|
84
88
|
var _Grid = require("./Grid");
|
|
85
89
|
|
|
86
90
|
exports.Grid = _Grid.Grid;
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
5
|
exports.__esModule = true;
|
|
6
|
-
exports.getColor = void 0;
|
|
6
|
+
exports.getVariants = exports.getColor = void 0;
|
|
7
|
+
|
|
8
|
+
var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
7
9
|
|
|
8
10
|
var _valetTheme = _interopRequireDefault(require("./generated/valet-theme.json"));
|
|
9
11
|
|
|
@@ -22,4 +24,21 @@ var getColor = function getColor(color, variant) {
|
|
|
22
24
|
return _valetTheme["default"][color][variant].value;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
|
-
exports.getColor = getColor;
|
|
27
|
+
exports.getColor = getColor;
|
|
28
|
+
|
|
29
|
+
var resolvePath = function resolvePath(object, path, defaultValue) {
|
|
30
|
+
return path.split('.').reduce(function (acc, property) {
|
|
31
|
+
return acc ? acc[property] : defaultValue;
|
|
32
|
+
}, object);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var getVariants = function getVariants(color) {
|
|
36
|
+
var property = resolvePath(_valetTheme["default"], color, {});
|
|
37
|
+
return Object.keys(property).reduce(function (variants, variant) {
|
|
38
|
+
var _extends2;
|
|
39
|
+
|
|
40
|
+
return (0, _extends3["default"])({}, variants, (_extends2 = {}, _extends2[variant] = property[variant].value, _extends2));
|
|
41
|
+
}, {});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
exports.getVariants = getVariants;
|
|
@@ -98,6 +98,8 @@ var _default = {
|
|
|
98
98
|
text: (0, _getColor.getColor)('text', 'secondary'),
|
|
99
99
|
heading: (0, _getColor.getColor)('text', 'primary'),
|
|
100
100
|
background: (0, _getColor.getColor)('background', 'primary'),
|
|
101
|
+
gold: (0, _getColor.getVariants)('color.gold'),
|
|
102
|
+
gray: (0, _getColor.getVariants)('color.gray'),
|
|
101
103
|
backgroundSecondary: _colors.light.grey['10'],
|
|
102
104
|
primary: _colors.light.brand['70'],
|
|
103
105
|
secondary: '#30c',
|
|
@@ -163,6 +165,9 @@ var _default = {
|
|
|
163
165
|
high: // eslint-disable-next-line max-len
|
|
164
166
|
'0px 2.76726px 2.21381px rgba(0, 0, 0, 0.0196802), 0px 6.6501px 5.32008px rgba(0, 0, 0, 0.0282725), 0px 12.5216px 10.0172px rgba(0, 0, 0, 0.035), 0px 22.3363px 17.869px rgba(0, 0, 0, 0.0417275), 0px 41.7776px 33.4221px rgba(0, 0, 0, 0.0503198), 0px 100px 80px rgba(0, 0, 0, 0.07)'
|
|
165
167
|
},
|
|
168
|
+
tag: {
|
|
169
|
+
gold: (0, _getColor.getVariants)('tag.gold')
|
|
170
|
+
},
|
|
166
171
|
cards: {
|
|
167
172
|
primary: {
|
|
168
173
|
padding: 3,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/vip-design-system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"main": "build/system/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build-storybook": "build-storybook",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"watch": "npm run build -- --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@radix-ui/react-accordion": "^1.0.1",
|
|
23
24
|
"@radix-ui/react-checkbox": "^1.0.0",
|
|
24
25
|
"@radix-ui/react-dialog": "^1.0.0",
|
|
25
26
|
"@radix-ui/react-dropdown-menu": "^1.0.1-rc.6",
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import { MdChevronRight } from 'react-icons/md';
|
|
9
|
+
import * as AccordionPrimitive from '@radix-ui/react-accordion';
|
|
10
|
+
import { keyframes } from '@emotion/react';
|
|
11
|
+
import classNames from 'classnames';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import { Heading } from '../Heading';
|
|
17
|
+
|
|
18
|
+
const slideDown = keyframes( {
|
|
19
|
+
from: { height: 0 },
|
|
20
|
+
to: { height: 'var(--radix-accordion-content-height)' },
|
|
21
|
+
} );
|
|
22
|
+
|
|
23
|
+
const slideUp = keyframes( {
|
|
24
|
+
from: { height: 'var(--radix-accordion-content-height)' },
|
|
25
|
+
to: { height: 0 },
|
|
26
|
+
} );
|
|
27
|
+
|
|
28
|
+
export const Item = ( { children, ...props } ) => (
|
|
29
|
+
<AccordionPrimitive.Item
|
|
30
|
+
{ ...props }
|
|
31
|
+
sx={ {
|
|
32
|
+
overflow: 'hidden',
|
|
33
|
+
borderWidth: '0 1px 1px 1px',
|
|
34
|
+
borderStyle: 'solid',
|
|
35
|
+
borderColor: 'border',
|
|
36
|
+
|
|
37
|
+
'&:first-of-type': {
|
|
38
|
+
borderTopWidth: '1px',
|
|
39
|
+
borderTopLeftRadius: 4,
|
|
40
|
+
borderTopRightRadius: 4,
|
|
41
|
+
},
|
|
42
|
+
'&:last-child': {
|
|
43
|
+
borderBottomLeftRadius: 4,
|
|
44
|
+
borderBottomRightRadius: 4,
|
|
45
|
+
},
|
|
46
|
+
'&:focus-within': theme => theme.outline,
|
|
47
|
+
} }
|
|
48
|
+
>
|
|
49
|
+
{ children }
|
|
50
|
+
</AccordionPrimitive.Item>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
Item.displayName = 'Accordion.Item';
|
|
54
|
+
|
|
55
|
+
Item.propTypes = {
|
|
56
|
+
children: PropTypes.node.isRequired,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const Trigger = React.forwardRef(
|
|
60
|
+
( { children, headingVariant = 'h3', ...props }, forwardedRef ) => (
|
|
61
|
+
<Heading
|
|
62
|
+
sx={ {
|
|
63
|
+
all: 'unset',
|
|
64
|
+
display: 'flex',
|
|
65
|
+
} }
|
|
66
|
+
variant={ headingVariant }
|
|
67
|
+
>
|
|
68
|
+
<AccordionPrimitive.Trigger
|
|
69
|
+
sx={ {
|
|
70
|
+
color: 'heading',
|
|
71
|
+
cursor: 'pointer',
|
|
72
|
+
all: 'unset',
|
|
73
|
+
fontFamily: 'inherit',
|
|
74
|
+
px: 3,
|
|
75
|
+
height: 45,
|
|
76
|
+
flex: 1,
|
|
77
|
+
display: 'flex',
|
|
78
|
+
alignItems: 'center',
|
|
79
|
+
justifyContent: 'space-between',
|
|
80
|
+
fontSize: 1,
|
|
81
|
+
fontWeight: 600,
|
|
82
|
+
textTransform: 'uppercase',
|
|
83
|
+
|
|
84
|
+
'&[data-state="closed"]': { backgroundColor: 'transparent' },
|
|
85
|
+
'&[data-state="open"]': {
|
|
86
|
+
backgroundColor: 'backgroundSecondary',
|
|
87
|
+
borderBottom: theme => `1px solid ${ theme.colors.border }`,
|
|
88
|
+
},
|
|
89
|
+
'&:hover': { backgroundColor: 'backgroundSecondary' },
|
|
90
|
+
} }
|
|
91
|
+
{ ...props }
|
|
92
|
+
ref={ forwardedRef }
|
|
93
|
+
>
|
|
94
|
+
{ children }
|
|
95
|
+
<MdChevronRight
|
|
96
|
+
sx={ {
|
|
97
|
+
fontSize: 3,
|
|
98
|
+
color: 'text',
|
|
99
|
+
transform: 'rotate(90deg)',
|
|
100
|
+
transition: 'transform 300ms cubic-bezier(0.87, 0, 0.13, 1)',
|
|
101
|
+
'[data-state=open] &': { transform: 'rotate(270deg)' },
|
|
102
|
+
} }
|
|
103
|
+
aria-hidden
|
|
104
|
+
/>
|
|
105
|
+
</AccordionPrimitive.Trigger>
|
|
106
|
+
</Heading>
|
|
107
|
+
)
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
Trigger.displayName = 'Accordion.Trigger';
|
|
111
|
+
|
|
112
|
+
Trigger.propTypes = {
|
|
113
|
+
children: PropTypes.node.isRequired,
|
|
114
|
+
headingVariant: PropTypes.string,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const TriggerWithIcon = React.forwardRef( ( { children, icon, ...props }, forwardedRef ) => (
|
|
118
|
+
<Trigger { ...props } ref={ forwardedRef }>
|
|
119
|
+
<span sx={ { color: 'text', fontSize: 3 } }>{ icon }</span>
|
|
120
|
+
<div sx={ { color: 'heading', flexGrow: 1, textAlign: 'left', ml: 3 } }>{ children }</div>
|
|
121
|
+
</Trigger>
|
|
122
|
+
) );
|
|
123
|
+
|
|
124
|
+
TriggerWithIcon.displayName = 'Accordion.TriggerWithIcon';
|
|
125
|
+
|
|
126
|
+
TriggerWithIcon.propTypes = {
|
|
127
|
+
children: PropTypes.node.isRequired,
|
|
128
|
+
icon: PropTypes.node.isRequired,
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const Content = React.forwardRef( ( { children, sx = {}, ...props }, forwardedRef ) => {
|
|
132
|
+
return (
|
|
133
|
+
<AccordionPrimitive.Content
|
|
134
|
+
sx={ {
|
|
135
|
+
backgroundColor: 'transparent',
|
|
136
|
+
color: 'text',
|
|
137
|
+
fontSize: 2,
|
|
138
|
+
overflow: 'hidden',
|
|
139
|
+
|
|
140
|
+
'&[data-state="open"]': {
|
|
141
|
+
animation: `${ slideDown } 300ms cubic-bezier(0.87, 0, 0.13, 1)`,
|
|
142
|
+
},
|
|
143
|
+
'&[data-state="closed"]': {
|
|
144
|
+
animation: `${ slideUp } 300ms cubic-bezier(0.87, 0, 0.13, 1)`,
|
|
145
|
+
},
|
|
146
|
+
...sx,
|
|
147
|
+
} }
|
|
148
|
+
{ ...props }
|
|
149
|
+
ref={ forwardedRef }
|
|
150
|
+
>
|
|
151
|
+
<div
|
|
152
|
+
sx={ {
|
|
153
|
+
px: 3,
|
|
154
|
+
py: 2,
|
|
155
|
+
} }
|
|
156
|
+
>
|
|
157
|
+
{ children }
|
|
158
|
+
</div>
|
|
159
|
+
</AccordionPrimitive.Content>
|
|
160
|
+
);
|
|
161
|
+
} );
|
|
162
|
+
|
|
163
|
+
Content.displayName = 'Accordion.Content';
|
|
164
|
+
|
|
165
|
+
Content.propTypes = {
|
|
166
|
+
children: PropTypes.node.isRequired,
|
|
167
|
+
sx: PropTypes.object,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const Root = React.forwardRef(
|
|
171
|
+
( { sx = {}, defaultValue, type, children, className }, forwardRef ) => (
|
|
172
|
+
<AccordionPrimitive.Root
|
|
173
|
+
className={ classNames( 'vip-accordion-component', className ) }
|
|
174
|
+
collapsible
|
|
175
|
+
defaultValue={ defaultValue }
|
|
176
|
+
ref={ forwardRef }
|
|
177
|
+
sx={ {
|
|
178
|
+
borderRadius: 6,
|
|
179
|
+
...sx,
|
|
180
|
+
} }
|
|
181
|
+
type={ type }
|
|
182
|
+
>
|
|
183
|
+
{ children }
|
|
184
|
+
</AccordionPrimitive.Root>
|
|
185
|
+
)
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
Root.displayName = 'Accordion';
|
|
189
|
+
|
|
190
|
+
Root.propTypes = {
|
|
191
|
+
children: PropTypes.node,
|
|
192
|
+
className: PropTypes.any,
|
|
193
|
+
defaultValue: PropTypes.any,
|
|
194
|
+
sx: PropTypes.object,
|
|
195
|
+
type: PropTypes.oneOf( [ 'single', 'multiple' ] ),
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export { Root };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { RiUserAddLine, RiCodeSSlashFill } from 'react-icons/ri';
|
|
7
|
+
import { BiBookContent } from 'react-icons/bi';
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { Box, Accordion } from '..';
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
title: 'Accordion',
|
|
15
|
+
component: Accordion,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const ExampleContent = () => (
|
|
19
|
+
<Box>
|
|
20
|
+
<p sx={ { mt: 0 } }>Add your key team members to the VIP Dashboard.</p>
|
|
21
|
+
<p>Add developers to GitHub.</p>
|
|
22
|
+
<p sx={ { mb: 0 } }>Add content editors and developers to WordPress admin.</p>
|
|
23
|
+
</Box>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const Default = () => (
|
|
27
|
+
<Box>
|
|
28
|
+
<Accordion.Root defaultValue="teamPermissions" sx={ { width: '450px' } }>
|
|
29
|
+
<Accordion.Item value="teamPermissions">
|
|
30
|
+
<Accordion.TriggerWithIcon icon={ <RiUserAddLine /> }>
|
|
31
|
+
Team & Permissions
|
|
32
|
+
</Accordion.TriggerWithIcon>
|
|
33
|
+
<Accordion.Content>
|
|
34
|
+
<ExampleContent />
|
|
35
|
+
</Accordion.Content>
|
|
36
|
+
</Accordion.Item>
|
|
37
|
+
<Accordion.Item value="addContentMedia">
|
|
38
|
+
<Accordion.TriggerWithIcon icon={ <BiBookContent /> }>
|
|
39
|
+
Add Content & Media
|
|
40
|
+
</Accordion.TriggerWithIcon>
|
|
41
|
+
<Accordion.Content>
|
|
42
|
+
<ExampleContent />
|
|
43
|
+
</Accordion.Content>
|
|
44
|
+
</Accordion.Item>
|
|
45
|
+
<Accordion.Item value="addCode">
|
|
46
|
+
<Accordion.TriggerWithIcon icon={ <RiCodeSSlashFill /> }>
|
|
47
|
+
Add Code
|
|
48
|
+
</Accordion.TriggerWithIcon>
|
|
49
|
+
<Accordion.Content>
|
|
50
|
+
<ExampleContent />
|
|
51
|
+
</Accordion.Content>
|
|
52
|
+
</Accordion.Item>
|
|
53
|
+
</Accordion.Root>
|
|
54
|
+
</Box>
|
|
55
|
+
);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
7
|
+
import { axe } from 'jest-axe';
|
|
8
|
+
import { ThemeProvider } from 'theme-ui';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import * as Accordion from './Accordion';
|
|
14
|
+
import { theme } from '../';
|
|
15
|
+
|
|
16
|
+
const renderWithTheme = children =>
|
|
17
|
+
render( <ThemeProvider theme={ theme }>{ children }</ThemeProvider> );
|
|
18
|
+
|
|
19
|
+
const renderComponent = () =>
|
|
20
|
+
renderWithTheme(
|
|
21
|
+
<Accordion.Root defaultValue="one" sx={ { width: '400px' } }>
|
|
22
|
+
<Accordion.Item value="one">
|
|
23
|
+
<Accordion.Trigger>trigger one</Accordion.Trigger>
|
|
24
|
+
<Accordion.Content>content one</Accordion.Content>
|
|
25
|
+
</Accordion.Item>
|
|
26
|
+
<Accordion.Item value="two">
|
|
27
|
+
<Accordion.Trigger>trigger two</Accordion.Trigger>
|
|
28
|
+
<Accordion.Content>content two</Accordion.Content>
|
|
29
|
+
</Accordion.Item>
|
|
30
|
+
</Accordion.Root>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
describe( '<Accordion />', () => {
|
|
34
|
+
it( 'renders the Accordion component with default value visible', async () => {
|
|
35
|
+
const { container } = renderComponent();
|
|
36
|
+
|
|
37
|
+
// Should find the open content
|
|
38
|
+
expect( screen.getByText( 'content one' ) ).toBeInTheDocument();
|
|
39
|
+
|
|
40
|
+
// Should not find the closed content
|
|
41
|
+
expect( screen.queryByText( 'content two' ) ).toBeNull();
|
|
42
|
+
|
|
43
|
+
// Check for accessibility issues
|
|
44
|
+
await expect( await axe( container ) ).toHaveNoViolations();
|
|
45
|
+
} );
|
|
46
|
+
|
|
47
|
+
it( 'should open the content when clicking on its trigger', async () => {
|
|
48
|
+
const { container } = renderComponent();
|
|
49
|
+
|
|
50
|
+
fireEvent.click( screen.getByRole( 'button', { name: 'trigger two' } ) );
|
|
51
|
+
|
|
52
|
+
// Should find the open content
|
|
53
|
+
expect( screen.queryByText( 'content one' ) ).toBeNull();
|
|
54
|
+
|
|
55
|
+
// Should not find the closed content
|
|
56
|
+
expect( screen.queryByText( 'content two' ) ).toBeInTheDocument();
|
|
57
|
+
|
|
58
|
+
// Check for accessibility issues
|
|
59
|
+
await expect( await axe( container ) ).toHaveNoViolations();
|
|
60
|
+
} );
|
|
61
|
+
} );
|
package/src/system/index.js
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
Textarea,
|
|
39
39
|
Checkbox,
|
|
40
40
|
} from './Form';
|
|
41
|
+
import { Accordion } from './Accordion';
|
|
41
42
|
import { Grid } from './Grid';
|
|
42
43
|
import { Heading } from './Heading';
|
|
43
44
|
import { Link } from './Link';
|
|
@@ -56,6 +57,7 @@ import theme from './theme';
|
|
|
56
57
|
import { Wizard, WizardStep, WizardStepHorizontal } from './Wizard';
|
|
57
58
|
|
|
58
59
|
export {
|
|
60
|
+
Accordion,
|
|
59
61
|
Avatar,
|
|
60
62
|
Badge,
|
|
61
63
|
Box,
|
|
@@ -11,3 +11,17 @@ export const getColor = ( color, variant = 'default' ) => {
|
|
|
11
11
|
|
|
12
12
|
return Valet[ color ][ variant ].value;
|
|
13
13
|
};
|
|
14
|
+
|
|
15
|
+
const resolvePath = ( object, path, defaultValue ) => {
|
|
16
|
+
return path.split( '.' ).reduce( ( acc, property ) => {
|
|
17
|
+
return acc ? acc[ property ] : defaultValue;
|
|
18
|
+
}, object );
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const getVariants = color => {
|
|
22
|
+
const property = resolvePath( Valet, color, {} );
|
|
23
|
+
|
|
24
|
+
return Object.keys( property ).reduce( ( variants, variant ) => {
|
|
25
|
+
return { ...variants, [ variant ]: property[ variant ].value };
|
|
26
|
+
}, {} );
|
|
27
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { light, dark } from './colors';
|
|
5
|
-
import { getColor } from './getColor';
|
|
5
|
+
import { getColor, getVariants } from './getColor';
|
|
6
6
|
|
|
7
7
|
const textStyles = {
|
|
8
8
|
h1: {
|
|
@@ -90,6 +90,8 @@ export default {
|
|
|
90
90
|
text: getColor( 'text', 'secondary' ),
|
|
91
91
|
heading: getColor( 'text', 'primary' ),
|
|
92
92
|
background: getColor( 'background', 'primary' ),
|
|
93
|
+
gold: getVariants( 'color.gold' ),
|
|
94
|
+
gray: getVariants( 'color.gray' ),
|
|
93
95
|
backgroundSecondary: light.grey[ '10' ],
|
|
94
96
|
primary: light.brand[ '70' ],
|
|
95
97
|
secondary: '#30c',
|
|
@@ -160,6 +162,10 @@ export default {
|
|
|
160
162
|
'0px 2.76726px 2.21381px rgba(0, 0, 0, 0.0196802), 0px 6.6501px 5.32008px rgba(0, 0, 0, 0.0282725), 0px 12.5216px 10.0172px rgba(0, 0, 0, 0.035), 0px 22.3363px 17.869px rgba(0, 0, 0, 0.0417275), 0px 41.7776px 33.4221px rgba(0, 0, 0, 0.0503198), 0px 100px 80px rgba(0, 0, 0, 0.07)',
|
|
161
163
|
},
|
|
162
164
|
|
|
165
|
+
tag: {
|
|
166
|
+
gold: getVariants( 'tag.gold' ),
|
|
167
|
+
},
|
|
168
|
+
|
|
163
169
|
cards: {
|
|
164
170
|
primary: {
|
|
165
171
|
padding: 3,
|