Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | 6x 1x 2x 1x 1x 1x 1x 1x 1x 1x 20x 1x 1x 1x 1x 1x 1x 1x 20x | import { map, times, partial } from 'lodash'; import React, { useState } from 'react'; import { Meta, Story } from '@storybook/react'; import VerticalListMenu, { IVerticalListMenuProps } from './VerticalListMenu'; //π Provide Storybook with the component name, 'section', any subcomponents and a description export default { title: 'Navigation/VerticalListMenu', component: VerticalListMenu, parameters: { docs: { description: { component: VerticalListMenu.peek.description, }, }, }, args: VerticalListMenu.defaultProps, } as Meta; //π Add a key prop to each child element of the array function addKeys(children: any) { return map(children, (child, index) => ({ ...child, key: index })); } //π Create a βtemplateβ of how args map to rendering const Template: Story<IVerticalListMenuProps> = (args) => { return ( <section> <VerticalListMenu {...(args as any)} style={{ width: 250 }} /> </section> ); }; //π Each story then reuses that template /** Basic VerticalListMenu */ export const Basic: Story<IVerticalListMenuProps> = Template.bind({}); Basic.args = { children: addKeys([ <VerticalListMenu.Item>Level one</VerticalListMenu.Item>, <VerticalListMenu.Item>Level one</VerticalListMenu.Item>, <VerticalListMenu.Item>Level one</VerticalListMenu.Item>, ]), }; /** Nested With Expander */ export const NestedWithExpander: Story<IVerticalListMenuProps> = (args) => { const [currentList, setCurrentList] = useState('one'); const [selectedIndices, setSelectedIndices] = useState([0]); const handleSelect = (currentList: string, index: number) => { setCurrentList(currentList); setSelectedIndices([index]); }; return ( <VerticalListMenu {...(args as any)} style={{ width: 250 }} onSelect={partial(handleSelect, 'one')} selectedIndices={currentList === 'one' ? selectedIndices : []} > <VerticalListMenu.Item>Level one</VerticalListMenu.Item> <VerticalListMenu.Item hasExpander={true}> Level one with VerticalListMenu <VerticalListMenu onSelect={partial(handleSelect, 'two')} selectedIndices={currentList === 'two' ? selectedIndices : []} > <VerticalListMenu.Item>Level two</VerticalListMenu.Item> <VerticalListMenu.Item hasExpander={true}> Level two with VerticalListMenu and lots of text. Lorem quos natus mollitia nihil quasi! Necessitatibus corporis aliquam quam laborum nesciunt quaerat. Nostrum distinctio officiis adipisci nulla unde repellat. Soluta eaque ex obcaecati molestiae provident aspernatur sit! Expedita et. <VerticalListMenu onSelect={partial(handleSelect, 'three')} selectedIndices={currentList === 'three' ? selectedIndices : []} > {times(20, (n) => { return ( <VerticalListMenu.Item key={n}> Level three </VerticalListMenu.Item> ); })} </VerticalListMenu> </VerticalListMenu.Item> <VerticalListMenu.Item>Level two</VerticalListMenu.Item> </VerticalListMenu> </VerticalListMenu.Item> <VerticalListMenu.Item>Level one</VerticalListMenu.Item> </VerticalListMenu> ); }; /** Nested Full Width */ export const NestedFullWidth: Story<IVerticalListMenuProps> = (args) => { const [currentList, setCurrentList] = useState('one'); const [selectedIndices, setSelectedIndices] = useState([0]); const handleSelect = (currentList: string, index: number) => { setCurrentList(currentList); setSelectedIndices([index]); }; return ( <VerticalListMenu {...(args as any)} onSelect={partial(handleSelect, 'one')} selectedIndices={currentList === 'one' ? selectedIndices : []} > <VerticalListMenu.Item>Level one</VerticalListMenu.Item> <VerticalListMenu.Item isExpanded={true}> Level one with VerticalListMenu <VerticalListMenu onSelect={partial(handleSelect, 'two')} selectedIndices={currentList === 'two' ? selectedIndices : []} > <VerticalListMenu.Item>Level two</VerticalListMenu.Item> <VerticalListMenu.Item>Level two</VerticalListMenu.Item> </VerticalListMenu> </VerticalListMenu.Item> <VerticalListMenu.Item isExpanded={true}> Level one with VerticalListMenu <VerticalListMenu onSelect={partial(handleSelect, 'three')} selectedIndices={currentList === 'three' ? selectedIndices : []} > <VerticalListMenu.Item>Level two</VerticalListMenu.Item> <VerticalListMenu.Item isExpanded={false}> Level two with closed VerticalListMenu <VerticalListMenu onSelect={partial(handleSelect, 'four')} selectedIndices={currentList === 'four' ? selectedIndices : []} > <VerticalListMenu.Item>Level three</VerticalListMenu.Item> <VerticalListMenu.Item>Level three</VerticalListMenu.Item> <VerticalListMenu.Item>Level three</VerticalListMenu.Item> </VerticalListMenu> </VerticalListMenu.Item> <VerticalListMenu.Item>Level two</VerticalListMenu.Item> </VerticalListMenu> </VerticalListMenu.Item> <VerticalListMenu.Item>Level one</VerticalListMenu.Item> </VerticalListMenu> ); }; /** No Animations */ export const NoAnimations: Story<IVerticalListMenuProps> = Template.bind({}); NoAnimations.args = { children: addKeys([ <VerticalListMenu.Item>Level one</VerticalListMenu.Item>, <VerticalListMenu.Item Collapsible={{ isAnimated: false, // don't animate isMountControlled: false, // don't remove items from the dom when they are hidden }} hasExpander={true} > Level one with VerticalListMenu <VerticalListMenu> {times(20, (n) => { return ( <VerticalListMenu.Item key={n}>Level two</VerticalListMenu.Item> ); })} </VerticalListMenu> </VerticalListMenu.Item>, <VerticalListMenu.Item>Level one</VerticalListMenu.Item>, ]), }; |