|
10 | 10 | * governing permissions and limitations under the License.
|
11 | 11 | */
|
12 | 12 |
|
13 |
| -import {action} from '@storybook/addon-actions'; |
14 | 13 | import {Button, Content, Flex, Footer, Heading, Link, Text} from '@adobe/react-spectrum';
|
| 14 | +import {ComponentMeta, ComponentStoryObj} from '@storybook/react'; |
15 | 15 | import {ContextualHelp} from '../src';
|
16 | 16 | import React from 'react';
|
17 |
| -import {storiesOf} from '@storybook/react'; |
18 | 17 |
|
19 |
| -storiesOf('ContextualHelp', module) |
20 |
| -.add( |
21 |
| - 'default', |
22 |
| - () => render({heading: 'Help title', description: helpText()}) |
23 |
| -) |
24 |
| -.add( |
25 |
| - 'type: info', |
26 |
| - () => render({heading: 'Help title', description: helpText(), variant: 'info'}) |
27 |
| -) |
28 |
| -.add( |
29 |
| - 'with link', |
30 |
| - () => render({heading: 'Help title', description: helpText(), link: <Link>Learn more</Link>}) |
31 |
| -) |
32 |
| -.add( |
33 |
| - 'with button', |
34 |
| - () => (<Flex alignItems="center"> |
35 |
| - <Button variant="primary" isDisabled>Create</Button> |
36 |
| - <ContextualHelp marginStart="size-100"> |
37 |
| - <Heading>Help title</Heading> |
38 |
| - <Content>{helpText()}</Content> |
39 |
| - </ContextualHelp> |
40 |
| - </Flex>) |
41 |
| -) |
42 |
| -.add( |
43 |
| - 'trigger events', |
44 |
| - () => render({heading: 'Help title', description: helpText(), onOpenChange: action('open change')}) |
45 |
| -) |
46 |
| -.add( |
47 |
| - 'placement: bottom', |
48 |
| - () => render({heading: 'Help title', description: helpText(), placement: 'bottom'}) |
49 |
| -) |
50 |
| -.add( |
51 |
| - 'placement: bottom start', |
52 |
| - () => render({heading: 'Help title', description: helpText(), placement: 'bottom start'}) |
53 |
| -); |
| 18 | +export default { |
| 19 | + title: 'ContextualHelp', |
| 20 | + component: ContextualHelp, |
| 21 | + argTypes: { |
| 22 | + onOpenChange: { |
| 23 | + action: 'openChange', |
| 24 | + table: {disable: true} |
| 25 | + }, |
| 26 | + placement: { |
| 27 | + control: 'select', |
| 28 | + defaultValue: 'bottom', |
| 29 | + options: [ |
| 30 | + 'bottom', 'bottom left', 'bottom right', 'bottom start', 'bottom end', |
| 31 | + 'top', 'top left', 'top right', 'top start', 'top end', |
| 32 | + 'left', 'left top', 'left bottom', |
| 33 | + 'start', 'start top', 'start bottom', |
| 34 | + 'right', 'right top', 'right bottom', |
| 35 | + 'end', 'end top', 'end bottom' |
| 36 | + ] |
| 37 | + }, |
| 38 | + variant: { |
| 39 | + control: 'select', |
| 40 | + defaultValue: 'help', |
| 41 | + options: ['help', 'info'] |
| 42 | + }, |
| 43 | + offset: { |
| 44 | + control: 'number', |
| 45 | + defaultValue: 0, |
| 46 | + min: -500, |
| 47 | + max: 500 |
| 48 | + }, |
| 49 | + crossOffset: { |
| 50 | + control: 'number', |
| 51 | + defaultValue: 0, |
| 52 | + min: -500, |
| 53 | + max: 500 |
| 54 | + }, |
| 55 | + containerPadding: { |
| 56 | + control: 'number', |
| 57 | + defaultValue: 0, |
| 58 | + min: -500, |
| 59 | + max: 500 |
| 60 | + }, |
| 61 | + shouldFlip: { |
| 62 | + control: 'boolean', |
| 63 | + defaultValue: true |
| 64 | + }, |
| 65 | + children: { |
| 66 | + table: {disable: true} |
| 67 | + } |
| 68 | + } |
| 69 | +} as ComponentMeta<typeof ContextualHelp>; |
| 70 | + |
| 71 | +export type ContextualHelpStory = ComponentStoryObj<typeof ContextualHelp>; |
54 | 72 |
|
55 | 73 | const helpText = () => <Text>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin sit amet tristique risus. In sit amet suscipit lorem.</Text>;
|
56 | 74 |
|
57 |
| -function render(props: any = {}) { |
58 |
| - let {heading, description, link, ...otherProps} = props; |
| 75 | +export const Default: ContextualHelpStory = { |
| 76 | + args: { |
| 77 | + children: ( |
| 78 | + <> |
| 79 | + <Heading>Help title</Heading> |
| 80 | + <Content>{helpText()}</Content> |
| 81 | + </> |
| 82 | + ) |
| 83 | + } |
| 84 | +}; |
| 85 | + |
| 86 | +export const WithLink: ContextualHelpStory = { |
| 87 | + args: { |
| 88 | + children: ( |
| 89 | + <> |
| 90 | + <Heading>Help title</Heading> |
| 91 | + <Content>{helpText()}</Content> |
| 92 | + <Footer><Link>Learn more</Link></Footer> |
| 93 | + </> |
| 94 | + ) |
| 95 | + }, |
| 96 | + name: 'with link' |
| 97 | +}; |
| 98 | + |
| 99 | +export const WithButton: ContextualHelpStory = { |
| 100 | + args: { |
| 101 | + marginStart: 'size-100' |
| 102 | + }, |
| 103 | + render: (args) => ( |
| 104 | + <Flex alignItems="center"> |
| 105 | + <Button variant="primary" isDisabled>Create</Button> |
| 106 | + <ContextualHelp {...args} UNSAFE_className="foo"> |
| 107 | + <Heading>Help title</Heading> |
| 108 | + <Content>{helpText()}</Content> |
| 109 | + </ContextualHelp> |
| 110 | + </Flex> |
| 111 | + ), |
| 112 | + name: 'with button', |
| 113 | + parameters: {description: {data: 'Custom classname foo is on the contextual help button.'}} |
| 114 | +}; |
59 | 115 |
|
60 |
| - return ( |
61 |
| - <ContextualHelp {...otherProps}> |
62 |
| - {heading && <Heading>{heading}</Heading>} |
63 |
| - {description && <Content>{description}</Content>} |
64 |
| - {link && <Footer>{link}</Footer>} |
65 |
| - </ContextualHelp> |
66 |
| - ); |
67 |
| -} |
| 116 | +export const AriaLabelledyBy: ContextualHelpStory = { |
| 117 | + render: (args) => ( |
| 118 | + <Flex alignItems="center"> |
| 119 | + <div id="foo">I label the contextual help button</div> |
| 120 | + <ContextualHelp {...args} aria-labelledby="foo"> |
| 121 | + <Heading>Help title</Heading> |
| 122 | + <Content>{helpText()}</Content> |
| 123 | + </ContextualHelp> |
| 124 | + </Flex> |
| 125 | + ), |
| 126 | + name: 'aria-labelledyby' |
| 127 | +}; |
0 commit comments