@automattic/vip-design-system 2.10.2 → 2.10.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.
@@ -26,6 +26,8 @@ interface RootProps {
26
26
  className?: Argument;
27
27
  sx?: ThemeUIStyleObject;
28
28
  defaultValue?: string;
29
+ value?: string;
30
+ onValueChange?: (value: string) => void;
29
31
  }
30
32
  export declare const Item: {
31
33
  ({ children, ...props }: AccordionItemProps): React.JSX.Element;
@@ -10,13 +10,14 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
10
10
  import { render, screen } from '@testing-library/react';
11
11
  import userEvent from '@testing-library/user-event';
12
12
  import { axe } from 'jest-axe';
13
+ import { useState } from 'react';
13
14
  import { ThemeUIProvider } from 'theme-ui';
14
15
 
15
16
  /**
16
17
  * Internal dependencies
17
18
  */
18
19
  import * as Accordion from './Accordion';
19
- import { theme } from '../';
20
+ import { Button, theme } from '../';
20
21
  import { jsx as _jsx } from "theme-ui/jsx-runtime";
21
22
  import { jsxs as _jsxs } from "theme-ui/jsx-runtime";
22
23
  var renderWithTheme = function renderWithTheme(children) {
@@ -25,7 +26,7 @@ var renderWithTheme = function renderWithTheme(children) {
25
26
  children: children
26
27
  }));
27
28
  };
28
- var renderComponent = function renderComponent() {
29
+ var renderUncontrolledComponent = function renderUncontrolledComponent() {
29
30
  return renderWithTheme(_jsxs(Accordion.Root, {
30
31
  defaultValue: "one",
31
32
  sx: {
@@ -48,7 +49,60 @@ var renderComponent = function renderComponent() {
48
49
  })]
49
50
  }));
50
51
  };
51
- describe('<Accordion />', function () {
52
+ var renderControlledComponent = function renderControlledComponent() {
53
+ var ControlledComponent = function ControlledComponent() {
54
+ var _useState = useState('one'),
55
+ value = _useState[0],
56
+ setValue = _useState[1];
57
+ return _jsxs(Accordion.Root, {
58
+ value: value,
59
+ onValueChange: setValue,
60
+ children: [_jsxs(Accordion.Item, {
61
+ value: "one",
62
+ children: [_jsx(Button, {
63
+ "aria-controls": "manage-content-one",
64
+ "aria-expanded": value === 'one' ? 'true' : 'false',
65
+ "data-state": value === 'one' ? 'open' : 'closed',
66
+ onClick: function onClick() {
67
+ if (value === 'one') {
68
+ setValue('');
69
+ } else {
70
+ setValue('one');
71
+ }
72
+ },
73
+ children: "trigger one"
74
+ }), _jsx(Accordion.Content, {
75
+ id: "manage-content-one",
76
+ children: "content one"
77
+ })]
78
+ }), _jsxs(Accordion.Item, {
79
+ value: "two",
80
+ children: [_jsx(Button, {
81
+ "aria-controls": "manage-content-two",
82
+ "aria-expanded": value === 'two' ? 'true' : 'false',
83
+ "data-state": value === 'two' ? 'open' : 'closed',
84
+ onClick: function onClick() {
85
+ if (value === 'two') {
86
+ setValue('');
87
+ } else {
88
+ setValue('two');
89
+ }
90
+ },
91
+ children: "trigger two"
92
+ }), _jsx(Accordion.Content, {
93
+ id: "manage-content-two",
94
+ children: "content two"
95
+ })]
96
+ })]
97
+ });
98
+ };
99
+ return renderWithTheme(_jsx(ControlledComponent, {}));
100
+ };
101
+ describe.each([['Uncontrolled', renderUncontrolledComponent], ['Controlled', renderControlledComponent]])('<Accordion />, %s', function () {
102
+ for (var _len = arguments.length, modeAndComponent = new Array(_len), _key = 0; _key < _len; _key++) {
103
+ modeAndComponent[_key] = arguments[_key];
104
+ }
105
+ var renderComponent = modeAndComponent[1];
52
106
  it('renders the Accordion component with default value visible', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
53
107
  var _renderComponent, container;
54
108
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -4,12 +4,18 @@
4
4
  */
5
5
  import { Argument } from 'classnames';
6
6
  import React, { ReactNode } from 'react';
7
- export interface CodeProps {
7
+ export type CodeProps = React.ComponentPropsWithoutRef<'code'> & {
8
8
  prompt?: boolean;
9
9
  showCopy?: boolean;
10
10
  onCopy?: () => void;
11
11
  className?: Argument;
12
12
  children?: ReactNode;
13
- }
14
- declare const Code: React.ForwardRefExoticComponent<CodeProps & React.RefAttributes<HTMLDivElement>>;
13
+ };
14
+ declare const Code: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & {
15
+ prompt?: boolean | undefined;
16
+ showCopy?: boolean | undefined;
17
+ onCopy?: (() => void) | undefined;
18
+ className?: Argument;
19
+ children?: ReactNode;
20
+ } & React.RefAttributes<HTMLDivElement>>;
15
21
  export { Code };
@@ -9,7 +9,13 @@ import type { StoryObj } from '@storybook/react';
9
9
  */
10
10
  declare const _default: {
11
11
  title: string;
12
- component: React.ForwardRefExoticComponent<import("./Code").CodeProps & React.RefAttributes<HTMLDivElement>>;
12
+ component: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & {
13
+ prompt?: boolean | undefined;
14
+ showCopy?: boolean | undefined;
15
+ onCopy?: (() => void) | undefined;
16
+ className?: import("classnames").Argument;
17
+ children?: React.ReactNode;
18
+ } & React.RefAttributes<HTMLDivElement>>;
13
19
  };
14
20
  export default _default;
15
21
  type Story = StoryObj<typeof Code>;
@@ -19,7 +19,8 @@ export default {
19
19
 
20
20
  const defaultProps = {
21
21
  title: 'User settings',
22
- description: 'Use this form to manage your settings',
22
+ description:
23
+ "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book",
23
24
  };
24
25
 
25
26
  export const Default = () => (
@@ -13,6 +13,7 @@ export var contentStyles = {
13
13
  maxWidth: '640px',
14
14
  maxHeight: '85vh',
15
15
  padding: 6,
16
+ overflowY: 'auto',
16
17
  '> h1, > h2': {
17
18
  marginTop: '0 !important'
18
19
  }
@@ -1,6 +1,9 @@
1
1
  import React from 'react';
2
- export interface FormProps {
2
+ export type FormProps = React.ComponentPropsWithoutRef<'form'> & {
3
3
  children?: React.ReactNode;
4
4
  className?: string;
5
- }
6
- export declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
5
+ };
6
+ export declare const Form: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref"> & {
7
+ children?: React.ReactNode;
8
+ className?: string | undefined;
9
+ } & React.RefAttributes<HTMLFormElement>>;
@@ -1,5 +1,8 @@
1
1
  export default Root;
2
- export const Root: import("react").ForwardRefExoticComponent<import("./Form").FormProps & import("react").RefAttributes<HTMLFormElement>>;
2
+ export const Root: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref"> & {
3
+ children?: import("react").ReactNode;
4
+ className?: string | undefined;
5
+ } & import("react").RefAttributes<HTMLFormElement>>;
3
6
  export const Select: import("react").ForwardRefExoticComponent<import("react").RefAttributes<any>>;
4
7
  export const Autocomplete: import("react").ForwardRefExoticComponent<import("react").RefAttributes<any>>;
5
8
  export const AutocompleteMulti: import("react").ForwardRefExoticComponent<import("react").RefAttributes<any>>;
@@ -1,7 +1,7 @@
1
1
  /** @jsxImportSource theme-ui */
2
2
  import React from 'react';
3
3
  import { ThemeUIStyleObject } from 'theme-ui';
4
- export interface NoticeProps {
4
+ export type NoticeProps = React.HTMLAttributes<HTMLDivElement> & {
5
5
  children: React.ReactNode;
6
6
  inline?: boolean;
7
7
  sx?: ThemeUIStyleObject;
@@ -9,7 +9,15 @@ export interface NoticeProps {
9
9
  variant?: ColorVariants;
10
10
  headingVariant?: React.ElementType;
11
11
  className?: string;
12
- }
12
+ };
13
13
  type ColorVariants = 'warning' | 'error' | 'alert' | 'success' | 'info';
14
- export declare const Notice: React.ForwardRefExoticComponent<NoticeProps & React.RefAttributes<HTMLDivElement>>;
14
+ export declare const Notice: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
15
+ children: React.ReactNode;
16
+ inline?: boolean | undefined;
17
+ sx?: ThemeUIStyleObject | undefined;
18
+ title?: React.ReactNode;
19
+ variant?: ColorVariants | undefined;
20
+ headingVariant?: React.ElementType<any> | undefined;
21
+ className?: string | undefined;
22
+ } & React.RefAttributes<HTMLDivElement>>;
15
23
  export {};
@@ -8,7 +8,15 @@
8
8
  import React from 'react';
9
9
  declare const _default: {
10
10
  title: string;
11
- component: React.ForwardRefExoticComponent<import("./Notice").NoticeProps & React.RefAttributes<HTMLDivElement>>;
11
+ component: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
12
+ children: React.ReactNode;
13
+ inline?: boolean | undefined;
14
+ sx?: import("theme-ui").ThemeUIStyleObject | undefined;
15
+ title?: React.ReactNode;
16
+ variant?: ("alert" | "error" | "success" | "warning" | "info") | undefined;
17
+ headingVariant?: React.ElementType<any> | undefined;
18
+ className?: string | undefined;
19
+ } & React.RefAttributes<HTMLDivElement>>;
12
20
  };
13
21
  export default _default;
14
22
  export declare const Default: () => React.JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip-design-system",
3
- "version": "2.10.2",
3
+ "version": "2.10.3",
4
4
  "main": "build/system/index.js",
5
5
  "scripts": {
6
6
  "build-storybook": "storybook build",
@@ -7,18 +7,19 @@
7
7
  import { render, screen } from '@testing-library/react';
8
8
  import userEvent from '@testing-library/user-event';
9
9
  import { axe } from 'jest-axe';
10
+ import { useState } from 'react';
10
11
  import { ThemeUIProvider } from 'theme-ui';
11
12
 
12
13
  /**
13
14
  * Internal dependencies
14
15
  */
15
16
  import * as Accordion from './Accordion';
16
- import { theme } from '../';
17
+ import { Button, theme } from '../';
17
18
 
18
19
  const renderWithTheme = children =>
19
20
  render( <ThemeUIProvider theme={ theme }>{ children }</ThemeUIProvider> );
20
21
 
21
- const renderComponent = () =>
22
+ const renderUncontrolledComponent = () =>
22
23
  renderWithTheme(
23
24
  <Accordion.Root defaultValue="one" sx={ { width: '400px' } }>
24
25
  <Accordion.Item value="one">
@@ -32,7 +33,58 @@ const renderComponent = () =>
32
33
  </Accordion.Root>
33
34
  );
34
35
 
35
- describe( '<Accordion />', () => {
36
+ const renderControlledComponent = () => {
37
+ const ControlledComponent = () => {
38
+ const [ value, setValue ] = useState( 'one' );
39
+
40
+ return (
41
+ <Accordion.Root value={ value } onValueChange={ setValue }>
42
+ <Accordion.Item value="one">
43
+ <Button
44
+ aria-controls="manage-content-one"
45
+ aria-expanded={ value === 'one' ? 'true' : 'false' }
46
+ data-state={ value === 'one' ? 'open' : 'closed' }
47
+ onClick={ () => {
48
+ if ( value === 'one' ) {
49
+ setValue( '' );
50
+ } else {
51
+ setValue( 'one' );
52
+ }
53
+ } }
54
+ >
55
+ trigger one
56
+ </Button>
57
+ <Accordion.Content id="manage-content-one">content one</Accordion.Content>
58
+ </Accordion.Item>
59
+ <Accordion.Item value="two">
60
+ <Button
61
+ aria-controls="manage-content-two"
62
+ aria-expanded={ value === 'two' ? 'true' : 'false' }
63
+ data-state={ value === 'two' ? 'open' : 'closed' }
64
+ onClick={ () => {
65
+ if ( value === 'two' ) {
66
+ setValue( '' );
67
+ } else {
68
+ setValue( 'two' );
69
+ }
70
+ } }
71
+ >
72
+ trigger two
73
+ </Button>
74
+ <Accordion.Content id="manage-content-two">content two</Accordion.Content>
75
+ </Accordion.Item>
76
+ </Accordion.Root>
77
+ );
78
+ };
79
+
80
+ return renderWithTheme( <ControlledComponent /> );
81
+ };
82
+
83
+ describe.each( [
84
+ [ 'Uncontrolled', renderUncontrolledComponent ],
85
+ [ 'Controlled', renderControlledComponent ],
86
+ ] )( '<Accordion />, %s', ( ...modeAndComponent ) => {
87
+ const [ , renderComponent ] = modeAndComponent;
36
88
  it( 'renders the Accordion component with default value visible', async () => {
37
89
  const { container } = renderComponent();
38
90
 
@@ -54,6 +54,8 @@ interface RootProps {
54
54
  className?: Argument;
55
55
  sx?: ThemeUIStyleObject;
56
56
  defaultValue?: string;
57
+ value?: string;
58
+ onValueChange?: ( value: string ) => void;
57
59
  }
58
60
  export const Item = ( { children, ...props }: AccordionItemProps ) => (
59
61
  <AccordionPrimitive.Item
@@ -7,13 +7,13 @@ import classNames, { Argument } from 'classnames';
7
7
  import React, { ReactNode, createRef, useState } from 'react';
8
8
  import { MdContentCopy } from 'react-icons/md';
9
9
 
10
- export interface CodeProps {
10
+ export type CodeProps = React.ComponentPropsWithoutRef< 'code' > & {
11
11
  prompt?: boolean;
12
12
  showCopy?: boolean;
13
13
  onCopy?: () => void;
14
14
  className?: Argument;
15
15
  children?: ReactNode;
16
- }
16
+ };
17
17
 
18
18
  const Code = React.forwardRef< HTMLDivElement, CodeProps >(
19
19
  ( { prompt = false, showCopy = false, onCopy, className, ...props }: CodeProps, forwardRef ) => {
@@ -19,7 +19,8 @@ export default {
19
19
 
20
20
  const defaultProps = {
21
21
  title: 'User settings',
22
- description: 'Use this form to manage your settings',
22
+ description:
23
+ "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book",
23
24
  };
24
25
 
25
26
  export const Default = () => (
@@ -15,5 +15,6 @@ export const contentStyles: ThemeUIStyleObject = {
15
15
  maxWidth: '640px',
16
16
  maxHeight: '85vh',
17
17
  padding: 6,
18
+ overflowY: 'auto',
18
19
  '> h1, > h2': { marginTop: '0 !important' },
19
20
  };
@@ -3,10 +3,10 @@
3
3
  */
4
4
  import classNames from 'classnames';
5
5
  import React from 'react';
6
- export interface FormProps {
6
+ export type FormProps = React.ComponentPropsWithoutRef< 'form' > & {
7
7
  children?: React.ReactNode;
8
8
  className?: string;
9
- }
9
+ };
10
10
  export const Form = React.forwardRef< HTMLFormElement, FormProps >(
11
11
  ( { children, className, ...props }, forwardRef ) => (
12
12
  <form
@@ -18,7 +18,7 @@ interface NoticeIconProps {
18
18
  variant: ColorVariants;
19
19
  }
20
20
 
21
- export interface NoticeProps {
21
+ export type NoticeProps = React.HTMLAttributes< HTMLDivElement > & {
22
22
  children: React.ReactNode;
23
23
  inline?: boolean;
24
24
  sx?: ThemeUIStyleObject;
@@ -26,7 +26,7 @@ export interface NoticeProps {
26
26
  variant?: ColorVariants;
27
27
  headingVariant?: React.ElementType;
28
28
  className?: string;
29
- }
29
+ };
30
30
  type ColorVariants = 'warning' | 'error' | 'alert' | 'success' | 'info';
31
31
 
32
32
  const NoticeIcon = ( { color, variant }: NoticeIconProps ) => {