|
| 1 | +import { ArgTypesWithNote, ControlsWithNote, DocsHeader, Footer } from '@sb/components'; |
| 2 | +import { Canvas, Description, Markdown, Meta } from '@storybook/blocks'; |
| 3 | +import * as ComponentStories from './Toolbar.stories'; |
| 4 | +import SubcomponentsSection from '@sb/docs/SubcomponentsSection.md?raw'; |
| 5 | +import { OverflowToolbarButton, OverflowToolbarToggleButton } from '../..'; |
| 6 | + |
| 7 | +<Meta of={ComponentStories} /> |
| 8 | + |
| 9 | +<DocsHeader /> |
| 10 | + |
| 11 | +## Example |
| 12 | + |
| 13 | +<Canvas of={ComponentStories.Default} /> |
| 14 | + |
| 15 | +## Properties |
| 16 | + |
| 17 | +<ControlsWithNote of={ComponentStories.Default} /> |
| 18 | + |
| 19 | +## Prevent event bubbling of Toolbar items |
| 20 | + |
| 21 | +Per default, if the `active` prop is "true" and an actionable element like a button is clicked, the `onClick` event of the `Toolbar` is also fired. |
| 22 | +To prevent this you can add `e.stopPropagation()` to your event handler. |
| 23 | + |
| 24 | +```jsx |
| 25 | +<Toolbar> |
| 26 | + <Button |
| 27 | + onClick={(e) => { |
| 28 | + //use e.stopPropagation() to prevent event bubbling |
| 29 | + e.stopPropagation(); |
| 30 | + }} |
| 31 | + > |
| 32 | + Toolbar Item |
| 33 | + </Button> |
| 34 | +</Toolbar> |
| 35 | +``` |
| 36 | + |
| 37 | +# More Examples |
| 38 | + |
| 39 | +## Align elements inside the Toolbar |
| 40 | + |
| 41 | +To align items inside the `Toolbar` you can use the `ToolbarSpacer` component.<br/> |
| 42 | +This will cover the remaining horizontal space between the `Toolbar` items and for example pushes one item to the edge of the `Toolbar`. |
| 43 | + |
| 44 | +### Right aligned items |
| 45 | + |
| 46 | +<Canvas of={ComponentStories.RightAlignedItems} /> |
| 47 | + |
| 48 | +### Evenly aligned items |
| 49 | + |
| 50 | +<Canvas of={ComponentStories.EvenlyAlignedItems} /> |
| 51 | + |
| 52 | +## Toolbar Separator |
| 53 | + |
| 54 | +You can add a visual separator between the preceding and succeeding `Toolbar` item with the use of the `ToolbarSeparator`. |
| 55 | + |
| 56 | +**Note:** In the overflow popover the `ToolbarSeparator` is represented by a horizontal line, in the `Toolbar` by a vertical |
| 57 | +line. |
| 58 | + |
| 59 | +<Canvas of={ComponentStories.WithSeparator} /> |
| 60 | + |
| 61 | +## Toolbar with overflow button |
| 62 | + |
| 63 | +If the horizontally available space isn't enough to fit all items in it, an overflow button is displayed. |
| 64 | + |
| 65 | +**Note:** You can change the width of the toolbar by dragging the `Slider`. |
| 66 | + |
| 67 | +<ControlsWithNote of={ComponentStories.WithOverflowButton} hideHTMLPropsNote include={['numberOfAlwaysVisibleItems']} /> |
| 68 | + |
| 69 | +<Canvas of={ComponentStories.WithOverflowButton} /> |
| 70 | + |
| 71 | +### OverflowToolbarButton & OverflowToolbarToggleButton |
| 72 | + |
| 73 | +With the `OverflowToolbarButton` and `OverflowToolbarToggleButton` it is possible to display the text of a `Button` with an icon only in the overflow popover of the `Toolbar`. |
| 74 | +Both components accept the same `props` as the standard `Button` or `ToggleButton` component, with the difference that `icon` is now required and `children` are only rendered inside the popover. |
| 75 | + |
| 76 | +<Canvas of={ComponentStories.OverflowBtns} /> |
| 77 | + |
| 78 | +### Toolbar with custom overflow button |
| 79 | + |
| 80 | +By setting the `overflowButton` prop, it's possible to change the overflow button, which is displayed if the `Toolbar` goes into overflow. |
| 81 | +Only buttons in icon only mode are supported and it's recommended to use the `ToggleButton` in `"Transparent"` design to comply with UX guidelines. |
| 82 | +Please also note that when using a custom button, it is your responsibility to set the appropriate a11y attributes. |
| 83 | + |
| 84 | +It is furthermore possible to prevent the popover from opening by using `event.preventDefault()` in the `onClick` of the button. This is useful e.g. when implementing a custom overflow popover. |
| 85 | + |
| 86 | +<Canvas of={ComponentStories.CustomOverflowButton} /> |
| 87 | + |
| 88 | +### Close overflow popover on interaction |
| 89 | + |
| 90 | +The overflow popover can be closed programmatically by using the `overflowPopoverRef`. |
| 91 | + |
| 92 | +```jsx |
| 93 | +const ToolbarComponent = () => { |
| 94 | + const overflowPopoverRef = useRef(null); |
| 95 | + const handlePopoverClose = () => { |
| 96 | + if (overflowPopoverRef.current.isOpen()) { |
| 97 | + overflowPopoverRef.current.close(); |
| 98 | + } |
| 99 | + }; |
| 100 | + return ( |
| 101 | + <Toolbar overflowPopoverRef={overflowPopoverRef}> |
| 102 | + <Text>Toolbar</Text> |
| 103 | + <Button onClick={handlePopoverClose}>Button One</Button> |
| 104 | + <Select onChange={handlePopoverClose}> |
| 105 | + <Option>Option 1</Option> |
| 106 | + <Option>Option 2</Option> |
| 107 | + </Select> |
| 108 | + </Toolbar> |
| 109 | + ); |
| 110 | +}; |
| 111 | +``` |
| 112 | + |
| 113 | +<Markdown>{SubcomponentsSection}</Markdown> |
| 114 | + |
| 115 | +## OverflowToolbarButton |
| 116 | + |
| 117 | +<Description of={OverflowToolbarButton} /> |
| 118 | + |
| 119 | +<ArgTypesWithNote of={OverflowToolbarButton} /> |
| 120 | + |
| 121 | +## OverflowToolbarToggleButton |
| 122 | + |
| 123 | +<Description of={OverflowToolbarToggleButton} /> |
| 124 | + |
| 125 | +<ArgTypesWithNote of={OverflowToolbarToggleButton} /> |
| 126 | + |
| 127 | +<Footer /> |
0 commit comments