@transferwise/components 0.0.0-experimental-1bc0453 → 0.0.0-experimental-9956441
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/divider/Divider.js +2 -2
- package/build/divider/Divider.js.map +1 -1
- package/build/divider/Divider.mjs +2 -2
- package/build/divider/Divider.mjs.map +1 -1
- package/build/types/divider/Divider.d.ts +18 -18
- package/build/types/divider/Divider.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/divider/Divider.accessibility.docs.mdx +61 -0
- package/src/divider/Divider.spec.tsx +11 -30
- package/src/divider/Divider.story.tsx +110 -7
- package/src/divider/Divider.tsx +21 -21
package/build/divider/Divider.js
CHANGED
|
@@ -5,8 +5,8 @@ require('react');
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
|
|
7
7
|
const Divider = ({
|
|
8
|
-
as = 'div',
|
|
9
8
|
className,
|
|
9
|
+
isContent = false,
|
|
10
10
|
testId,
|
|
11
11
|
variant = 'section',
|
|
12
12
|
...props
|
|
@@ -20,7 +20,7 @@ const Divider = ({
|
|
|
20
20
|
...commonProps,
|
|
21
21
|
role: 'presentation'
|
|
22
22
|
};
|
|
23
|
-
return
|
|
23
|
+
return isContent ? /*#__PURE__*/jsxRuntime.jsx("hr", {
|
|
24
24
|
...commonProps,
|
|
25
25
|
...props
|
|
26
26
|
}) : /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Divider.js","sources":["../../src/divider/Divider.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport React, { FunctionComponent } from 'react';\n\nexport interface DividerProps {\n
|
|
1
|
+
{"version":3,"file":"Divider.js","sources":["../../src/divider/Divider.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport React, { FunctionComponent } from 'react';\n\nexport interface DividerProps {\n /**\n * If `true`, renders the Divider as a semantic `<hr>`, providing clear separation to assistive technologies.\n * Otherwise, a non-semantic `<div role=\"presentation\">` is used for purely visual separation.\n * @default false\n */\n isContent?: boolean;\n\n /**\n * Appends additional class names to style the `Divider`.\n */\n className?: string;\n\n /**\n * Provides a `data-testid` attribute for testing.\n */\n testId?: string;\n\n /**\n * Alters the visual style of the divider, accommodating different types\n * of separated content. Accepts `'section'`, `'subsection'`, or `'content'`.\n * @default 'section'\n */\n variant?: 'section' | 'subsection' | 'content';\n}\n\n/**\n * @see {@link Divider} for further information.\n * @see {@link https://storybook.wise.design/?path=/docs/layouts-divider--docs|Storybook Wise Design}\n */\nconst Divider: FunctionComponent<DividerProps> = ({\n className,\n isContent = false,\n testId,\n variant = 'section',\n ...props\n}) => {\n const variantClass = variant && variant !== 'section' ? `wds-Divider--${variant}` : '';\n\n const commonProps = {\n className: clsx('wds-Divider', variantClass, className),\n 'data-testid': testId,\n };\n\n const divProps = {\n ...commonProps,\n role: 'presentation',\n };\n\n return isContent ? <hr {...commonProps} {...props} /> : <div {...divProps} {...props} />;\n};\n\nexport default Divider;\n"],"names":["Divider","className","isContent","testId","variant","props","variantClass","commonProps","clsx","divProps","role","_jsx"],"mappings":";;;;;;AAiCMA,MAAAA,OAAO,GAAoCA,CAAC;EAChDC,SAAS;AACTC,EAAAA,SAAS,GAAG,KAAK;EACjBC,MAAM;AACNC,EAAAA,OAAO,GAAG,SAAS;EACnB,GAAGC,KAAAA;AAAK,CACT,KAAI;AACH,EAAA,MAAMC,YAAY,GAAGF,OAAO,IAAIA,OAAO,KAAK,SAAS,GAAG,CAAgBA,aAAAA,EAAAA,OAAO,CAAE,CAAA,GAAG,EAAE,CAAA;AAEtF,EAAA,MAAMG,WAAW,GAAG;IAClBN,SAAS,EAAEO,SAAI,CAAC,aAAa,EAAEF,YAAY,EAAEL,SAAS,CAAC;AACvD,IAAA,aAAa,EAAEE,MAAAA;GAChB,CAAA;AAED,EAAA,MAAMM,QAAQ,GAAG;AACf,IAAA,GAAGF,WAAW;AACdG,IAAAA,IAAI,EAAE,cAAA;GACP,CAAA;EAED,OAAOR,SAAS,gBAAGS,cAAA,CAAA,IAAA,EAAA;AAAA,IAAA,GAAQJ,WAAW;IAAA,GAAMF,KAAAA;GAAS,CAAA,gBAAGM,cAAA,CAAA,KAAA,EAAA;AAAA,IAAA,GAASF,QAAQ;IAAA,GAAMJ,KAAAA;AAAK,IAAI,CAAA;AAC1F;;;;"}
|
|
@@ -3,8 +3,8 @@ import 'react';
|
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
const Divider = ({
|
|
6
|
-
as = 'div',
|
|
7
6
|
className,
|
|
7
|
+
isContent = false,
|
|
8
8
|
testId,
|
|
9
9
|
variant = 'section',
|
|
10
10
|
...props
|
|
@@ -18,7 +18,7 @@ const Divider = ({
|
|
|
18
18
|
...commonProps,
|
|
19
19
|
role: 'presentation'
|
|
20
20
|
};
|
|
21
|
-
return
|
|
21
|
+
return isContent ? /*#__PURE__*/jsx("hr", {
|
|
22
22
|
...commonProps,
|
|
23
23
|
...props
|
|
24
24
|
}) : /*#__PURE__*/jsx("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Divider.mjs","sources":["../../src/divider/Divider.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport React, { FunctionComponent } from 'react';\n\nexport interface DividerProps {\n
|
|
1
|
+
{"version":3,"file":"Divider.mjs","sources":["../../src/divider/Divider.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport React, { FunctionComponent } from 'react';\n\nexport interface DividerProps {\n /**\n * If `true`, renders the Divider as a semantic `<hr>`, providing clear separation to assistive technologies.\n * Otherwise, a non-semantic `<div role=\"presentation\">` is used for purely visual separation.\n * @default false\n */\n isContent?: boolean;\n\n /**\n * Appends additional class names to style the `Divider`.\n */\n className?: string;\n\n /**\n * Provides a `data-testid` attribute for testing.\n */\n testId?: string;\n\n /**\n * Alters the visual style of the divider, accommodating different types\n * of separated content. Accepts `'section'`, `'subsection'`, or `'content'`.\n * @default 'section'\n */\n variant?: 'section' | 'subsection' | 'content';\n}\n\n/**\n * @see {@link Divider} for further information.\n * @see {@link https://storybook.wise.design/?path=/docs/layouts-divider--docs|Storybook Wise Design}\n */\nconst Divider: FunctionComponent<DividerProps> = ({\n className,\n isContent = false,\n testId,\n variant = 'section',\n ...props\n}) => {\n const variantClass = variant && variant !== 'section' ? `wds-Divider--${variant}` : '';\n\n const commonProps = {\n className: clsx('wds-Divider', variantClass, className),\n 'data-testid': testId,\n };\n\n const divProps = {\n ...commonProps,\n role: 'presentation',\n };\n\n return isContent ? <hr {...commonProps} {...props} /> : <div {...divProps} {...props} />;\n};\n\nexport default Divider;\n"],"names":["Divider","className","isContent","testId","variant","props","variantClass","commonProps","clsx","divProps","role","_jsx"],"mappings":";;;;AAiCMA,MAAAA,OAAO,GAAoCA,CAAC;EAChDC,SAAS;AACTC,EAAAA,SAAS,GAAG,KAAK;EACjBC,MAAM;AACNC,EAAAA,OAAO,GAAG,SAAS;EACnB,GAAGC,KAAAA;AAAK,CACT,KAAI;AACH,EAAA,MAAMC,YAAY,GAAGF,OAAO,IAAIA,OAAO,KAAK,SAAS,GAAG,CAAgBA,aAAAA,EAAAA,OAAO,CAAE,CAAA,GAAG,EAAE,CAAA;AAEtF,EAAA,MAAMG,WAAW,GAAG;IAClBN,SAAS,EAAEO,IAAI,CAAC,aAAa,EAAEF,YAAY,EAAEL,SAAS,CAAC;AACvD,IAAA,aAAa,EAAEE,MAAAA;GAChB,CAAA;AAED,EAAA,MAAMM,QAAQ,GAAG;AACf,IAAA,GAAGF,WAAW;AACdG,IAAAA,IAAI,EAAE,cAAA;GACP,CAAA;EAED,OAAOR,SAAS,gBAAGS,GAAA,CAAA,IAAA,EAAA;AAAA,IAAA,GAAQJ,WAAW;IAAA,GAAMF,KAAAA;GAAS,CAAA,gBAAGM,GAAA,CAAA,KAAA,EAAA;AAAA,IAAA,GAASF,QAAQ;IAAA,GAAMJ,KAAAA;AAAK,IAAI,CAAA;AAC1F;;;;"}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { FunctionComponent } from 'react';
|
|
2
2
|
export interface DividerProps {
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/**
|
|
4
|
+
* If `true`, renders the Divider as a semantic `<hr>`, providing clear separation to assistive technologies.
|
|
5
|
+
* Otherwise, a non-semantic `<div role="presentation">` is used for purely visual separation.
|
|
6
|
+
* @default false
|
|
7
|
+
*/
|
|
8
|
+
isContent?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Appends additional class names to style the `Divider`.
|
|
11
|
+
*/
|
|
6
12
|
className?: string;
|
|
7
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Provides a `data-testid` attribute for testing.
|
|
15
|
+
*/
|
|
8
16
|
testId?: string;
|
|
9
|
-
/**
|
|
10
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Alters the visual style of the divider, accommodating different types
|
|
19
|
+
* of separated content. Accepts `'section'`, `'subsection'`, or `'content'`.
|
|
20
|
+
* @default 'section'
|
|
21
|
+
*/
|
|
22
|
+
variant?: 'section' | 'subsection' | 'content';
|
|
11
23
|
}
|
|
12
24
|
/**
|
|
13
|
-
* Divider component
|
|
14
|
-
*
|
|
15
|
-
* The Divider component is used to visually separate different sections of content.
|
|
16
|
-
* It can be rendered as a horizontal line and supports various styles such as
|
|
17
|
-
* section, subsection, and content. Additionally, the Divider can include custom styles.
|
|
18
|
-
*
|
|
19
|
-
* @component
|
|
20
|
-
* @param {boolean} [isContent=false] - Option prop to specify if the Divider is for content or presentation.
|
|
21
|
-
* @param {string} [className] - Optional prop to specify classNames onto the Divider.
|
|
22
|
-
* @param {string} [testId] - Optional prop to specify the ID used for testing.
|
|
23
|
-
* @param {'section' | 'subsection' | 'content'} [variant='section'] - Optional prop to specify the variant of the Divider.
|
|
24
|
-
*
|
|
25
25
|
* @see {@link Divider} for further information.
|
|
26
26
|
* @see {@link https://storybook.wise.design/?path=/docs/layouts-divider--docs|Storybook Wise Design}
|
|
27
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Divider.d.ts","sourceRoot":"","sources":["../../../src/divider/Divider.tsx"],"names":[],"mappings":"AACA,OAAc,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B
|
|
1
|
+
{"version":3,"file":"Divider.d.ts","sourceRoot":"","sources":["../../../src/divider/Divider.tsx"],"names":[],"mappings":"AACA,OAAc,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;OAIG;IACH,OAAO,CAAC,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,CAAC;CAChD;AAED;;;GAGG;AACH,QAAA,MAAM,OAAO,EAAE,iBAAiB,CAAC,YAAY,CAoB5C,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Meta, Canvas, Source } from '@storybook/blocks';
|
|
2
|
+
import { NavigationOption } from '..';
|
|
3
|
+
import { Bulb } from '@transferwise/icons';
|
|
4
|
+
|
|
5
|
+
<Meta title="Layouts/Divider/Accessibility" />
|
|
6
|
+
|
|
7
|
+
# Accessibility
|
|
8
|
+
|
|
9
|
+
A Divider is used to separate sections of content. While it doesn't directly announce anything to screen readers, there are a few considerations:
|
|
10
|
+
|
|
11
|
+
<NavigationOption
|
|
12
|
+
media={<Bulb size={24} />}
|
|
13
|
+
title="Design guidance"
|
|
14
|
+
content="Before you start, please review the documentation on how separators should be used, announced or hidden from assistive tech."
|
|
15
|
+
href="https://wise.design/components/divider"
|
|
16
|
+
/>
|
|
17
|
+
|
|
18
|
+
<br />
|
|
19
|
+
<br />
|
|
20
|
+
|
|
21
|
+
## Using `<hr />` vs `<div />`
|
|
22
|
+
|
|
23
|
+
By default, our Divider is rendered as `<div role="presentation" />`. However, you can optionally set `isContent` to true, which many screen readers interpret as a “separator.”
|
|
24
|
+
|
|
25
|
+
<Source dark code={`
|
|
26
|
+
// By default: non-semantic divider
|
|
27
|
+
<Divider isContent={false} />
|
|
28
|
+
|
|
29
|
+
// Alternatively, to provide a semantic HR:
|
|
30
|
+
|
|
31
|
+
<Divider isContent={true} />
|
|
32
|
+
`}/>
|
|
33
|
+
|
|
34
|
+
Compared to a `<div>`, `<hr>` tells assistive technologies that a thematic break or separation has occurred. However, sometimes you may not want an audible separation. In that case, using `<div>` (which omits semantic meaning) might be preferable.
|
|
35
|
+
|
|
36
|
+
<br />
|
|
37
|
+
|
|
38
|
+
## Variants
|
|
39
|
+
|
|
40
|
+
The Divider supports variants like “section”, “subsection”, or “content” to visually change the separation style:
|
|
41
|
+
|
|
42
|
+
<Source
|
|
43
|
+
dark
|
|
44
|
+
code={`
|
|
45
|
+
// A few variant examples
|
|
46
|
+
<>
|
|
47
|
+
<Divider variant="section" />
|
|
48
|
+
<Divider variant="subsection" />
|
|
49
|
+
<Divider variant="content" />
|
|
50
|
+
</>
|
|
51
|
+
`}
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
Screen readers generally ignore these visual styling changes unless you explicitly provide more context (e.g., additional text or heading tags).
|
|
55
|
+
|
|
56
|
+
<br />
|
|
57
|
+
|
|
58
|
+
**Additional resources:**
|
|
59
|
+
|
|
60
|
+
1. [WAI-ARIA Authoring Practices: Separator Role](https://www.w3.org/TR/wai-aria-practices-1.2/#separator)
|
|
61
|
+
2. [MDN Web Docs: <hr />](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/hr)
|
|
@@ -11,7 +11,6 @@ describe('Divider', () => {
|
|
|
11
11
|
|
|
12
12
|
beforeEach(() => {
|
|
13
13
|
const { rerender } = render(<Divider {...defaultProps} />);
|
|
14
|
-
|
|
15
14
|
rerenderDivider = (props?: DividerProps) => {
|
|
16
15
|
rerender(<Divider {...defaultProps} {...props} />);
|
|
17
16
|
};
|
|
@@ -21,64 +20,46 @@ describe('Divider', () => {
|
|
|
21
20
|
return render(<Divider {...props} />);
|
|
22
21
|
};
|
|
23
22
|
|
|
24
|
-
it('
|
|
23
|
+
it('should render the Divider component', () => {
|
|
25
24
|
expect(screen.getByTestId('test-divider')).toBeInTheDocument();
|
|
26
25
|
expect(screen.getByTestId('test-divider')).toHaveClass('wds-Divider');
|
|
27
26
|
});
|
|
28
27
|
|
|
29
|
-
it('
|
|
30
|
-
const props: DividerProps = {
|
|
31
|
-
as: 'hr',
|
|
32
|
-
};
|
|
33
|
-
|
|
28
|
+
it('should render as a semantic <hr> when `isContent` is true', () => {
|
|
29
|
+
const props: DividerProps = { isContent: true };
|
|
34
30
|
rerenderDivider(props);
|
|
35
31
|
|
|
36
32
|
expect(screen.getByTestId('test-divider')).not.toHaveAttribute('role', 'presentation');
|
|
37
33
|
});
|
|
38
34
|
|
|
39
|
-
it('
|
|
40
|
-
const props: DividerProps = {
|
|
41
|
-
as: 'div',
|
|
42
|
-
};
|
|
43
|
-
|
|
35
|
+
it('should render as a non-semantic <div> when `isContent` is false', () => {
|
|
36
|
+
const props: DividerProps = { isContent: false };
|
|
44
37
|
rerenderDivider(props);
|
|
45
38
|
|
|
46
39
|
expect(screen.getByTestId('test-divider')).toHaveAttribute('role', 'presentation');
|
|
47
40
|
});
|
|
48
41
|
|
|
49
|
-
it('
|
|
50
|
-
const props: DividerProps = {
|
|
51
|
-
className: 'custom-class',
|
|
52
|
-
};
|
|
53
|
-
|
|
42
|
+
it('should apply custom class names when provided', () => {
|
|
43
|
+
const props: DividerProps = { className: 'custom-class' };
|
|
54
44
|
expect(screen.getByTestId('test-divider')).not.toHaveClass('custom-class');
|
|
55
45
|
|
|
56
46
|
rerenderDivider(props);
|
|
57
|
-
|
|
58
47
|
expect(screen.getByTestId('test-divider')).toHaveClass('custom-class');
|
|
59
48
|
});
|
|
60
49
|
|
|
61
|
-
it('
|
|
62
|
-
const props: DividerProps = {
|
|
63
|
-
variant: 'content',
|
|
64
|
-
};
|
|
65
|
-
|
|
50
|
+
it('should apply the "content" variant styling', () => {
|
|
51
|
+
const props: DividerProps = { variant: 'content' };
|
|
66
52
|
expect(screen.getByTestId('test-divider')).not.toHaveClass('wds-Divider--content');
|
|
67
53
|
|
|
68
54
|
rerenderDivider(props);
|
|
69
|
-
|
|
70
55
|
expect(screen.getByTestId('test-divider')).toHaveClass('wds-Divider', 'wds-Divider--content');
|
|
71
56
|
});
|
|
72
57
|
|
|
73
|
-
it('
|
|
74
|
-
const props: DividerProps = {
|
|
75
|
-
variant: 'subsection',
|
|
76
|
-
};
|
|
77
|
-
|
|
58
|
+
it('should apply the "subsection" variant styling', () => {
|
|
59
|
+
const props: DividerProps = { variant: 'subsection' };
|
|
78
60
|
expect(screen.getByTestId('test-divider')).not.toHaveClass('wds-Divider--subsection');
|
|
79
61
|
|
|
80
62
|
rerenderDivider(props);
|
|
81
|
-
|
|
82
63
|
expect(screen.getByTestId('test-divider')).toHaveClass(
|
|
83
64
|
'wds-Divider',
|
|
84
65
|
'wds-Divider--subsection',
|
|
@@ -1,29 +1,132 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
|
|
3
2
|
import Divider from './Divider';
|
|
4
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Wraps stories with a container (e.g., centered or padded).
|
|
6
|
+
* Adjust styles to your needs.
|
|
7
|
+
*/
|
|
8
|
+
const withContainer = (Story: any) => (
|
|
9
|
+
<div style={{ padding: '1rem' }}>
|
|
10
|
+
<Story />
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Not all stories need access to all controls as it causes unnecessary UI noise.
|
|
16
|
+
*/
|
|
17
|
+
const hideControls = (args: string[]) => {
|
|
18
|
+
const hidden = ['variant', 'as', 'className', 'testId', ...args];
|
|
19
|
+
|
|
20
|
+
return Object.fromEntries(hidden.map((item) => [item, { table: { disable: true } }]));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The stories below document the `<Divider />` component, which can be rendered as either a semantic `<hr>` or a non-semantic `<div>`.
|
|
25
|
+
* Variants allow customization for different visual separation needs.
|
|
26
|
+
*
|
|
27
|
+
* For more details, please refer to the [design documentation](https://wise.design/components/divider).
|
|
28
|
+
*
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
5
31
|
const meta: Meta<typeof Divider> = {
|
|
6
32
|
component: Divider,
|
|
7
33
|
title: 'Layouts/Divider',
|
|
8
34
|
tags: ['autodocs'],
|
|
35
|
+
decorators: [withContainer],
|
|
9
36
|
parameters: {
|
|
10
37
|
actions: { argTypesRegex: null },
|
|
11
38
|
},
|
|
39
|
+
argTypes: {
|
|
40
|
+
variant: {
|
|
41
|
+
control: 'select',
|
|
42
|
+
options: ['section', 'subsection', 'content'],
|
|
43
|
+
description: 'Choose the Divider variant.',
|
|
44
|
+
table: {
|
|
45
|
+
category: 'Appearance',
|
|
46
|
+
type: { summary: 'string' },
|
|
47
|
+
defaultValue: { summary: 'section' },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
isContent: {
|
|
51
|
+
control: 'boolean',
|
|
52
|
+
description: 'Render as a semantic <hr> (true) or non-semantic <div> (false).',
|
|
53
|
+
table: {
|
|
54
|
+
category: 'Appearance',
|
|
55
|
+
type: { summary: 'boolean' },
|
|
56
|
+
defaultValue: { summary: 'false' },
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
className: {
|
|
60
|
+
description: 'Add custom class names to the Divider.',
|
|
61
|
+
table: {
|
|
62
|
+
category: 'Appearance',
|
|
63
|
+
type: { summary: 'string' },
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
testId: {
|
|
67
|
+
description: 'Add a data-testid attribute for testing.',
|
|
68
|
+
table: {
|
|
69
|
+
category: 'Testing',
|
|
70
|
+
type: { summary: 'string' },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
args: {
|
|
75
|
+
isContent: false,
|
|
76
|
+
className: '',
|
|
77
|
+
testId: '',
|
|
78
|
+
variant: 'section',
|
|
79
|
+
},
|
|
12
80
|
};
|
|
13
|
-
|
|
14
81
|
export default meta;
|
|
82
|
+
|
|
15
83
|
type Story = StoryObj<typeof Divider>;
|
|
16
84
|
|
|
17
|
-
export const
|
|
85
|
+
export const Playground: Story = {
|
|
86
|
+
args: {
|
|
87
|
+
variant: 'section',
|
|
88
|
+
},
|
|
89
|
+
tags: ['!autodocs'],
|
|
90
|
+
};
|
|
18
91
|
|
|
19
|
-
|
|
92
|
+
/**
|
|
93
|
+
* There are three different types of divider – `section`, `subsection`, and `content` –
|
|
94
|
+
* each designed to visually separate or group content. <br />
|
|
95
|
+
* [Design documentation](https://wise.design/components/divider)
|
|
96
|
+
*/
|
|
97
|
+
export const Variant: Story = {
|
|
98
|
+
argTypes: {
|
|
99
|
+
...hideControls(['testId', 'className', 'isContent']),
|
|
100
|
+
},
|
|
20
101
|
args: {
|
|
21
|
-
variant: '
|
|
102
|
+
variant: 'section',
|
|
22
103
|
},
|
|
23
104
|
};
|
|
24
105
|
|
|
25
|
-
|
|
106
|
+
/**
|
|
107
|
+
* The `isContent` prop determines whether the divider is rendered as a semantic `<hr>` or a non-semantic `<div>`.
|
|
108
|
+
*/
|
|
109
|
+
export const ContentDivider: Story = {
|
|
110
|
+
argTypes: {
|
|
111
|
+
...hideControls(['variant', 'testId', 'className']),
|
|
112
|
+
},
|
|
26
113
|
args: {
|
|
27
|
-
|
|
114
|
+
isContent: true,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const AllVariants: Story = {
|
|
119
|
+
render: function Render() {
|
|
120
|
+
return (
|
|
121
|
+
<>
|
|
122
|
+
<Divider variant="section" />
|
|
123
|
+
<Divider variant="subsection" />
|
|
124
|
+
<Divider variant="content" />
|
|
125
|
+
</>
|
|
126
|
+
);
|
|
127
|
+
},
|
|
128
|
+
argTypes: {
|
|
129
|
+
...hideControls(['variant', 'testId', 'className', 'isContent']),
|
|
28
130
|
},
|
|
131
|
+
tags: ['!autodocs'],
|
|
29
132
|
};
|
package/src/divider/Divider.tsx
CHANGED
|
@@ -2,38 +2,38 @@ import { clsx } from 'clsx';
|
|
|
2
2
|
import React, { FunctionComponent } from 'react';
|
|
3
3
|
|
|
4
4
|
export interface DividerProps {
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* If `true`, renders the Divider as a semantic `<hr>`, providing clear separation to assistive technologies.
|
|
7
|
+
* Otherwise, a non-semantic `<div role="presentation">` is used for purely visual separation.
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
isContent?: boolean;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Appends additional class names to style the `Divider`.
|
|
14
|
+
*/
|
|
9
15
|
className?: string;
|
|
10
16
|
|
|
11
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Provides a `data-testid` attribute for testing.
|
|
19
|
+
*/
|
|
12
20
|
testId?: string;
|
|
13
21
|
|
|
14
|
-
/**
|
|
15
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Alters the visual style of the divider, accommodating different types
|
|
24
|
+
* of separated content. Accepts `'section'`, `'subsection'`, or `'content'`.
|
|
25
|
+
* @default 'section'
|
|
26
|
+
*/
|
|
27
|
+
variant?: 'section' | 'subsection' | 'content';
|
|
16
28
|
}
|
|
17
29
|
|
|
18
30
|
/**
|
|
19
|
-
* Divider component
|
|
20
|
-
*
|
|
21
|
-
* The Divider component is used to visually separate different sections of content.
|
|
22
|
-
* It can be rendered as a horizontal line and supports various styles such as
|
|
23
|
-
* section, subsection, and content. Additionally, the Divider can include custom styles.
|
|
24
|
-
*
|
|
25
|
-
* @component
|
|
26
|
-
* @param {boolean} [isContent=false] - Option prop to specify if the Divider is for content or presentation.
|
|
27
|
-
* @param {string} [className] - Optional prop to specify classNames onto the Divider.
|
|
28
|
-
* @param {string} [testId] - Optional prop to specify the ID used for testing.
|
|
29
|
-
* @param {'section' | 'subsection' | 'content'} [variant='section'] - Optional prop to specify the variant of the Divider.
|
|
30
|
-
*
|
|
31
31
|
* @see {@link Divider} for further information.
|
|
32
32
|
* @see {@link https://storybook.wise.design/?path=/docs/layouts-divider--docs|Storybook Wise Design}
|
|
33
33
|
*/
|
|
34
34
|
const Divider: FunctionComponent<DividerProps> = ({
|
|
35
|
-
as = 'div',
|
|
36
35
|
className,
|
|
36
|
+
isContent = false,
|
|
37
37
|
testId,
|
|
38
38
|
variant = 'section',
|
|
39
39
|
...props
|
|
@@ -50,7 +50,7 @@ const Divider: FunctionComponent<DividerProps> = ({
|
|
|
50
50
|
role: 'presentation',
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
return
|
|
53
|
+
return isContent ? <hr {...commonProps} {...props} /> : <div {...divProps} {...props} />;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export default Divider;
|