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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 3x 1x 1x 1x 1x 1x 1x 4x 12x 36x 108x | import _ from 'lodash'; import React, { useState } from 'react'; import createClass from 'create-react-class'; import { Meta, Story } from '@storybook/react'; import Button from '../Button/Button'; import ContextMenu, { IContextMenuProps } from './ContextMenu'; import SingleSelect from '../SingleSelect/SingleSelect'; import TextField from '../TextField/TextField'; export default { title: 'Utility/ContextMenu', component: ContextMenu, parameters: { docs: { description: { component: (ContextMenu as any).peek.description, }, }, }, } as Meta; enum EnumDirection { up = 'up', down = 'down', left = 'left', right = 'right', } /* Basic */ export const Basic: Story<IContextMenuProps> = (args) => { const Component = createClass({ render() { return ( <ContextMenu {...args}> <ContextMenu.Target> <Button>Target</Button> </ContextMenu.Target> <ContextMenu.FlyOut style={{ background: 'white', boxShadow: '1px 1px 4px black', padding: 4, }} > FlyOut </ContextMenu.FlyOut> </ContextMenu> ); }, }); return <Component />; }; /* Basic With Text */ export const BasicWithText: Story<IContextMenuProps> = (args) => { return ( <section> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget tempor mi. Curabitur eget risus ac diam euismod ultricies ac in est. Morbi in vehicula arcu, at laoreet libero. Phasellus nisi dolor, porta et erat quis, egestas mattis purus. <ContextMenu {...args} isExpanded direction='up'> <ContextMenu.Target> <Button>Target</Button> </ContextMenu.Target> <ContextMenu.FlyOut style={{ background: 'white', boxShadow: '1px -1px 4px black', padding: 4, }} > FlyOut </ContextMenu.FlyOut> </ContextMenu> Sed vel ex iaculis, tincidunt magna in, fringilla urna. Aenean congue est nec elit molestie, nec mollis mi rutrum. Quisque hendrerit nisl placerat tempus sodales. Vivamus et tortor vulputate, elementum turpis tempor, condimentum sapien. Nunc ac imperdiet ipsum, vitae ullamcorper sem. </section> ); }; /* Menu Bar */ export const MenuBar: Story<IContextMenuProps> = (args) => { const [isFileExpanded, setIsFileExpanded] = useState(false); const [fileDirection, setFileDirection] = useState('down'); const [isEditExpanded, setIsEditExpanded] = useState(false); const [editDirection, setEditDirection] = useState('down'); const handleFileMenuToggle = () => { setIsFileExpanded(!isFileExpanded); }; const handleEditMenuToggle = () => { setIsEditExpanded(!isEditExpanded); }; return ( <section> <ContextMenu {...args} portalId='FileMenu-example' isExpanded={isFileExpanded} direction={fileDirection as EnumDirection} onClickOut={handleFileMenuToggle} > <ContextMenu.Target> <div style={{ background: isFileExpanded ? '#fafafa' : '#eaeaea', outline: 'solid 1px #d1d1d1', padding: '4px', cursor: 'pointer', }} onClick={handleFileMenuToggle} > File </div> </ContextMenu.Target> <ContextMenu.FlyOut style={{ background: '#fafafa', outline: 'solid 1px #d1d1d1', boxShadow: ' 1px 1px 2px rgba(0, 0, 0, 0.2)', padding: '8px', }} > <div>New Window</div> <div>New File</div> <div>Open...</div> <div>Add Folder...</div> <div>Reopen Last Item</div> <hr /> <div>Save</div> <div>Save As...</div> <div>Save All</div> <hr /> <div>Close Tab</div> <div>Close Pane</div> <div>Close Window</div> </ContextMenu.FlyOut> </ContextMenu> <ContextMenu {...args} portalId='EditMenu-example' isExpanded={isEditExpanded} direction={editDirection as EnumDirection} onClickOut={handleEditMenuToggle} > <ContextMenu.Target> <div style={{ background: isEditExpanded ? '#fafafa' : '#eaeaea', outline: 'solid 1px #d1d1d1', padding: '4px', cursor: 'pointer', }} onClick={handleEditMenuToggle} > Edit </div> </ContextMenu.Target> <ContextMenu.FlyOut style={{ background: '#fafafa', outline: 'solid 1px #d1d1d1', boxShadow: ' 1px 1px 2px rgba(0, 0, 0, 0.2)', padding: '8px', }} > <div>Undo</div> <div>Redo</div> <hr /> <div>Cut</div> <div>Copy</div> <div>Paste</div> <div>Select All</div> </ContextMenu.FlyOut> </ContextMenu> </section> ); }; MenuBar.storyName = 'MenuBar'; /* Directions Interactive */ export const DirectionsInteractive: Story<IContextMenuProps> = (args) => { const { CENTER, DOWN, END, LEFT, RIGHT, START, UP } = ContextMenu; const [direction, setDirection] = useState('up'); const [directonOffset, setDirectionOffset] = useState('0'); const [alignment, setAlignment] = useState('start'); const [alignmentOffset, setAlignmentOffset] = useState('0'); const [getAlignmentOffset, setGetAlignmentOffset] = useState(() => { return undefined; }); const style = { background: 'white', boxShadow: '1px 1px 4px black', padding: 4, }; const directions = [UP, DOWN, LEFT, RIGHT]; const alignments = [START, CENTER, END]; return ( <section> <section style={{ display: 'flex', flexDirection: 'column', }} > <SingleSelect onSelect={(i) => setDirection(directions[i as any] as any)} > <SingleSelect.Placeholder> Select a direction </SingleSelect.Placeholder> {_.map(directions, (direction) => ( <SingleSelect.Option key={direction}> {direction} </SingleSelect.Option> ))} </SingleSelect> directonOffset: <TextField style={{ width: 100 }} value={directonOffset} onChange={(directonOffset) => setDirectionOffset(directonOffset)} /> <SingleSelect onSelect={(i) => setAlignment(alignments[i as any] as any)} > <SingleSelect.Placeholder> Select an alignment </SingleSelect.Placeholder> {_.map(alignments, (alignment) => ( <SingleSelect.Option key={alignment}> {alignment} </SingleSelect.Option> ))} </SingleSelect> alignmentOffset: <TextField style={{ width: 100 }} value={alignmentOffset} onChange={(alignmentOffset) => setAlignmentOffset(alignmentOffset)} /> getAlignmentOffset: <TextField isDisabled={alignment !== CENTER} style={{ width: 100 }} value={getAlignmentOffset} onSubmit={() => {}} /> <code>{getAlignmentOffset || null}</code> </section> <section style={{ display: 'flex', flexDirection: 'row', justifyContent: 'center', margin: '90px', }} > <ContextMenu {...args} direction={direction as any} directonOffset={ _.isEmpty(directonOffset) ? 0 : _.parseInt(directonOffset) } alignment={(alignment as any) || undefined} alignmentOffset={ _.isEmpty(alignmentOffset) ? undefined : _.parseInt(alignmentOffset) } getAlignmentOffset={getAlignmentOffset} > <ContextMenu.Target>Target</ContextMenu.Target> <ContextMenu.FlyOut style={{ width: 210, ...style }}> <div>{`direction: ${direction || 'default'}`}</div> <div>{`directonOffset: ${directonOffset || 'default'}`}</div> <div>{`alignment: ${alignment || 'default'}`}</div> <div>{`alignmentOffset: ${alignmentOffset || 'default'}`}</div> <div>{`getAlignmentOffset: ${ getAlignmentOffset || 'default' }`}</div> </ContextMenu.FlyOut> </ContextMenu> </section> </section> ); }; /* Directions Static */ export const DirectionsStatic: Story<IContextMenuProps> = (args) => { const { CENTER, DOWN, END, LEFT, RIGHT, START, UP } = ContextMenu; const directions = [UP, DOWN, LEFT, RIGHT]; const alignments = [START, CENTER, END]; const style = { background: 'white', boxShadow: '1px 1px 4px black', padding: 4, }; return ( <section style={{ display: 'flex', flexDirection: 'row', margin: '0 60px', }} > {_.map(directions, (direction) => { return ( <section key={direction} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', flexGrow: 1, }} > {_.map(alignments, (alignment) => _.map([0, 15, -15], (directonOffset) => _.map([0, 15, -15], (alignmentOffset) => ( <div key={`${alignment}${alignmentOffset}${directonOffset}`} style={{ marginTop: '120px' }} > <ContextMenu {...args} {...{ direction, directonOffset, alignment, alignmentOffset, }} > <ContextMenu.Target>Target</ContextMenu.Target> <ContextMenu.FlyOut style={style}> <div>{`direction: ${direction}`}</div> <div>{`directonOffset: ${directonOffset}`}</div> <div>{`alignment: ${alignment}`}</div> <div>{`alignmentOffset: ${alignmentOffset}`}</div> </ContextMenu.FlyOut> </ContextMenu> </div> )) ) )} </section> ); })} </section> ); }; |