|
| 1 | +import {Fragment} from 'react'; |
| 2 | + |
| 3 | +import {Button} from 'sentry/components/core/button'; |
| 4 | +import {Flex} from 'sentry/components/core/layout'; |
| 5 | +import {Tooltip} from 'sentry/components/core/tooltip'; |
| 6 | +import * as Storybook from 'sentry/stories'; |
| 7 | + |
| 8 | +import types from '!!type-loader!sentry/components/core/tooltip'; |
| 9 | + |
| 10 | +export default Storybook.story('Tooltip', (story, APIReference) => { |
| 11 | + APIReference(types.Tooltip); |
| 12 | + |
| 13 | + story('Default', () => { |
| 14 | + return ( |
| 15 | + <Fragment> |
| 16 | + <p> |
| 17 | + Tooltip is a component that displays a tooltip when hovering over an element |
| 18 | + (duh). |
| 19 | + </p> |
| 20 | + <p> |
| 21 | + By default, a tooltip renders a wrapper around the children element and renders |
| 22 | + the tooltip content in a portal. The wrapper can be skipped by passing the{' '} |
| 23 | + <Storybook.JSXProperty name="skipWrapper" value="true" /> prop. |
| 24 | + </p> |
| 25 | + <Storybook.SideBySide> |
| 26 | + <Tooltip title="Tooltip"> |
| 27 | + <Button>Hover me</Button> |
| 28 | + </Tooltip> |
| 29 | + </Storybook.SideBySide> |
| 30 | + </Fragment> |
| 31 | + ); |
| 32 | + }); |
| 33 | + |
| 34 | + story('Hoverable Tooltip', () => { |
| 35 | + return ( |
| 36 | + <Fragment> |
| 37 | + <p> |
| 38 | + A tooltip is not hoverable by default and will hide before the pointer enters |
| 39 | + it's container - to make it hoverable, pass the{' '} |
| 40 | + <Storybook.JSXProperty name="isHoverable" value="true" /> prop. |
| 41 | + </p> |
| 42 | + <Storybook.SideBySide> |
| 43 | + <Tooltip title="This can be copied" isHoverable skipWrapper> |
| 44 | + <Button>Hoverable Tooltip</Button> |
| 45 | + </Tooltip> |
| 46 | + <Tooltip title="This cannot be copied" skipWrapper> |
| 47 | + <Button>Non Hoverable Tooltip</Button> |
| 48 | + </Tooltip> |
| 49 | + </Storybook.SideBySide> |
| 50 | + </Fragment> |
| 51 | + ); |
| 52 | + }); |
| 53 | + |
| 54 | + story('All Positions', () => { |
| 55 | + return ( |
| 56 | + <Fragment> |
| 57 | + <p> |
| 58 | + Tooltips can be positioned in different directions. Use the{' '} |
| 59 | + <Storybook.JSXNode name="position" /> prop to control placement. |
| 60 | + </p> |
| 61 | + <Flex direction="column" gap={1} align="center"> |
| 62 | + <div |
| 63 | + style={{ |
| 64 | + display: 'flex', |
| 65 | + flexDirection: 'column', |
| 66 | + gap: '8px', |
| 67 | + margin: '40px 0 40px 0', |
| 68 | + alignItems: 'center', |
| 69 | + }} |
| 70 | + > |
| 71 | + <Tooltip title="Top Tooltip Position" position="top" forceVisible> |
| 72 | + <Button>Top</Button> |
| 73 | + </Tooltip> |
| 74 | + <div style={{display: 'flex', gap: '8px'}}> |
| 75 | + <Tooltip title="Left Tooltip Position" position="left" forceVisible> |
| 76 | + <Button>Left</Button> |
| 77 | + </Tooltip> |
| 78 | + <Tooltip title="Right Tooltip Position" position="right" forceVisible> |
| 79 | + <Button>Right</Button> |
| 80 | + </Tooltip> |
| 81 | + </div> |
| 82 | + <Tooltip title="Bottom Tooltip Position" position="bottom" forceVisible> |
| 83 | + <Button>Bottom</Button> |
| 84 | + </Tooltip> |
| 85 | + </div> |
| 86 | + </Flex> |
| 87 | + </Fragment> |
| 88 | + ); |
| 89 | + }); |
| 90 | +}); |
0 commit comments