@automattic/vip-design-system 2.2.0 → 2.3.1

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 (87) hide show
  1. package/.eslintrc.js +3 -0
  2. package/build/system/Accordion/Accordion.test.d.ts +0 -1
  3. package/build/system/Accordion/Accordion.test.js +23 -12
  4. package/build/system/Button/Button.d.ts +2 -0
  5. package/build/system/Button/Button.js +6 -15
  6. package/build/system/Button/Button.stories.js +86 -67
  7. package/build/system/Card/Card.js +1 -2
  8. package/build/system/Drawer/Drawer.d.ts +12 -3
  9. package/build/system/Drawer/Drawer.js +8 -9
  10. package/build/system/Drawer/Drawer.stories.d.ts +0 -1
  11. package/build/system/Drawer/Drawer.stories.js +19 -225
  12. package/build/system/Drawer/styles.d.ts +2 -2
  13. package/build/system/Drawer/styles.js +13 -9
  14. package/build/system/Form/Toggle.d.ts +14 -2
  15. package/build/system/Form/Toggle.js +68 -69
  16. package/build/system/Form/Toggle.stories.d.ts +29 -18
  17. package/build/system/Form/Toggle.stories.js +99 -0
  18. package/build/system/Form/Toggle.test.js +36 -19
  19. package/build/system/Link/Link.d.ts +1 -1
  20. package/build/system/Link/Link.js +5 -20
  21. package/build/system/Link/Link.stories.d.ts +3 -1
  22. package/build/system/Link/Link.stories.js +18 -1
  23. package/build/system/MobileMenu/MobileMenu.d.ts +16 -0
  24. package/build/system/MobileMenu/MobileMenu.js +112 -0
  25. package/build/system/MobileMenu/MobileMenu.stories.d.ts +19 -0
  26. package/build/system/MobileMenu/MobileMenu.stories.js +173 -0
  27. package/build/system/MobileMenu/MobileMenu.test.d.ts +1 -0
  28. package/build/system/MobileMenu/MobileMenu.test.js +81 -0
  29. package/build/system/Nav/NavItem.js +4 -5
  30. package/build/system/Nav/NavItemGroup.d.ts +3 -0
  31. package/build/system/Nav/NavItemGroup.js +18 -6
  32. package/build/system/Nav/styles/variants/menu.js +15 -9
  33. package/build/system/Nav/styles/variants/menugroup.js +9 -5
  34. package/build/system/Nav/styles/variants/toolbar.js +1 -2
  35. package/build/system/Nav/styles.js +1 -0
  36. package/build/system/NewDialog/DialogClose.d.ts +7 -2
  37. package/build/system/NewDialog/DialogClose.js +29 -16
  38. package/build/system/NewDialog/index.d.ts +2 -1
  39. package/build/system/NewDialog/index.js +2 -1
  40. package/build/system/NewForm/FormAutocomplete.css +1 -3
  41. package/build/system/Table/Table.js +1 -0
  42. package/build/system/Toolbar/Toolbar.js +1 -1
  43. package/build/system/Toolbar/Toolbar.stories.d.ts +3 -0
  44. package/build/system/Toolbar/Toolbar.stories.js +62 -5
  45. package/build/system/Toolbar/ToolbarUtilNav.d.ts +3 -0
  46. package/build/system/Toolbar/ToolbarUtilNav.js +21 -3
  47. package/build/system/Toolbar/index.d.ts +3 -0
  48. package/build/system/Toolbar/index.js +2 -1
  49. package/build/system/index.d.ts +4 -1
  50. package/build/system/index.js +4 -0
  51. package/build/system/theme/index.d.ts +75 -35
  52. package/build/system/theme/index.js +52 -18
  53. package/package.json +2 -1
  54. package/src/system/Accordion/Accordion.test.tsx +15 -8
  55. package/src/system/Button/Button.stories.tsx +40 -31
  56. package/src/system/Button/Button.tsx +6 -15
  57. package/src/system/Card/Card.tsx +0 -1
  58. package/src/system/Drawer/Drawer.stories.tsx +28 -197
  59. package/src/system/Drawer/Drawer.tsx +31 -18
  60. package/src/system/Drawer/styles.ts +15 -5
  61. package/src/system/Form/Toggle.stories.tsx +122 -0
  62. package/src/system/Form/{Toggle.test.js → Toggle.test.tsx} +1 -1
  63. package/src/system/Form/Toggle.tsx +77 -0
  64. package/src/system/Link/Link.stories.tsx +21 -0
  65. package/src/system/Link/Link.tsx +10 -17
  66. package/src/system/MobileMenu/MobileMenu.stories.tsx +171 -0
  67. package/src/system/MobileMenu/MobileMenu.test.tsx +50 -0
  68. package/src/system/MobileMenu/MobileMenu.tsx +116 -0
  69. package/src/system/Nav/NavItem.tsx +3 -3
  70. package/src/system/Nav/NavItemGroup.tsx +18 -2
  71. package/src/system/Nav/styles/variants/menu.ts +15 -9
  72. package/src/system/Nav/styles/variants/menugroup.ts +7 -3
  73. package/src/system/Nav/styles/variants/toolbar.ts +1 -2
  74. package/src/system/Nav/styles.ts +1 -0
  75. package/src/system/NewDialog/DialogClose.tsx +37 -23
  76. package/src/system/NewDialog/index.ts +3 -2
  77. package/src/system/NewForm/FormAutocomplete.css +1 -3
  78. package/src/system/Table/Table.tsx +1 -1
  79. package/src/system/Toolbar/Toolbar.stories.tsx +49 -2
  80. package/src/system/Toolbar/Toolbar.tsx +1 -1
  81. package/src/system/Toolbar/ToolbarUtilNav.tsx +19 -2
  82. package/src/system/Toolbar/index.tsx +6 -1
  83. package/src/system/index.js +4 -0
  84. package/src/system/theme/index.js +52 -18
  85. package/build/system/Form/Toggle.stories.jsx +0 -96
  86. package/src/system/Form/Toggle.js +0 -74
  87. package/src/system/Form/Toggle.stories.jsx +0 -96
@@ -64,6 +64,10 @@ declare namespace _default {
64
64
  color: string;
65
65
  bg: string;
66
66
  border: string;
67
+ py: number;
68
+ px: number;
69
+ minHeight: string;
70
+ display: string;
67
71
  cursor: string;
68
72
  fontWeight: string;
69
73
  boxShadow: string;
@@ -72,6 +76,19 @@ declare namespace _default {
72
76
  backgroundColor: string;
73
77
  color: string;
74
78
  };
79
+ verticalAlign: string;
80
+ alignItems: string;
81
+ justifyContent: string;
82
+ textDecoration: string;
83
+ svg: {
84
+ fill: string;
85
+ '&:hover': {
86
+ fill: string;
87
+ };
88
+ };
89
+ '&:hover': {
90
+ textDecoration: string;
91
+ };
75
92
  };
76
93
  export { primary_1 as primary };
77
94
  let secondary_1: {
@@ -162,26 +179,45 @@ declare namespace _default {
162
179
  };
163
180
  };
164
181
  }
165
- export namespace links {
166
- let dark: {
182
+ export let links: {
183
+ primary: {
167
184
  color: string;
168
- '&:hover': {
185
+ '&:visited': {
169
186
  color: string;
170
187
  };
171
- };
172
- let hover: {
173
- display: string;
174
- color: string;
175
- py: number;
176
- px: number;
177
- my: number;
178
- mx: number;
179
- borderRadius: number;
180
188
  '&:hover': {
181
- backgroundColor: string;
189
+ color: string;
190
+ };
191
+ '&:active': {
192
+ color: string;
193
+ };
194
+ textDecorationThickness: string;
195
+ textUnderlineOffset: string;
196
+ '&:hover, &:focus': {
197
+ color: string;
198
+ textDecorationLine: string;
199
+ textDecorationThickness: string;
182
200
  };
183
201
  };
184
- }
202
+ 'button-primary': {
203
+ variant: string;
204
+ };
205
+ 'button-danger': {
206
+ variant: string;
207
+ };
208
+ 'button-display': {
209
+ variant: string;
210
+ };
211
+ 'button-ghost': {
212
+ variant: string;
213
+ };
214
+ 'button-secondary': {
215
+ variant: string;
216
+ };
217
+ 'button-tertiary': {
218
+ variant: string;
219
+ };
220
+ };
185
221
  let text_1: {};
186
222
  export { text_1 as text };
187
223
  export namespace dialog {
@@ -277,32 +313,36 @@ declare namespace _default {
277
313
  };
278
314
  };
279
315
  export namespace styles {
280
- let root: {
281
- fontFamily: string;
282
- lineHeight: string;
283
- fontWeight: string;
284
- fontSize: number;
285
- color: string;
286
- backgroundColor: string;
287
- '-webkit-font-smoothing': string;
288
- '-moz-osx-font-smoothing': string;
289
- a: {
316
+ namespace root {
317
+ export let fontFamily: string;
318
+ export let lineHeight: string;
319
+ export let fontWeight: string;
320
+ let color_1: string;
321
+ export { color_1 as color };
322
+ let backgroundColor_5: string;
323
+ export { backgroundColor_5 as backgroundColor };
324
+ export let fontSmoothing: string;
325
+ export let a: {
290
326
  '&:hover': {
291
327
  textDecorationLine: string;
292
328
  textDecorationThickness: string;
293
329
  };
294
330
  };
295
- svg: {
296
- fill: string;
297
- display: string;
298
- };
299
- pre: {
300
- fontFamily: string;
301
- };
302
- p: {
303
- color: string;
304
- };
305
- };
331
+ export namespace svg {
332
+ export let fill: string;
333
+ let display_1: string;
334
+ export { display_1 as display };
335
+ }
336
+ export namespace pre {
337
+ let fontFamily_1: string;
338
+ export { fontFamily_1 as fontFamily };
339
+ }
340
+ export namespace p_2 {
341
+ let color_2: string;
342
+ export { color_2 as color };
343
+ }
344
+ export { p_2 as p };
345
+ }
306
346
  }
307
347
  }
308
348
  export default _default;
@@ -271,11 +271,14 @@ export default {
271
271
 
272
272
  buttons: {
273
273
  primary: {
274
- // you can reference other values defined in the theme
275
274
  fontFamily: 'body',
276
275
  color: 'button.primary.label.default',
277
276
  bg: 'button.primary.background.default',
278
277
  border: '1px solid transparent',
278
+ py: 0,
279
+ px: 5,
280
+ minHeight: '38px',
281
+ display: 'inline-flex',
279
282
  cursor: 'pointer',
280
283
  fontWeight: 'medium',
281
284
  boxShadow: 'none',
@@ -284,6 +287,19 @@ export default {
284
287
  backgroundColor: 'button.primary.background.hover',
285
288
  color: 'button.primary.label.hover',
286
289
  },
290
+ verticalAlign: 'middle',
291
+ alignItems: 'center',
292
+ justifyContent: 'center',
293
+ textDecoration: 'none',
294
+ svg: {
295
+ fill: 'currentColor',
296
+ '&:hover': {
297
+ fill: 'inherit',
298
+ },
299
+ },
300
+ '&:hover': {
301
+ textDecoration: 'none',
302
+ },
287
303
  },
288
304
 
289
305
  secondary: {
@@ -387,22 +403,42 @@ export default {
387
403
  },
388
404
 
389
405
  links: {
390
- dark: {
391
- color: 'modes.dark.muted',
392
- '&:hover': { color: 'modes.dark.heading' },
393
- },
394
-
395
- hover: {
396
- display: 'block',
397
- color: 'inherit',
398
- py: 1,
399
- px: 2,
400
- my: -1,
401
- mx: -2,
402
- borderRadius: 2,
406
+ primary: {
407
+ color: 'link',
408
+ '&:visited': {
409
+ color: 'links.visited',
410
+ },
403
411
  '&:hover': {
404
- backgroundColor: 'hover',
412
+ color: 'hover',
405
413
  },
414
+ '&:active': {
415
+ color: 'links.active',
416
+ },
417
+ textDecorationThickness: '0.125rem',
418
+ textUnderlineOffset: '0.125rem',
419
+ '&:hover, &:focus': {
420
+ color: 'links.hover',
421
+ textDecorationLine: 'underline',
422
+ textDecorationThickness: '0.125rem',
423
+ },
424
+ },
425
+ 'button-primary': {
426
+ variant: 'buttons.primary',
427
+ },
428
+ 'button-danger': {
429
+ variant: 'buttons.danger',
430
+ },
431
+ 'button-display': {
432
+ variant: 'buttons.display',
433
+ },
434
+ 'button-ghost': {
435
+ variant: 'buttons.ghost',
436
+ },
437
+ 'button-secondary': {
438
+ variant: 'buttons.secondary',
439
+ },
440
+ 'button-tertiary': {
441
+ variant: 'buttons.tertiary',
406
442
  },
407
443
  },
408
444
 
@@ -492,11 +528,9 @@ export default {
492
528
  fontFamily: 'body',
493
529
  lineHeight: 'body',
494
530
  fontWeight: 'body',
495
- fontSize: 2,
496
531
  color: 'text',
497
532
  backgroundColor: 'backgrounds.primary',
498
- '-webkit-font-smoothing': 'antialiased',
499
- '-moz-osx-font-smoothing': 'grayscale',
533
+ fontSmoothing: 'antialiased',
500
534
  a: {
501
535
  '&:hover': {
502
536
  textDecorationLine: 'underline',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip-design-system",
3
- "version": "2.2.0",
3
+ "version": "2.3.1",
4
4
  "main": "build/system/index.js",
5
5
  "scripts": {
6
6
  "build-storybook": "storybook build",
@@ -93,6 +93,7 @@
93
93
  "@testing-library/dom": "9.3.3",
94
94
  "@testing-library/jest-dom": "6.1.3",
95
95
  "@testing-library/react": "14.0.0",
96
+ "@testing-library/user-event": "^14.4.3",
96
97
  "@tsconfig/node18": "18.2.2",
97
98
  "@types/jest": "29.5.5",
98
99
  "@types/jest-axe": "3.5.6",
@@ -1,12 +1,11 @@
1
- // TODO: Fix this
2
1
  /* eslint-disable @typescript-eslint/ban-ts-comment */
3
2
  // @ts-nocheck
4
3
  /** @jsxImportSource theme-ui */
5
-
6
4
  /**
7
5
  * External dependencies
8
6
  */
9
- import { fireEvent, render, screen } from '@testing-library/react';
7
+ import { render, screen } from '@testing-library/react';
8
+ import userEvent from '@testing-library/user-event';
10
9
  import { axe } from 'jest-axe';
11
10
  import { ThemeUIProvider } from 'theme-ui';
12
11
 
@@ -48,15 +47,23 @@ describe( '<Accordion />', () => {
48
47
  } );
49
48
 
50
49
  it( 'should open the content when clicking on its trigger', async () => {
50
+ const user = userEvent.setup();
51
+
51
52
  const { container } = renderComponent();
52
53
 
53
- fireEvent.click( screen.getByRole( 'button', { name: 'trigger two' } ) );
54
+ await user.click( screen.getByRole( 'button', { name: 'trigger two', expanded: false } ) );
54
55
 
55
- // Should find the open content
56
- expect( screen.queryByText( 'content one' ) ).toBeNull();
56
+ expect(
57
+ screen.getByRole( 'button', { name: 'trigger one', expanded: false } )
58
+ ).toHaveAttribute( 'data-state', 'closed' );
59
+ expect( screen.queryByText( 'content one' ) ).not.toBeInTheDocument();
57
60
 
58
- // Should not find the closed content
59
- expect( screen.queryByText( 'content two' ) ).toBeInTheDocument();
61
+ // Should find the open content
62
+ expect( screen.getByRole( 'button', { name: 'trigger two', expanded: true } ) ).toHaveAttribute(
63
+ 'data-state',
64
+ 'open'
65
+ );
66
+ expect( screen.getByText( 'content two' ) ).toBeVisible();
60
67
 
61
68
  // Check for accessibility issues
62
69
  expect( await axe( container ) ).toHaveNoViolations();
@@ -10,6 +10,7 @@ import { BiCalendarHeart } from 'react-icons/bi';
10
10
  * Internal dependencies
11
11
  */
12
12
  import { Button, ButtonVariant } from '..';
13
+ import { Flex } from '../Flex/Flex';
13
14
  import ScreenReaderText from '../ScreenReaderText';
14
15
 
15
16
  export default {
@@ -66,48 +67,56 @@ This documentation is heavily inspired by the [U.S Web Design System (USWDS)](ht
66
67
  };
67
68
 
68
69
  const Template = args => (
69
- <React.Fragment>
70
- <Button { ...args }>Primary</Button>
70
+ <div>
71
+ <Flex sx={ { gap: 2, flexDirection: 'row' } }>
72
+ <Button { ...args }>Primary</Button>
71
73
 
72
- <Button variant="secondary" sx={ { ml: 2 } } { ...args }>
73
- Secondary
74
- </Button>
74
+ <Button variant="secondary" sx={ { ml: 2 } } { ...args }>
75
+ Secondary
76
+ </Button>
75
77
 
76
- <Button variant="tertiary" sx={ { ml: 2 } } { ...args }>
77
- Tertiary
78
- </Button>
78
+ <Button variant="tertiary" sx={ { ml: 2 } } { ...args }>
79
+ Tertiary
80
+ </Button>
79
81
 
80
- <Button variant="ghost" sx={ { ml: 2 } } { ...args }>
81
- Ghost
82
- </Button>
82
+ <Button variant="ghost" sx={ { ml: 2 } } { ...args }>
83
+ Ghost
84
+ </Button>
83
85
 
84
- <Button variant="display" sx={ { ml: 2 } } { ...args }>
85
- Display
86
- </Button>
86
+ <Button variant="display" sx={ { ml: 2 } } { ...args }>
87
+ Display
88
+ </Button>
87
89
 
88
- <Button variant="danger" sx={ { ml: 2 } } { ...args }>
89
- Danger
90
- </Button>
90
+ <Button variant="danger" sx={ { ml: 2 } } { ...args }>
91
+ Danger
92
+ </Button>
91
93
 
92
- <Button variant="primary" disabled={ true } sx={ { ml: 2 } } { ...args }>
93
- Disabled
94
- </Button>
94
+ <Button variant="primary" disabled={ true } sx={ { ml: 2 } } { ...args }>
95
+ Disabled
96
+ </Button>
95
97
 
96
- <Button variant="text" sx={ { ml: 2 } } as="a" href="https://google/com" { ...args }>
97
- Button link
98
- </Button>
98
+ <Button variant="text" sx={ { ml: 2 } } as="a" href="https://google/com" { ...args }>
99
+ Button link
100
+ </Button>
101
+
102
+ <Button variant="icon" sx={ { ml: 2 } } type="button" { ...args }>
103
+ <BiCalendarHeart size={ 24 } />
104
+ <ScreenReaderText>domain.com</ScreenReaderText>
105
+ </Button>
106
+ </Flex>
99
107
 
100
- <Button variant="icon" sx={ { ml: 2 } } type="button" { ...args }>
101
- <BiCalendarHeart size={ 24 } />
102
- <ScreenReaderText>domain.com</ScreenReaderText>
103
- </Button>
108
+ <div sx={ { mt: 3 } }>
109
+ <Button variant="secondary" href="https://google/com" { ...args } full>
110
+ Button with full width
111
+ </Button>
112
+ </div>
104
113
 
105
- <div sx={ { maxWidth: '100px', mt: 3 } }>
106
- <Button variant="secondary" href="https://google/com" { ...args }>
107
- Button with constrained width
114
+ <div sx={ { mt: 3, display: 'flex' } }>
115
+ <Button variant="secondary" href="https://google/com" { ...args } grow>
116
+ Button with grow width
108
117
  </Button>
109
118
  </div>
110
- </React.Fragment>
119
+ </div>
111
120
  );
112
121
 
113
122
  export const Default = Template.bind( {} );
@@ -1,8 +1,5 @@
1
- /**
2
- * External dependencies
3
- */
4
1
  import classNames from 'classnames';
5
- import React, { useCallback, forwardRef, Ref } from 'react';
2
+ import React, { useCallback, forwardRef } from 'react';
6
3
  import { Theme, Button as ThemeButton, ButtonProps as ThemeButtonProps } from 'theme-ui';
7
4
 
8
5
  type ButtonClickType = React.MouseEvent< HTMLButtonElement, MouseEvent >;
@@ -25,11 +22,13 @@ export enum ButtonVariant {
25
22
  export interface ButtonProps extends ThemeButtonProps {
26
23
  disabled?: boolean;
27
24
  onClick?: ( event: ButtonClickType ) => void;
25
+ full?: boolean;
26
+ grow?: boolean;
28
27
  variant?: keyof typeof ButtonVariant; // converts the enum to a string union type
29
28
  }
30
29
 
31
30
  const Button = forwardRef< HTMLButtonElement, ButtonProps >(
32
- ( { className, disabled, onClick, sx, ...rest }: ButtonProps, ref: Ref< HTMLButtonElement > ) => {
31
+ ( { className, disabled, onClick, sx, full, grow, ...rest }, ref ) => {
33
32
  const handleOnClick = useCallback(
34
33
  ( event: ButtonClickType ) => {
35
34
  if ( disabled ) {
@@ -46,16 +45,6 @@ const Button = forwardRef< HTMLButtonElement, ButtonProps >(
46
45
  return (
47
46
  <ThemeButton
48
47
  sx={ {
49
- verticalAlign: 'middle',
50
- display: 'inline-flex',
51
- alignItems: 'center',
52
- justifyContent: 'center',
53
- minHeight: '36px',
54
- py: 0,
55
- textDecoration: 'none',
56
- '&:hover': {
57
- textDecoration: 'none',
58
- },
59
48
  '&:focus': 'none',
60
49
  '&:focus-visible': ( theme: ButtonTheme ) => theme.outline,
61
50
  '&[aria-disabled="true"]': {
@@ -65,6 +54,8 @@ const Button = forwardRef< HTMLButtonElement, ButtonProps >(
65
54
  cursor: 'not-allowed',
66
55
  pointerEvents: 'none',
67
56
  },
57
+ flexGrow: Boolean( grow ) === true ? '1' : undefined,
58
+ width: Boolean( full ) === true ? '100%' : undefined,
68
59
  ...sx,
69
60
  } }
70
61
  { ...rest }
@@ -28,7 +28,6 @@ export const Card = forwardRef< HTMLElement, CardBoxProps >(
28
28
  sx={ {
29
29
  // pass variant prop to sx
30
30
  variant: `cards.${ variant }`,
31
- overflow: 'hidden',
32
31
  ...sx,
33
32
  } }
34
33
  className={ classNames( 'vip-card-component', className ) }