| 504 | export const WithRef: Story = { |
| 505 | render: () => { |
| 506 | const TooltipWithRef = () => { |
| 507 | const tooltipRef = useRef<TooltipHandle>(null); |
| 508 | |
| 509 | return ( |
| 510 | <div style={{display: 'flex', gap: '20px'}}> |
| 511 | <Tooltip |
| 512 | ref={tooltipRef} |
| 513 | content="Controlled via ref" |
| 514 | position="top" |
| 515 | onOpen={fn()} |
| 516 | onClose={fn()} |
| 517 | onMouseLeave={fn()} |
| 518 | > |
| 519 | <button style={{padding: '10px 20px'}}>Hover for tooltip</button> |
| 520 | </Tooltip> |
| 521 | <button |
| 522 | style={{padding: '10px 20px'}} |
| 523 | onClick={() => { |
| 524 | if (tooltipRef.current) { |
| 525 | tooltipRef.current.dismissTooltip(true); |
| 526 | } |
| 527 | }} |
| 528 | > |
| 529 | Dismiss tooltip |
| 530 | </button> |
| 531 | </div> |
| 532 | ); |
| 533 | }; |
| 534 | |
| 535 | return <TooltipWithRef />; |
| 536 | }, |