@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,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports["default"] = exports.Inline = exports.Default = 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 = require("react");
|
|
13
|
+
|
|
14
|
+
var Form = _interopRequireWildcard(require("."));
|
|
15
|
+
|
|
16
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
17
|
+
|
|
18
|
+
var _excluded = ["label", "width", "onChange"];
|
|
19
|
+
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
var _default = {
|
|
25
|
+
title: 'Form/Autocomplete',
|
|
26
|
+
argTypes: {
|
|
27
|
+
placeholder: {
|
|
28
|
+
type: {
|
|
29
|
+
name: 'string',
|
|
30
|
+
required: false
|
|
31
|
+
},
|
|
32
|
+
control: {
|
|
33
|
+
type: 'text'
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
label: {
|
|
37
|
+
type: {
|
|
38
|
+
name: 'string',
|
|
39
|
+
required: false
|
|
40
|
+
},
|
|
41
|
+
control: {
|
|
42
|
+
type: 'text'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports["default"] = _default;
|
|
48
|
+
var defaultOptions = [{
|
|
49
|
+
value: 'chocolate',
|
|
50
|
+
label: 'Chocolate'
|
|
51
|
+
}, {
|
|
52
|
+
value: 'strawberry',
|
|
53
|
+
label: 'Strawberry Chocolate Vanilla Chocolate Vanilla'
|
|
54
|
+
}, {
|
|
55
|
+
value: 'vanilla',
|
|
56
|
+
label: 'Vanilla'
|
|
57
|
+
}]; // eslint-disable-next-line react/prop-types
|
|
58
|
+
|
|
59
|
+
var DefaultComponent = function DefaultComponent(_ref) {
|
|
60
|
+
var _ref$label = _ref.label,
|
|
61
|
+
label = _ref$label === void 0 ? 'Label' : _ref$label,
|
|
62
|
+
_ref$width = _ref.width,
|
|
63
|
+
width = _ref$width === void 0 ? 250 : _ref$width,
|
|
64
|
+
onChange = _ref.onChange,
|
|
65
|
+
rest = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
|
|
66
|
+
return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
67
|
+
children: (0, _jsxRuntime.jsx)(Form.Root, {
|
|
68
|
+
children: (0, _jsxRuntime.jsx)("div", {
|
|
69
|
+
sx: {
|
|
70
|
+
width: width
|
|
71
|
+
},
|
|
72
|
+
children: (0, _jsxRuntime.jsx)(Form.Autocomplete, (0, _extends2["default"])({
|
|
73
|
+
id: "form-autocomplete",
|
|
74
|
+
label: label,
|
|
75
|
+
onChange: onChange
|
|
76
|
+
}, rest))
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
var Default = function Default() {
|
|
83
|
+
var _useState = (0, _react.useState)(defaultOptions),
|
|
84
|
+
options = _useState[0],
|
|
85
|
+
setOptions = _useState[1];
|
|
86
|
+
|
|
87
|
+
var onChange = (0, _react.useCallback)(function (value) {
|
|
88
|
+
setOptions(defaultOptions.filter(function (option) {
|
|
89
|
+
return !value || option.label.toLowerCase().indexOf(value.toLowerCase()) >= 0;
|
|
90
|
+
}));
|
|
91
|
+
});
|
|
92
|
+
var args = {
|
|
93
|
+
label: 'Label',
|
|
94
|
+
options: options
|
|
95
|
+
};
|
|
96
|
+
return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
97
|
+
children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({
|
|
98
|
+
onChange: onChange
|
|
99
|
+
}, args))
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
exports.Default = Default;
|
|
104
|
+
|
|
105
|
+
var Inline = function Inline() {
|
|
106
|
+
var _useState2 = (0, _react.useState)(defaultOptions),
|
|
107
|
+
options = _useState2[0],
|
|
108
|
+
setOptions = _useState2[1];
|
|
109
|
+
|
|
110
|
+
var onChange = (0, _react.useCallback)(function (value) {
|
|
111
|
+
setOptions(defaultOptions.filter(function (option) {
|
|
112
|
+
return !value || option.label.toLowerCase().indexOf(value.toLowerCase()) >= 0;
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
|
+
var args = {
|
|
116
|
+
label: 'Label',
|
|
117
|
+
options: options
|
|
118
|
+
};
|
|
119
|
+
return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
120
|
+
children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({
|
|
121
|
+
isInline: true,
|
|
122
|
+
onChange: onChange
|
|
123
|
+
}, args))
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
exports.Inline = Inline;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
6
|
+
|
|
7
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
8
|
+
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
|
|
11
|
+
var _react = require("@testing-library/react");
|
|
12
|
+
|
|
13
|
+
var _jestAxe = require("jest-axe");
|
|
14
|
+
|
|
15
|
+
var _FormAutocomplete = require("./FormAutocomplete");
|
|
16
|
+
|
|
17
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* External dependencies
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Internal dependencies
|
|
25
|
+
*/
|
|
26
|
+
var options = [{
|
|
27
|
+
value: 'chocolate',
|
|
28
|
+
label: 'Chocolate'
|
|
29
|
+
}, {
|
|
30
|
+
value: 'strawberry',
|
|
31
|
+
label: 'Strawberry Chocolate Vanilla Chocolate Vanilla'
|
|
32
|
+
}, {
|
|
33
|
+
value: 'vanilla',
|
|
34
|
+
label: 'Vanilla'
|
|
35
|
+
}];
|
|
36
|
+
var defaultProps = {
|
|
37
|
+
label: 'This is a label',
|
|
38
|
+
options: options
|
|
39
|
+
};
|
|
40
|
+
describe('<FormAutocomplete />', function () {
|
|
41
|
+
it('renders the FormAutocomplete component', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
42
|
+
var _render, container;
|
|
43
|
+
|
|
44
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
45
|
+
while (1) {
|
|
46
|
+
switch (_context.prev = _context.next) {
|
|
47
|
+
case 0:
|
|
48
|
+
_render = (0, _react.render)((0, _jsxRuntime.jsx)(_FormAutocomplete.FormAutocomplete, (0, _extends2["default"])({
|
|
49
|
+
id: "my_desert_list"
|
|
50
|
+
}, defaultProps))), container = _render.container;
|
|
51
|
+
expect(_react.screen.getByLabelText(defaultProps.label)).toBeInTheDocument(); // Check for accessibility issues
|
|
52
|
+
|
|
53
|
+
_context.t0 = expect;
|
|
54
|
+
_context.next = 5;
|
|
55
|
+
return (0, _jestAxe.axe)(container);
|
|
56
|
+
|
|
57
|
+
case 5:
|
|
58
|
+
_context.t1 = _context.sent;
|
|
59
|
+
_context.next = 8;
|
|
60
|
+
return (0, _context.t0)(_context.t1).toHaveNoViolations();
|
|
61
|
+
|
|
62
|
+
case 8:
|
|
63
|
+
case "end":
|
|
64
|
+
return _context.stop();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, _callee);
|
|
68
|
+
})));
|
|
69
|
+
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports["default"] = exports.Select = exports.Root = void 0;
|
|
4
|
+
exports["default"] = exports.Select = exports.Root = exports.Autocomplete = void 0;
|
|
5
5
|
|
|
6
6
|
var _FormSelect = require("./FormSelect");
|
|
7
7
|
|
|
8
|
+
var _FormAutocomplete = require("./FormAutocomplete");
|
|
9
|
+
|
|
8
10
|
var _Form = require("./Form");
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -12,6 +14,8 @@ var _Form = require("./Form");
|
|
|
12
14
|
*/
|
|
13
15
|
var Select = _FormSelect.FormSelect;
|
|
14
16
|
exports.Select = Select;
|
|
17
|
+
var Autocomplete = _FormAutocomplete.FormAutocomplete;
|
|
18
|
+
exports.Autocomplete = Autocomplete;
|
|
15
19
|
var Root = _Form.Form;
|
|
16
20
|
exports.Root = Root;
|
|
17
21
|
var _default = Root;
|
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.25.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",
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"@radix-ui/react-tooltip": "^1.0.0",
|
|
29
30
|
"@radix-ui/react-visually-hidden": "^1.0.0",
|
|
30
31
|
"@storybook/addon-storysource": "^6.5.10",
|
|
32
|
+
"accessible-autocomplete": "^2.0.4",
|
|
31
33
|
"babel-loader": "^8.2.2",
|
|
32
34
|
"classnames": "^2.3.1",
|
|
33
35
|
"framer-motion": "^3.9.1",
|
|
@@ -70,6 +72,9 @@
|
|
|
70
72
|
],
|
|
71
73
|
"transform": {
|
|
72
74
|
"\\.[jt]sx?$": "babel-jest"
|
|
75
|
+
},
|
|
76
|
+
"moduleNameMapper": {
|
|
77
|
+
"\\.(css|less)$": "<rootDir>/test/fileMock.js"
|
|
73
78
|
}
|
|
74
79
|
},
|
|
75
80
|
"devDependencies": {
|
|
@@ -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
|
+
} );
|