|
| 1 | +import type { Meta, StoryObj } from "@storybook/react"; |
| 2 | + |
| 3 | +import { Tooltip, Button } from "@fluentui/react-components"; |
| 4 | +import useFuiProviderNode from "@hooks/useFuiProviderNode"; |
| 5 | + |
| 6 | +/** |
| 7 | + * @description |
| 8 | + * - when you use a component in fluent that requires the parent provider node, for example for relative positioning, you can use this hook to get the parent provider node |
| 9 | + * - some components like Tooltip for example allow to set a mountNode prop, which is the parent provider node |
| 10 | + * - this will only work if you have exactly one provider node in your app |
| 11 | + * |
| 12 | + * @example |
| 13 | + * |
| 14 | + * ```tsx |
| 15 | + * import { Tooltip, Button } from "@fluentui/react-components"; |
| 16 | + * import useFuiProviderNode from "@hooks/useFuiProviderNode"; |
| 17 | + * |
| 18 | + * export default function SomeHigherComponent() { |
| 19 | + * const { fuiProviderNode } = useFuiProviderNode(); |
| 20 | + * return ( |
| 21 | + * <Tooltip |
| 22 | + * content="This is a tooltip that uses the provider node" |
| 23 | + * mountNode={fuiProviderNode} |
| 24 | + * relationship="label" |
| 25 | + * > |
| 26 | + * <Button>Hover me</Button> |
| 27 | + * </Tooltip> |
| 28 | + * ); |
| 29 | + * } |
| 30 | + * ``` |
| 31 | + */ |
| 32 | +export function Wrapper({ hasProviderNode }: { hasProviderNode: boolean }) { |
| 33 | + const { fuiProviderNode } = useFuiProviderNode(); |
| 34 | + return hasProviderNode ? ( |
| 35 | + <Tooltip |
| 36 | + content="This is a tooltip that uses the provider node" |
| 37 | + mountNode={fuiProviderNode} |
| 38 | + relationship="label" |
| 39 | + > |
| 40 | + <Button>Hover me</Button> |
| 41 | + </Tooltip> |
| 42 | + ) : ( |
| 43 | + <Tooltip |
| 44 | + content="This is a tooltip that relies on a unspecified provider node" |
| 45 | + relationship="label" |
| 46 | + > |
| 47 | + <Button>Hover me</Button> |
| 48 | + </Tooltip> |
| 49 | + ); |
| 50 | +} |
| 51 | + |
| 52 | +const meta: Meta = { |
| 53 | + title: "Hooks/Specific/useFuiProviderNode", |
| 54 | + component: Wrapper, |
| 55 | + args: { |
| 56 | + hasProviderNode: true, |
| 57 | + }, |
| 58 | +}; |
| 59 | + |
| 60 | +export default meta; |
| 61 | + |
| 62 | +type Story = StoryObj<typeof Wrapper>; |
| 63 | + |
| 64 | +export const WithNodeFromHook: Story = {}; |
| 65 | + |
| 66 | +export const DefaultProviderNode: Story = { |
| 67 | + args: { hasProviderNode: false }, |
| 68 | +}; |
0 commit comments