@automattic/vip-design-system 0.9.0 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/build/system/Avatar/Avatar.test.js +41 -22
  2. package/build/system/Badge/Badge.test.js +73 -0
  3. package/build/system/BlankState/BlankState.js +12 -9
  4. package/build/system/BlankState/BlankState.test.js +124 -0
  5. package/build/system/Button/Button.test.js +44 -0
  6. package/build/system/Card/Card.js +5 -7
  7. package/build/system/Card/Card.test.js +78 -0
  8. package/build/system/Code/Code.js +11 -8
  9. package/build/system/Code/Code.test.js +167 -0
  10. package/build/system/Dialog/DialogContent.js +3 -1
  11. package/build/system/Form/Input.js +7 -9
  12. package/build/system/Form/Select.js +29 -12
  13. package/build/system/Form/Textarea.js +5 -7
  14. package/build/system/Timeline/index.js +11 -9
  15. package/build/system/index.js +4 -0
  16. package/build/system/theme/index.js +1 -1
  17. package/package.json +15 -4
  18. package/src/system/Avatar/Avatar.test.js +9 -10
  19. package/src/system/Badge/Badge.test.js +30 -0
  20. package/src/system/BlankState/BlankState.js +13 -5
  21. package/src/system/BlankState/BlankState.test.js +58 -0
  22. package/src/system/Button/Button.test.js +21 -0
  23. package/src/system/Card/Card.js +16 -14
  24. package/src/system/Card/Card.test.js +33 -0
  25. package/src/system/Code/Code.js +12 -9
  26. package/src/system/Code/Code.stories.js +2 -0
  27. package/src/system/Code/Code.test.js +69 -0
  28. package/src/system/Dialog/DialogContent.js +2 -0
  29. package/src/system/Form/Input.js +6 -6
  30. package/src/system/Form/Select.js +16 -6
  31. package/src/system/Form/Select.stories.js +52 -24
  32. package/src/system/Form/Textarea.js +4 -4
  33. package/src/system/Timeline/index.js +46 -0
  34. package/src/system/index.js +2 -0
  35. package/src/system/theme/index.js +1 -1
@@ -147,7 +147,9 @@ var DialogMotion = function DialogMotion(_ref2) {
147
147
  right: position === 'left' ? 'auto' : 0,
148
148
  padding: 0,
149
149
  display: 'inline-block',
150
- variant: "dialog." + variant
150
+ variant: "dialog." + variant,
151
+ overflow: 'auto',
152
+ maxHeight: variant === 'modal' ? '90%' : ''
151
153
  }
152
154
  }));
153
155
  };
@@ -19,7 +19,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
19
19
 
20
20
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
21
21
 
22
- var InputComponent = function InputComponent(_ref, ref) {
22
+ var Input = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
23
23
  var variant = _ref.variant,
24
24
  label = _ref.label,
25
25
  forLabel = _ref.forLabel,
@@ -38,7 +38,7 @@ var InputComponent = function InputComponent(_ref, ref) {
38
38
  required: required,
39
39
  sx: {
40
40
  border: '1px solid',
41
- borderColor: 'grey.60',
41
+ borderColor: 'border',
42
42
  backgroundColor: 'card',
43
43
  borderRadius: 1,
44
44
  lineHeight: 'inherit',
@@ -57,16 +57,17 @@ var InputComponent = function InputComponent(_ref, ref) {
57
57
  bg: 'backgroundSecondary'
58
58
  },
59
59
  '&::placeholder': {
60
- color: 'grey.30'
60
+ color: 'placeholder'
61
61
  }
62
62
  }
63
63
  })), hasError && errorMessage && (0, _jsxRuntime.jsx)(_.Validation, {
64
64
  children: errorMessage
65
65
  })]
66
66
  });
67
- };
67
+ });
68
68
 
69
- InputComponent.propTypes = {
69
+ exports.Input = Input;
70
+ Input.propTypes = {
70
71
  variant: _propTypes["default"].string,
71
72
  label: _propTypes["default"].string,
72
73
  hasError: _propTypes["default"].bool,
@@ -74,7 +75,4 @@ InputComponent.propTypes = {
74
75
  forLabel: _propTypes["default"].string,
75
76
  errorMessage: _propTypes["default"].string
76
77
  };
77
-
78
- var Input = /*#__PURE__*/_react["default"].forwardRef(InputComponent);
79
-
80
- exports.Input = Input;
78
+ Input.displayName = 'Input';
@@ -3,6 +3,8 @@
3
3
  exports.__esModule = true;
4
4
  exports.Select = void 0;
5
5
 
6
+ var _react = _interopRequireDefault(require("react"));
7
+
6
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
7
9
 
8
10
  var _SearchSelect = require("./SearchSelect");
@@ -11,7 +13,7 @@ var _InlineSelect = require("./InlineSelect");
11
13
 
12
14
  var _jsxRuntime = require("theme-ui/jsx-runtime");
13
15
 
14
- var _excluded = ["isMulti", "isInline", "options", "label", "isSearch"];
16
+ var _excluded = ["isMulti", "isInline", "options", "label", "isSearch", "usePortal"];
15
17
 
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
19
 
@@ -26,21 +28,35 @@ var Select = function Select(_ref) {
26
28
  options = _ref.options,
27
29
  label = _ref.label,
28
30
  isSearch = _ref.isSearch,
31
+ usePortal = _ref.usePortal,
29
32
  props = _objectWithoutPropertiesLoose(_ref, _excluded);
30
33
 
31
- if (isInline) {
32
- return (0, _jsxRuntime.jsx)(_InlineSelect.InlineSelect, _extends({
34
+ var selectRef = _react["default"].useRef();
35
+
36
+ var portalProps = {};
37
+
38
+ if (usePortal !== undefined) {
39
+ var _selectRef$current;
40
+
41
+ portalProps.menuPortalTarget = selectRef == null ? void 0 : (_selectRef$current = selectRef.current) == null ? void 0 : _selectRef$current.querySelector('.select__control').parentElement;
42
+ portalProps.styles = {
43
+ menuPortal: function menuPortal(base) {
44
+ return _extends({}, base, {
45
+ position: 'fixed'
46
+ });
47
+ }
48
+ };
49
+ }
50
+
51
+ var Component = isInline ? _InlineSelect.InlineSelect : _SearchSelect.SearchSelect;
52
+ return (0, _jsxRuntime.jsx)("div", {
53
+ ref: selectRef,
54
+ children: (0, _jsxRuntime.jsx)(Component, _extends({
33
55
  isMulti: isMulti,
34
56
  label: label,
35
57
  options: options
36
- }, props));
37
- }
38
-
39
- return (0, _jsxRuntime.jsx)(_SearchSelect.SearchSelect, _extends({
40
- isMulti: isMulti,
41
- label: label,
42
- options: options
43
- }, props));
58
+ }, portalProps, props))
59
+ });
44
60
  };
45
61
 
46
62
  exports.Select = Select;
@@ -49,5 +65,6 @@ Select.propTypes = {
49
65
  isMulti: _propTypes["default"].bool,
50
66
  isSearch: _propTypes["default"].bool,
51
67
  label: _propTypes["default"].string,
52
- options: _propTypes["default"].array
68
+ options: _propTypes["default"].array,
69
+ usePortal: _propTypes["default"].bool
53
70
  };
@@ -19,7 +19,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
19
19
 
20
20
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
21
21
 
22
- var TextareaComponent = function TextareaComponent(_ref, ref) {
22
+ var Textarea = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
23
23
  var variant = _ref.variant,
24
24
  label = _ref.label,
25
25
  forLabel = _ref.forLabel,
@@ -59,9 +59,10 @@ var TextareaComponent = function TextareaComponent(_ref, ref) {
59
59
  children: errorMessage
60
60
  })]
61
61
  });
62
- };
62
+ });
63
63
 
64
- TextareaComponent.propTypes = {
64
+ exports.Textarea = Textarea;
65
+ Textarea.propTypes = {
65
66
  variant: _propTypes["default"].string,
66
67
  label: _propTypes["default"].string,
67
68
  hasError: _propTypes["default"].bool,
@@ -69,7 +70,4 @@ TextareaComponent.propTypes = {
69
70
  forLabel: _propTypes["default"].string,
70
71
  errorMessage: _propTypes["default"].string
71
72
  };
72
-
73
- var Textarea = /*#__PURE__*/_react["default"].forwardRef(TextareaComponent);
74
-
75
- exports.Textarea = Textarea;
73
+ Textarea.displayName = 'Textarea';
@@ -11,7 +11,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
12
  var _jsxRuntime = require("theme-ui/jsx-runtime");
13
13
 
14
- var _excluded = ["time"];
14
+ var _excluded = ["time", "first", "last"];
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
17
 
@@ -32,6 +32,10 @@ var VerticalLine = function VerticalLine() {
32
32
 
33
33
  var Timeline = function Timeline(_ref) {
34
34
  var time = _ref.time,
35
+ _ref$first = _ref.first,
36
+ first = _ref$first === void 0 ? false : _ref$first,
37
+ _ref$last = _ref.last,
38
+ last = _ref$last === void 0 ? false : _ref$last,
35
39
  props = _objectWithoutPropertiesLoose(_ref, _excluded);
36
40
 
37
41
  return (0, _jsxRuntime.jsxs)(_themeUi.Flex, _extends({}, props, {
@@ -41,22 +45,18 @@ var Timeline = function Timeline(_ref) {
41
45
  justifyContent: 'space-evenly',
42
46
  alignItems: 'center'
43
47
  },
44
- children: [(0, _jsxRuntime.jsx)(VerticalLine, {}), (0, _jsxRuntime.jsx)(_md.MdWatchLater, {
48
+ children: [!first && (0, _jsxRuntime.jsx)(VerticalLine, {}), (0, _jsxRuntime.jsx)(_md.MdWatchLater, {
45
49
  sx: {
46
50
  color: 'border'
47
51
  },
48
52
  size: 18
49
- }), (0, _jsxRuntime.jsx)(VerticalLine, {})]
53
+ }), !last && (0, _jsxRuntime.jsx)(VerticalLine, {})]
50
54
  }), (0, _jsxRuntime.jsx)(_themeUi.Flex, {
51
55
  sx: {
52
56
  alignItems: 'center',
53
57
  ml: 2
54
58
  },
55
- children: (0, _jsxRuntime.jsx)(_themeUi.Text, {
56
- as: "span",
57
- sx: {
58
- color: 'muted'
59
- },
59
+ children: (0, _jsxRuntime.jsx)("span", {
60
60
  children: time
61
61
  })
62
62
  })]
@@ -65,5 +65,7 @@ var Timeline = function Timeline(_ref) {
65
65
 
66
66
  exports.Timeline = Timeline;
67
67
  Timeline.propTypes = {
68
- time: _propTypes["default"].string
68
+ first: _propTypes["default"].bool,
69
+ time: _propTypes["default"].string,
70
+ last: _propTypes["default"].bool
69
71
  };
@@ -99,6 +99,10 @@ var _Time = require("./Time");
99
99
 
100
100
  exports.Time = _Time.Time;
101
101
 
102
+ var _Timeline = require("./Timeline");
103
+
104
+ exports.Timeline = _Timeline.Timeline;
105
+
102
106
  var _Notification = require("./Notification");
103
107
 
104
108
  exports.Notification = _Notification.Notification;
@@ -90,7 +90,7 @@ var _default = {
90
90
  muted: _colors.light.grey['90'],
91
91
  link: _colors.light.brand['90'],
92
92
  card: '#fff',
93
- border: _colors.light.grey['20'],
93
+ border: _colors.light.grey['60'],
94
94
  hover: 'rgba(0,0,0,.02)',
95
95
  lightenBackground: 'rgba(255,255,255,.5)',
96
96
  darken: 'rgba(0,0,0,.05)',
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@automattic/vip-design-system",
3
- "version": "0.9.0",
3
+ "version": "0.9.3",
4
4
  "main": "build/system/index.js",
5
5
  "scripts": {
6
6
  "build-storybook": "build-storybook",
7
7
  "build": "cross-env NODE_ENV=production babel src --out-dir build",
8
8
  "format": "eslint . --fix",
9
9
  "jest": "NODE_ENV=test jest --detectOpenHandles",
10
+ "jest:coverage": "npm run jest && open-cli ./coverage/index.html",
10
11
  "jest:watch": "npm run jest --watch",
11
12
  "lint": "eslint . -f json | eslines --quiet",
12
13
  "storybook": "start-storybook -p 6006",
@@ -34,12 +35,21 @@
34
35
  "**/react-dom": "17.0.1"
35
36
  },
36
37
  "jest": {
38
+ "collectCoverage": true,
39
+ "coverageReporters": [
40
+ "json",
41
+ "html"
42
+ ],
37
43
  "testURL": "http://localhost",
44
+ "roots": [
45
+ "<rootDir>/src",
46
+ "<rootDir>/test"
47
+ ],
38
48
  "setupFiles": [
39
- "./test/setupTests.js"
49
+ "<rootDir>/test/setupTests.js"
40
50
  ],
41
51
  "setupFilesAfterEnv": [
42
- "./test/setupAfterEnv.js"
52
+ "<rootDir>/test/setupAfterEnv.js"
43
53
  ],
44
54
  "transformIgnorePatterns": [
45
55
  ".*.stories.js$"
@@ -49,7 +59,6 @@
49
59
  }
50
60
  },
51
61
  "devDependencies": {
52
- "immer": ">=9.0.6",
53
62
  "@axe-core/react": "4.3.2",
54
63
  "@babel/cli": "^7.14.3",
55
64
  "@babel/core": "7.14.0",
@@ -85,7 +94,9 @@
85
94
  "eslint-plugin-no-async-foreach": "0.1.1",
86
95
  "eslint-plugin-react": "7.25.3",
87
96
  "eslint-plugin-wpcalypso": "4.1.0",
97
+ "immer": ">=9.0.6",
88
98
  "jest-axe": "5.0.1",
99
+ "open-cli": "^7.0.1",
89
100
  "optimize-css-assets-webpack-plugin": "^6.0.1",
90
101
  "react-input-autosize": "^3.0.0",
91
102
  "react-refresh": "^0.9.0",
@@ -10,22 +10,21 @@ import { axe } from 'jest-axe';
10
10
  import { Avatar } from './Avatar';
11
11
 
12
12
  describe( '<Avatar />', () => {
13
- it( 'renders the Avatar without an image', () => {
14
- render( <Avatar name="John Doe" /> );
13
+ it( 'renders the Avatar without an image', async () => {
14
+ const { container } = render( <Avatar name="John Doe" /> );
15
15
 
16
16
  expect( screen.getByText( 'J' ) ).toBeInTheDocument();
17
- } );
18
-
19
- it( 'renders the Avatar with image', () => {
20
- render( <Avatar name="John Doe" src="path/to/image" /> );
21
17
 
22
- expect( screen.getByAltText( 'Avatar image from John Doe' ) ).toBeInTheDocument();
18
+ // Check for accessibility issues
19
+ await expect( await axe( container ) ).toHaveNoViolations();
23
20
  } );
24
21
 
25
- it( 'should not have basic accessibility issues', async () => {
22
+ it( 'renders the Avatar with image', async () => {
26
23
  const { container } = render( <Avatar name="John Doe" src="path/to/image" /> );
27
- const results = await axe( container );
28
24
 
29
- expect( results ).toHaveNoViolations();
25
+ expect( screen.getByAltText( 'Avatar image from John Doe' ) ).toBeInTheDocument();
26
+
27
+ // Check for accessibility issues
28
+ await expect( await axe( container ) ).toHaveNoViolations();
30
29
  } );
31
30
  } );
@@ -0,0 +1,30 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { render, screen } from '@testing-library/react';
5
+ import { axe } from 'jest-axe';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import { Badge } from './Badge';
11
+
12
+ describe( '<Badge />', () => {
13
+ it( 'renders the Badge component', async () => {
14
+ const { container } = render( <Badge>Badge text</Badge> );
15
+
16
+ expect( screen.getByText( 'Badge text' ) ).toBeInTheDocument();
17
+
18
+ // Check for accessibility issues
19
+ await expect( await axe( container ) ).toHaveNoViolations();
20
+ } );
21
+
22
+ it( 'renders the Badge component with a different variant', async () => {
23
+ const { container } = render( <Badge variant="primary">Badge text</Badge> );
24
+
25
+ expect( screen.getByText( 'Badge text' ) ).toBeInTheDocument();
26
+
27
+ // Check for accessibility issues
28
+ await expect( await axe( container ) ).toHaveNoViolations();
29
+ } );
30
+ } );
@@ -10,10 +10,17 @@ import PropTypes from 'prop-types';
10
10
  */
11
11
  import { Box, Heading, Text } from '..';
12
12
 
13
- const BlankState = ( { image, icon, title, body, cta } ) => {
13
+ const BlankState = ( {
14
+ body,
15
+ cta,
16
+ icon,
17
+ image,
18
+ imageAlt = 'Image representing the blank state',
19
+ title,
20
+ } ) => {
14
21
  return (
15
22
  <Box sx={{ textAlign: 'center', padding: 5 }}>
16
- {icon ? icon : <img src={image} sx={{ mb: 3 }} alt="Icon representing the blank state" />}
23
+ {icon ? icon : <img src={image} sx={{ mb: 3 }} alt={imageAlt} />}
17
24
  <Heading variant="h4">{title}</Heading>
18
25
  <Text>{body}</Text>
19
26
  <Box sx={{ mt: 3 }}>{cta}</Box>
@@ -22,11 +29,12 @@ const BlankState = ( { image, icon, title, body, cta } ) => {
22
29
  };
23
30
 
24
31
  BlankState.propTypes = {
25
- image: PropTypes.oneOfType( [ PropTypes.object, PropTypes.string ] ),
26
- icon: PropTypes.node,
27
- title: PropTypes.node,
28
32
  body: PropTypes.node,
29
33
  cta: PropTypes.node,
34
+ icon: PropTypes.node,
35
+ image: PropTypes.oneOfType( [ PropTypes.object, PropTypes.string ] ),
36
+ imageAlt: PropTypes.string,
37
+ title: PropTypes.node,
30
38
  };
31
39
 
32
40
  export { BlankState };
@@ -0,0 +1,58 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { render, screen } from '@testing-library/react';
5
+ import { axe } from 'jest-axe';
6
+ import { MdContentCopy } from 'react-icons/md';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import { BlankState } from './BlankState';
12
+ import { Link } from '../Link';
13
+
14
+ // eslint-disable-next-line max-len
15
+ const image = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='79' height='79' viewBox='0 0 79 79' fill='none'%3E%3Cpath d='M66.3001 15.9C66.3001 15.9 66.3 15.8 66.2 15.8C66.1 15.7 66 15.5 65.9001 15.4C65.9001 15.4 65.9001 15.4 65.9001 15.3L44.4001 0.2C44.3001 0.0999998 44.2 0.0999994 44.1 0.0999994C44 0.0999994 44.0001 0 43.9001 0H43.3C43.2 0 43.1 0.0999994 43.1 0.0999994C43 0.0999994 42.9 0.2 42.8 0.2L28.2001 10.3C28.1 10.4 28.0001 10.5 27.9001 10.6C27.9001 10.6 27.9001 10.6 27.9001 10.7C27.8001 10.8 27.7001 11 27.7001 11.2C27.7001 11.2 27.7001 11.2 27.7001 11.3V31.1L13.9 40.8L13.7001 41C13.6001 41.1 13.6 41.1 13.6 41.2L13.5 41.3C13.5 41.4 13.4 41.5 13.4 41.5V41.6C13.4 41.7 13.3 41.8 13.3 42V62.2C13.3 62.4 13.3 62.6 13.4 62.7V62.8C13.5 62.9 13.6001 63.1 13.7001 63.2C13.7001 63.2 13.7 63.2 13.8 63.3L13.9 63.4L35.3 78.6H35.4001C35.4001 78.6 35.5 78.6 35.5 78.7H35.6C35.8 78.8 36 78.8 36.2001 78.8C36.3001 78.8 36.5 78.8 36.6 78.7H36.7001C36.8001 78.7 36.8001 78.7 36.9001 78.6C36.9001 78.6 37 78.6 37 78.5H37.1L66 58.3C66.1 58.2 66.2001 58.1 66.3001 58V15.9ZM34.6 74.5L16.1 61.3V44.7L34.6 57.8V74.5ZM36 55.3L17.2001 41.9L29 33.5L47.9001 46.9L36 55.3ZM49 44.1L30.5 31V14.4L49 27.5V44.1ZM50.5 24.9L31.6 11.5L43.5 3.2L62.4001 16.6L50.5 24.9Z' fill='%23BD9D70'/%3E%3C/svg%3E";
16
+
17
+ const defaultProps = {
18
+ body: 'Sorry, there\'s nothing here yet.',
19
+ cta: <Link as="a">Explore add-ons →</Link>,
20
+ image,
21
+ imageAlt: 'This is the image alt',
22
+ title: 'Power up your application',
23
+ };
24
+
25
+ describe( '<BlankState />', () => {
26
+ it( 'renders the BlankState component', async () => {
27
+ const { container } = render( <BlankState { ...defaultProps } /> );
28
+
29
+ expect( screen.getByText( defaultProps.body ) ).toBeInTheDocument();
30
+ expect( screen.getByText( defaultProps.title ) ).toBeInTheDocument();
31
+ expect( screen.getByText( 'Explore add-ons →' ) ).toBeInTheDocument();
32
+ expect( screen.getByAltText( defaultProps.imageAlt ) ).toBeInTheDocument();
33
+
34
+ // Check for accessibility issues
35
+ await expect( await axe( container ) ).toHaveNoViolations();
36
+ } );
37
+
38
+ it( 'renders the BlankState component with default alt text for the given image', async () => {
39
+ const props = { ...defaultProps, imageAlt: undefined };
40
+ const { container } = render( <BlankState { ...props } /> );
41
+
42
+ expect( screen.getByAltText( 'Image representing the blank state' ) ).toBeInTheDocument();
43
+
44
+ // Check for accessibility issues
45
+ await expect( await axe( container ) ).toHaveNoViolations();
46
+ } );
47
+
48
+ it( 'renders the BlankState component with an icon', async () => {
49
+ const icon = <MdContentCopy title="this is an icon" />;
50
+ const props = { ...defaultProps, icon };
51
+ const { container } = render( <BlankState { ...props } /> );
52
+
53
+ expect( screen.getByTitle( 'this is an icon' ) ).toBeInTheDocument();
54
+
55
+ // Check for accessibility issues
56
+ await expect( await axe( container ) ).toHaveNoViolations();
57
+ } );
58
+ } );
@@ -0,0 +1,21 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { render, screen } from '@testing-library/react';
5
+ import { axe } from 'jest-axe';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import { Button } from './Button';
11
+
12
+ describe( '<Button />', () => {
13
+ it( 'renders the Button component', async () => {
14
+ const { container } = render( <Button>Button text</Button> );
15
+
16
+ expect( screen.getByText( 'Button text' ) ).toBeInTheDocument();
17
+
18
+ // Check for accessibility issues
19
+ await expect( await axe( container ) ).toHaveNoViolations();
20
+ } );
21
+ } );
@@ -11,24 +11,26 @@ import PropTypes from 'prop-types';
11
11
  */
12
12
  import { Box } from '..';
13
13
 
14
- const CardComponent = ( { variant = 'primary', sx = {}, ...props }, ref ) => (
15
- <Box
16
- ref={ref}
17
- sx={{
18
- // pass variant prop to sx
19
- variant: `cards.${ variant }`,
20
- overflow: 'hidden',
21
- ...sx,
22
- }}
23
- {...props}
24
- />
25
- );
14
+ const Card = React.forwardRef( ( { variant = 'primary', sx = {}, ...props }, ref ) => {
15
+ return (
16
+ <Box
17
+ ref={ref}
18
+ sx={{
19
+ // pass variant prop to sx
20
+ variant: `cards.${ variant }`,
21
+ overflow: 'hidden',
22
+ ...sx,
23
+ }}
24
+ {...props}
25
+ />
26
+ );
27
+ } );
26
28
 
27
- CardComponent.propTypes = {
29
+ Card.propTypes = {
28
30
  variant: PropTypes.string,
29
31
  sx: PropTypes.object,
30
32
  };
31
33
 
32
- const Card = React.forwardRef( CardComponent );
34
+ Card.displayName = 'Card';
33
35
 
34
36
  export { Card };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
5
+ import { axe } from 'jest-axe';
6
+ import { MdContentCopy } from 'react-icons/md';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import { Card } from './Card';
12
+
13
+ const defaultProps = {};
14
+
15
+ describe( '<Card />', () => {
16
+ it( 'renders the Card component', async () => {
17
+ const { container } = render( <Card { ...defaultProps }>This is a Card</Card> );
18
+
19
+ expect( screen.getByText( 'This is a Card' ) ).toBeInTheDocument();
20
+
21
+ // Check for accessibility issues
22
+ await expect( await axe( container ) ).toHaveNoViolations();
23
+ } );
24
+
25
+ it( 'renders the Card component with a different variant', async () => {
26
+ const { container } = render( <Card variant="primary">Card text</Card> );
27
+
28
+ expect( screen.getByText( 'Card text' ) ).toBeInTheDocument();
29
+
30
+ // Check for accessibility issues
31
+ await expect( await axe( container ) ).toHaveNoViolations();
32
+ } );
33
+ } );
@@ -47,18 +47,21 @@ const Code = ( { prompt = false, showCopy = false, onCopy = null, ...props } ) =
47
47
  >
48
48
  { codeDom }
49
49
  {
50
- <span
50
+ <button
51
+ aria-label="Copy"
51
52
  sx={ {
52
- position: 'absolute',
53
- top: 0,
54
53
  bg: 'grey.10',
55
- right: 0,
56
- paddingRight: 2,
57
- paddingLeft: 2,
58
- paddingTop: 1,
59
- paddingBottom: 1,
60
54
  borderTopRightRadius: 1,
55
+ borderWidth: 0,
56
+ color: 'muted',
61
57
  opacity: 0.8,
58
+ paddingBottom: 1,
59
+ paddingLeft: 2,
60
+ paddingRight: 2,
61
+ paddingTop: 1,
62
+ position: 'absolute',
63
+ right: 0,
64
+ top: '-1px',
62
65
  '&:hover': {
63
66
  opacity: 1,
64
67
  cursor: 'pointer',
@@ -75,7 +78,7 @@ const Code = ( { prompt = false, showCopy = false, onCopy = null, ...props } ) =
75
78
  } }
76
79
  >
77
80
  { copied ? 'Copied!' : <MdContentCopy /> }
78
- </span>
81
+ </button>
79
82
  }
80
83
  </div>
81
84
  );
@@ -16,7 +16,9 @@ export default {
16
16
  export const Default = () => (
17
17
  <React.Fragment>
18
18
  <Code>Code</Code>
19
+ <br />
19
20
  <Code showCopy={true}>Code with Icon</Code>
21
+ <br />
20
22
  <Code showCopy={true} onCopy={
21
23
  // eslint-disable-next-line no-console
22
24
  () => console.info( 'Hello world' )
@@ -0,0 +1,69 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
5
+ import { axe } from 'jest-axe';
6
+ import { MdContentCopy } from 'react-icons/md';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import { Code } from './Code';
12
+
13
+ const defaultProps = {
14
+ showCopy: false,
15
+ };
16
+
17
+ // Mock navigator.clipboard because jsdom doesn't support it
18
+ Object.defineProperty( window.navigator, 'clipboard', {
19
+ value: {
20
+ writeText: () => {},
21
+ },
22
+ } );
23
+
24
+ describe( '<Code />', () => {
25
+ it( 'renders the Code component', async () => {
26
+ const { container } = render( <Code { ...defaultProps }>This is a code</Code> );
27
+
28
+ expect( screen.getByText( 'This is a code' ) ).toBeInTheDocument();
29
+
30
+ // Check for accessibility issues
31
+ await expect( await axe( container ) ).toHaveNoViolations();
32
+ } );
33
+
34
+ // jsdom currently doesn't support pseudo-elements with getComputedStyle
35
+ it.skip( 'renders "$" in front of the code when in prompt mode', async () => {
36
+ const props = { ...defaultProps, prompt: true };
37
+ const { container } = render( <Code { ...props }>This is a code</Code> );
38
+ const codeElement = screen.getByText( 'This is a code' );
39
+
40
+ expect( window.getComputedStyle( codeElement, ':before' ).content ).toEqual( '$' );
41
+
42
+ // Check for accessibility issues
43
+ await expect( await axe( container ) ).toHaveNoViolations();
44
+ } );
45
+
46
+ it( 'renders the Code component with a copy button', async () => {
47
+ const props = { ...defaultProps, showCopy: true };
48
+ const { container } = render( <Code { ...props }>This is a code</Code> );
49
+
50
+ expect( screen.getByRole( 'button', { name: 'Copy' } ) ).toBeInTheDocument();
51
+
52
+ // Check for accessibility issues
53
+ await expect( await axe( container ) ).toHaveNoViolations();
54
+ } );
55
+
56
+ it( 'updates the the UI after clicking on "Copy"', async () => {
57
+ const props = { ...defaultProps, showCopy: true };
58
+ const { container } = render( <Code { ...props }>This is a code</Code> );
59
+
60
+ fireEvent.click( screen.getByRole( 'button', { name: 'Copy' } ) );
61
+
62
+ await waitFor( () => new Promise( res => setTimeout( res, 0 ) ) );
63
+
64
+ expect( screen.getByText( 'Copied!' ) ).toBeInTheDocument();
65
+
66
+ // Check for accessibility issues
67
+ await expect( await axe( container ) ).toHaveNoViolations();
68
+ } );
69
+ } );