@automattic/vip-design-system 0.20.1 → 0.22.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.
Files changed (47) hide show
  1. package/build/system/Avatar/Avatar.js +7 -3
  2. package/build/system/Badge/Badge.js +7 -3
  3. package/build/system/Box/Box.js +4 -3
  4. package/build/system/Code/Code.js +10 -4
  5. package/build/system/Flex/Flex.js +10 -5
  6. package/build/system/Form/Label.js +12 -4
  7. package/build/system/Form/Radio.js +7 -3
  8. package/build/system/Form/RadioBoxGroup.js +7 -3
  9. package/build/system/Form/Toggle.js +7 -3
  10. package/build/system/Form/ToggleGroup.js +7 -3
  11. package/build/system/Link/Link.js +7 -3
  12. package/build/system/Notice/Notice.js +2 -1
  13. package/build/system/Notification/Notification.js +6 -2
  14. package/build/system/OptionRow/OptionRow.js +5 -3
  15. package/build/system/ScreenReaderText/ScreenReaderText.js +16 -13
  16. package/build/system/Spinner/Spinner.js +7 -3
  17. package/build/system/Table/Table.js +22 -4
  18. package/build/system/Table/Table.stories.js +5 -1
  19. package/build/system/Tabs/Tabs.js +7 -3
  20. package/build/system/Text/Text.js +7 -3
  21. package/build/system/Wizard/Wizard.js +4 -2
  22. package/build/system/Wizard/WizardStep.js +6 -2
  23. package/build/system/Wizard/WizardStepHorizontal.js +6 -2
  24. package/package.json +1 -1
  25. package/src/system/Avatar/Avatar.js +54 -53
  26. package/src/system/Badge/Badge.js +24 -19
  27. package/src/system/Box/Box.js +2 -2
  28. package/src/system/Code/Code.js +81 -76
  29. package/src/system/Flex/Flex.js +6 -1
  30. package/src/system/Form/Label.js +10 -2
  31. package/src/system/Form/Radio.js +11 -3
  32. package/src/system/Form/RadioBoxGroup.js +52 -46
  33. package/src/system/Form/Toggle.js +50 -50
  34. package/src/system/Form/ToggleGroup.js +49 -43
  35. package/src/system/Link/Link.js +6 -2
  36. package/src/system/Notice/Notice.js +1 -1
  37. package/src/system/Notification/Notification.js +41 -34
  38. package/src/system/OptionRow/OptionRow.js +86 -78
  39. package/src/system/ScreenReaderText/ScreenReaderText.js +14 -17
  40. package/src/system/Spinner/Spinner.js +6 -2
  41. package/src/system/Table/Table.js +25 -10
  42. package/src/system/Table/Table.stories.jsx +4 -1
  43. package/src/system/Tabs/Tabs.js +6 -2
  44. package/src/system/Text/Text.js +6 -2
  45. package/src/system/Wizard/Wizard.js +49 -45
  46. package/src/system/Wizard/WizardStep.js +63 -57
  47. package/src/system/Wizard/WizardStepHorizontal.js +6 -2
@@ -10,24 +10,21 @@ import PropTypes from 'prop-types';
10
10
  * Internal dependencies
11
11
  */
12
12
 
13
+ export const screenReaderTextClass = {
14
+ border: 'none',
15
+ clip: 'rect(1px, 1px, 1px, 1px)',
16
+ clipPath: 'inset(50%)',
17
+ height: '1px',
18
+ margin: '-1px',
19
+ overflow: 'hidden',
20
+ padding: '0',
21
+ position: 'absolute',
22
+ width: '1px',
23
+ wordWrap: 'normal !important',
24
+ };
25
+
13
26
  export const ScreenReaderText = React.forwardRef( ( props, forwardRef ) => (
14
- <span
15
- className="screen-reader-text"
16
- sx={ {
17
- border: 'none',
18
- clip: 'rect(1px, 1px, 1px, 1px)',
19
- clipPath: 'inset(50%)',
20
- height: '1px',
21
- margin: '-1px',
22
- overflow: 'hidden',
23
- padding: '0',
24
- position: 'absolute',
25
- width: '1px',
26
- wordWrap: 'normal !important',
27
- } }
28
- { ...props }
29
- ref={ forwardRef }
30
- >
27
+ <span className="screen-reader-text" sx={ screenReaderTextClass } { ...props } ref={ forwardRef }>
31
28
  { props.children }
32
29
  </span>
33
30
  ) );
@@ -3,11 +3,12 @@
3
3
  /**
4
4
  * External dependencies
5
5
  */
6
+ import React from 'react';
6
7
  import { Spinner as ThemeSpinner } from 'theme-ui';
7
8
  import PropTypes from 'prop-types';
8
9
  import classNames from 'classnames';
9
10
 
10
- const Spinner = ( { sx, className = null, ...props } ) => (
11
+ const Spinner = React.forwardRef( ( { sx, className = null, ...props }, forwardRef ) => (
11
12
  <ThemeSpinner
12
13
  strokeWidth={ 2 }
13
14
  sx={ {
@@ -15,9 +16,12 @@ const Spinner = ( { sx, className = null, ...props } ) => (
15
16
  color: 'primary',
16
17
  } }
17
18
  className={ classNames( 'vip-spinner-component', className ) }
19
+ ref={ forwardRef }
18
20
  { ...props }
19
21
  />
20
- );
22
+ ) );
23
+
24
+ Spinner.displayName = 'Spinner';
21
25
 
22
26
  Spinner.propTypes = {
23
27
  sx: PropTypes.object,
@@ -6,23 +6,38 @@
6
6
  import React from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import classNames from 'classnames';
9
+ import { screenReaderTextClass } from '../ScreenReaderText/ScreenReaderText';
9
10
 
10
- const Table = React.forwardRef( ( { sx, className, ...props }, forwardRef ) => (
11
- <table
12
- sx={ { width: '100%', minWidth: 1024, ...sx } }
13
- cellPadding={ 0 }
14
- cellSpacing={ 0 }
15
- className={ classNames( 'vip-table-component', className ) }
16
- ref={ forwardRef }
17
- { ...props }
18
- />
19
- ) );
11
+ const Table = React.forwardRef(
12
+ ( { sx, className, children, caption = null, ...props }, forwardRef ) => {
13
+ if ( ! caption ) {
14
+ // eslint-disable-next-line no-console
15
+ console.warn( '[A11Y] Please, add a caption to your table.' );
16
+ }
17
+
18
+ return (
19
+ <table
20
+ sx={ { width: '100%', minWidth: 1024, ...sx } }
21
+ cellPadding={ 0 }
22
+ cellSpacing={ 0 }
23
+ className={ classNames( 'vip-table-component', className ) }
24
+ ref={ forwardRef }
25
+ { ...props }
26
+ >
27
+ { caption && <caption sx={ screenReaderTextClass }>{ caption }</caption> }
28
+ { children }
29
+ </table>
30
+ );
31
+ }
32
+ );
20
33
 
21
34
  Table.displayName = 'Table';
22
35
 
23
36
  Table.propTypes = {
24
37
  sx: PropTypes.object,
25
38
  className: PropTypes.any,
39
+ children: PropTypes.any,
40
+ caption: PropTypes.string.isRequired,
26
41
  };
27
42
 
28
43
  export { Table };
@@ -1,3 +1,5 @@
1
+ /** @jsxImportSource theme-ui */
2
+
1
3
  /**
2
4
  * Internal dependencies
3
5
  */
@@ -9,7 +11,7 @@ export default {
9
11
  };
10
12
 
11
13
  export const Default = () => (
12
- <Table>
14
+ <Table caption="Storybook Example">
13
15
  <thead>
14
16
  <TableRow head cells={ [ 'User', 'Command', 'Duration', 'Time' ] } />
15
17
  </thead>
@@ -35,6 +37,7 @@ export const Default = () => (
35
37
  11th Mar 2020, 16:49:22
36
38
  </Text>,
37
39
  ] }
40
+ gbc
38
41
  />
39
42
  <TableRow>
40
43
  <TableCell sx={ { backgroundColor: 'lightgray' } }>
@@ -3,6 +3,7 @@
3
3
  /**
4
4
  * External dependencies
5
5
  */
6
+ import React from 'react';
6
7
  import classNames from 'classnames';
7
8
  import PropTypes from 'prop-types';
8
9
 
@@ -11,7 +12,7 @@ import PropTypes from 'prop-types';
11
12
  */
12
13
  import { Flex } from '..';
13
14
 
14
- const Tabs = ( { className = null, sx, ...props } ) => (
15
+ const Tabs = React.forwardRef( ( { className = null, sx, ...props }, forwardRef ) => (
15
16
  <Flex
16
17
  className={ classNames( 'vip-tabs-component', className ) }
17
18
  sx={ {
@@ -22,9 +23,12 @@ const Tabs = ( { className = null, sx, ...props } ) => (
22
23
  padding: 0,
23
24
  ...sx,
24
25
  } }
26
+ ref={ forwardRef }
25
27
  { ...props }
26
28
  />
27
- );
29
+ ) );
30
+
31
+ Tabs.displayName = 'Tabs';
28
32
 
29
33
  Tabs.propTypes = {
30
34
  className: PropTypes.any,
@@ -3,11 +3,12 @@
3
3
  /**
4
4
  * External dependencies
5
5
  */
6
+ import React from 'react';
6
7
  import { Text as ThemeText } from 'theme-ui';
7
8
  import PropTypes from 'prop-types';
8
9
  import classNames from 'classnames';
9
10
 
10
- const Text = ( { sx, className = null, ...props } ) => (
11
+ const Text = React.forwardRef( ( { sx, className = null, ...props }, forwardRef ) => (
11
12
  <ThemeText
12
13
  as="p"
13
14
  sx={ {
@@ -16,9 +17,12 @@ const Text = ( { sx, className = null, ...props } ) => (
16
17
  ...sx,
17
18
  } }
18
19
  className={ classNames( 'vip-text-component', className ) }
20
+ ref={ forwardRef }
19
21
  { ...props }
20
22
  />
21
- );
23
+ ) );
24
+
25
+ Text.displayName = 'Text';
22
26
 
23
27
  Text.propTypes = {
24
28
  sx: PropTypes.object,
@@ -13,51 +13,55 @@ import { MdArrowForward } from 'react-icons/md';
13
13
  */
14
14
  import { Box, WizardStep, Flex, WizardStepHorizontal } from '..';
15
15
 
16
- const Wizard = ( { steps, activeStep, variant, completed = [], className = null, ...props } ) => {
17
- return (
18
- <Box className={ classNames( 'vip-wizard-component', className ) }>
19
- { variant === 'horizontal' ? (
20
- <Box>
21
- <Flex
22
- sx={ {
23
- flex: '0 0 auto',
24
- } }
25
- { ...props }
26
- >
27
- { steps.map( ( { title, subTitle, titleVariant }, index ) => (
28
- <React.Fragment key={ index }>
29
- <WizardStepHorizontal
30
- active={ index === activeStep }
31
- order={ index + 1 }
32
- subTitle={ subTitle }
33
- title={ title }
34
- titleVariant={ titleVariant }
35
- />
36
- { index < steps.length - 1 && (
37
- <MdArrowForward sx={ { mx: 2, color: 'grey.80' } } />
38
- ) }
39
- </React.Fragment>
40
- ) ) }
41
- </Flex>
42
- { steps[ activeStep ].children }
43
- </Box>
44
- ) : (
45
- steps.map( ( { title, subTitle, children }, index ) => (
46
- <WizardStep
47
- active={ index === activeStep }
48
- complete={ completed.includes( index ) }
49
- key={ index }
50
- order={ index + 1 }
51
- subTitle={ subTitle }
52
- title={ title }
53
- >
54
- { children }
55
- </WizardStep>
56
- ) )
57
- ) }
58
- </Box>
59
- );
60
- };
16
+ const Wizard = React.forwardRef(
17
+ ( { steps, activeStep, variant, completed = [], className = null, ...props }, forwardRef ) => {
18
+ return (
19
+ <Box className={ classNames( 'vip-wizard-component', className ) } ref={ forwardRef }>
20
+ { variant === 'horizontal' ? (
21
+ <Box>
22
+ <Flex
23
+ sx={ {
24
+ flex: '0 0 auto',
25
+ } }
26
+ { ...props }
27
+ >
28
+ { steps.map( ( { title, subTitle, titleVariant }, index ) => (
29
+ <React.Fragment key={ index }>
30
+ <WizardStepHorizontal
31
+ active={ index === activeStep }
32
+ order={ index + 1 }
33
+ subTitle={ subTitle }
34
+ title={ title }
35
+ titleVariant={ titleVariant }
36
+ />
37
+ { index < steps.length - 1 && (
38
+ <MdArrowForward sx={ { mx: 2, color: 'grey.80' } } />
39
+ ) }
40
+ </React.Fragment>
41
+ ) ) }
42
+ </Flex>
43
+ { steps[ activeStep ].children }
44
+ </Box>
45
+ ) : (
46
+ steps.map( ( { title, subTitle, children }, index ) => (
47
+ <WizardStep
48
+ active={ index === activeStep }
49
+ complete={ completed.includes( index ) }
50
+ key={ index }
51
+ order={ index + 1 }
52
+ subTitle={ subTitle }
53
+ title={ title }
54
+ >
55
+ { children }
56
+ </WizardStep>
57
+ ) )
58
+ ) }
59
+ </Box>
60
+ );
61
+ }
62
+ );
63
+
64
+ Wizard.displayName = 'Wizard';
61
65
 
62
66
  Wizard.propTypes = {
63
67
  steps: PropTypes.array,
@@ -3,6 +3,7 @@
3
3
  /**
4
4
  * External dependencies
5
5
  */
6
+ import React from 'react';
6
7
  import { MdCheckCircle } from 'react-icons/md';
7
8
  import PropTypes from 'prop-types';
8
9
 
@@ -11,69 +12,74 @@ import PropTypes from 'prop-types';
11
12
  */
12
13
  import { Card, Heading, Text, Flex } from '..';
13
14
 
14
- const WizardStep = ( { title, subTitle, complete = false, children, active, order } ) => {
15
- let borderLeftColor = 'border';
15
+ const WizardStep = React.forwardRef(
16
+ ( { title, subTitle, complete = false, children, active, order }, forwardRef ) => {
17
+ let borderLeftColor = 'border';
16
18
 
17
- if ( complete ) {
18
- borderLeftColor = 'success';
19
- } else if ( active ) {
20
- borderLeftColor = 'primary';
21
- }
19
+ if ( complete ) {
20
+ borderLeftColor = 'success';
21
+ } else if ( active ) {
22
+ borderLeftColor = 'primary';
23
+ }
22
24
 
23
- let color = 'muted';
25
+ let color = 'muted';
24
26
 
25
- if ( complete ) {
26
- color = 'success';
27
- } else if ( active ) {
28
- color = 'heading';
29
- }
27
+ if ( complete ) {
28
+ color = 'success';
29
+ } else if ( active ) {
30
+ color = 'heading';
31
+ }
30
32
 
31
- return (
32
- <Card
33
- sx={ {
34
- boxShadow: active ? 'low' : 'none',
35
- borderLeft: '2px solid',
36
- p: 4,
37
- backgroundColor: active ? 'card' : 'transparent',
38
- borderRadius: 0,
39
- borderBottom: active ? 'none' : '1px solid',
40
- '&:first-of-type': {
41
- borderTopWidth: '1px',
42
- borderTopStyle: 'solid',
43
- borderTopColor: 'borders.2',
44
- },
45
- borderColor: active ? 'primary' : 'borders.2',
46
- borderLeftColor: borderLeftColor,
47
- } }
48
- data-step={ order }
49
- data-active={ active || undefined }
50
- >
51
- { typeof title === 'string' ? (
52
- <Heading
53
- variant="h4"
54
- sx={ {
55
- mb: 0,
56
- display: 'flex',
57
- alignItems: 'center',
58
- color: color,
59
- } }
60
- >
61
- <MdCheckCircle aria-hidden="true" sx={ { mr: 2 } } />
62
- { title }
63
- </Heading>
64
- ) : (
65
- <Flex sx={ { alignItems: 'center', color } }>
66
- <MdCheckCircle aria-hidden="true" sx={ { mr: 2 } } />
67
- { title }
68
- </Flex>
69
- ) }
33
+ return (
34
+ <Card
35
+ sx={ {
36
+ boxShadow: active ? 'low' : 'none',
37
+ borderLeft: '2px solid',
38
+ p: 4,
39
+ backgroundColor: active ? 'card' : 'transparent',
40
+ borderRadius: 0,
41
+ borderBottom: active ? 'none' : '1px solid',
42
+ '&:first-of-type': {
43
+ borderTopWidth: '1px',
44
+ borderTopStyle: 'solid',
45
+ borderTopColor: 'borders.2',
46
+ },
47
+ borderColor: active ? 'primary' : 'borders.2',
48
+ borderLeftColor: borderLeftColor,
49
+ } }
50
+ data-step={ order }
51
+ data-active={ active || undefined }
52
+ ref={ forwardRef }
53
+ >
54
+ { typeof title === 'string' ? (
55
+ <Heading
56
+ variant="h4"
57
+ sx={ {
58
+ mb: 0,
59
+ display: 'flex',
60
+ alignItems: 'center',
61
+ color: color,
62
+ } }
63
+ >
64
+ <MdCheckCircle aria-hidden="true" sx={ { mr: 2 } } />
65
+ { title }
66
+ </Heading>
67
+ ) : (
68
+ <Flex sx={ { alignItems: 'center', color } }>
69
+ <MdCheckCircle aria-hidden="true" sx={ { mr: 2 } } />
70
+ { title }
71
+ </Flex>
72
+ ) }
70
73
 
71
- { subTitle && active && <Text sx={ { mb: 3 } }>{ subTitle }</Text> }
74
+ { subTitle && active && <Text sx={ { mb: 3 } }>{ subTitle }</Text> }
72
75
 
73
- { active && children }
74
- </Card>
75
- );
76
- };
76
+ { active && children }
77
+ </Card>
78
+ );
79
+ }
80
+ );
81
+
82
+ WizardStep.displayName = 'WizardStep';
77
83
 
78
84
  WizardStep.propTypes = {
79
85
  active: PropTypes.bool,
@@ -3,6 +3,7 @@
3
3
  /**
4
4
  * External dependencies
5
5
  */
6
+ import React from 'react';
6
7
  import { MdCheckCircle } from 'react-icons/md';
7
8
  import PropTypes from 'prop-types';
8
9
 
@@ -11,7 +12,7 @@ import PropTypes from 'prop-types';
11
12
  */
12
13
  import { Heading, Flex } from '..';
13
14
 
14
- const WizardStepHorizontal = ( { title, active, order } ) => {
15
+ const WizardStepHorizontal = React.forwardRef( ( { title, active, order }, forwardRef ) => {
15
16
  const color = active ? 'heading' : 'muted';
16
17
 
17
18
  return typeof title === 'string' ? (
@@ -25,6 +26,7 @@ const WizardStepHorizontal = ( { title, active, order } ) => {
25
26
  } }
26
27
  data-step={ order }
27
28
  data-active={ active || undefined }
29
+ ref={ forwardRef }
28
30
  >
29
31
  <MdCheckCircle aria-hidden="true" sx={ { mr: 2 } } />
30
32
  { title }
@@ -35,7 +37,9 @@ const WizardStepHorizontal = ( { title, active, order } ) => {
35
37
  { title }
36
38
  </Flex>
37
39
  );
38
- };
40
+ } );
41
+
42
+ WizardStepHorizontal.displayName = 'WizardStepHorizontal';
39
43
 
40
44
  WizardStepHorizontal.propTypes = {
41
45
  active: PropTypes.bool,