|
10 | 10 | * governing permissions and limitations under the License.
|
11 | 11 | */
|
12 | 12 |
|
| 13 | +import {Story as _Story, Meta} from '@storybook/react'; |
13 | 14 | import {Accordion, Item} from '../src';
|
14 | 15 | import React from 'react';
|
15 |
| -import {storiesOf} from '@storybook/react'; |
16 |
| - |
17 |
| -storiesOf('Accordion', module) |
18 |
| - .add( |
19 |
| - 'default', |
20 |
| - () => render({}) |
21 |
| - ) |
22 |
| - .add( |
23 |
| - 'disabledKeys: files, shared', |
24 |
| - () => render({disabledKeys: ['files', 'shared']}) |
25 |
| - ) |
26 |
| - .add('defaultExpandedKeys: files', () => render({ |
27 |
| - defaultExpandedKeys: ['files'] |
28 |
| - })) |
29 |
| - .add('disabledKeys: files, shared, defaultExpandedKeys: files', () => render({ |
30 |
| - defaultExpandedKeys: ['files'], |
31 |
| - disabledKeys: ['files', 'shared'] |
32 |
| - })); |
33 |
| - |
34 |
| -function render(props = {}) { |
35 |
| - return ( |
36 |
| - <Accordion {...props} > |
37 |
| - <Item key="files" title="Your files"> |
38 |
| - files |
39 |
| - </Item> |
40 |
| - <Item key="shared" title="Shared with you"> |
41 |
| - shared |
42 |
| - </Item> |
43 |
| - <Item key="last" title="Last item"> |
44 |
| - last |
45 |
| - </Item> |
46 |
| - </Accordion> |
47 |
| - ); |
| 16 | +import {SpectrumAccordionProps} from '@react-types/accordion'; |
| 17 | + |
| 18 | +type ItemType = { |
| 19 | + key: React.Key, |
| 20 | + title: string |
| 21 | +}; |
| 22 | + |
| 23 | +/** |
| 24 | + * Helper type so `bind` returns the actual Story type. |
| 25 | + */ |
| 26 | +interface Story<T> extends _Story<T> { |
| 27 | + bind: (this: ThisParameterType<typeof Function.bind>, thisArg: Parameters<typeof Function.bind>[0], ...argArray: Parameters<typeof Function.bind>[1][]) => _Story<T> |
48 | 28 | }
|
| 29 | + |
| 30 | +export default { |
| 31 | + title: 'Accordion', |
| 32 | + component: Accordion |
| 33 | +} as Meta<SpectrumAccordionProps<ItemType>>; |
| 34 | + |
| 35 | +const AccordionRenderPropsTemplate: Story<SpectrumAccordionProps<ItemType>> = (args) => ( |
| 36 | + <Accordion {...args}> |
| 37 | + {item => <Item key={item.key} title={item.title}>{item.key}</Item>} |
| 38 | + </Accordion> |
| 39 | +); |
| 40 | + |
| 41 | +export const Default = AccordionRenderPropsTemplate.bind({}); |
| 42 | +Default.storyName = 'default'; |
| 43 | +Default.args = { |
| 44 | + items: [ |
| 45 | + {key: 'files', title: 'Your files'}, |
| 46 | + {key: 'shared', title: 'Shared with you'}, |
| 47 | + {key: 'last', title: 'Last item'} |
| 48 | + ] |
| 49 | +}; |
| 50 | + |
| 51 | +const AccordionTemplate: Story<SpectrumAccordionProps<ItemType>> = (args) => ( |
| 52 | + <Accordion {...args} > |
| 53 | + <Item key="files" title="Your files"> |
| 54 | + files |
| 55 | + </Item> |
| 56 | + <Item key="shared" title="Shared with you"> |
| 57 | + shared |
| 58 | + </Item> |
| 59 | + <Item key="last" title="Last item"> |
| 60 | + last |
| 61 | + </Item> |
| 62 | + </Accordion> |
| 63 | +); |
| 64 | + |
| 65 | +export const DefaultExpandedKeys = AccordionTemplate.bind({}); |
| 66 | +DefaultExpandedKeys.storyName = 'defaultExpandedKeys: files'; |
| 67 | +DefaultExpandedKeys.args = {defaultExpandedKeys: ['files']}; |
| 68 | + |
| 69 | +export const DisabledKeys = AccordionTemplate.bind({}); |
| 70 | +DisabledKeys.storyName = 'disabledKeys: files, shared'; |
| 71 | +DisabledKeys.args = {disabledKeys: ['files', 'shared']}; |
| 72 | + |
| 73 | +export const DisabledDefaultExpandedKeys = AccordionTemplate.bind({}); |
| 74 | +DisabledDefaultExpandedKeys.storyName = 'defaultExpandedKeys: files, disabledKeys: files, shared'; |
| 75 | +DisabledDefaultExpandedKeys.args = { |
| 76 | + defaultExpandedKeys: ['files'], |
| 77 | + disabledKeys: ['files', 'shared'] |
| 78 | +}; |
0 commit comments