diff --git a/src/components/tooltip/index.tsx b/src/components/tooltip/index.tsx new file mode 100644 index 00000000..3781f373 --- /dev/null +++ b/src/components/tooltip/index.tsx @@ -0,0 +1,33 @@ +import * as React from 'react' +import { Tooltip as BaseTooltip, TooltipTrigger, TooltipContent } from '../ui/tooltip' + +type TooltipProps = React.ComponentProps & { + title: React.ReactNode +} & Pick, 'side' | 'sideOffset' | 'align'> + +const TooltipContentNoArrow = ({ + children, + sideOffset = 8, // Needed when arrow is hidden + ...props +}: React.ComponentProps) => { + return ( + + {children} + + ) +} + +export const Tooltip = ({ title, children, side, sideOffset, align, ...props }: TooltipProps) => { + return ( + + {children} + + {title} + + + ) +} diff --git a/src/stories/Tooltip/Tooltip.stories.tsx b/src/stories/Tooltip/Tooltip.stories.tsx index f0b0e186..32ab86f0 100644 --- a/src/stories/Tooltip/Tooltip.stories.tsx +++ b/src/stories/Tooltip/Tooltip.stories.tsx @@ -1,5 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react-vite' -import { Tooltip, TooltipContent, TooltipTrigger } from '../../components/ui/tooltip.tsx' +import { Tooltip } from '../../components/tooltip' import { Button } from '../../components/ui/button.tsx' import { expect, within } from 'storybook/test' @@ -21,8 +21,14 @@ const meta: Meta = { }, tags: ['autodocs'], argTypes: { - defaultOpen: { - control: 'boolean', + title: { + control: 'text', + description: 'The content of the tooltip', + }, + side: { + control: { type: 'radio' }, + options: ['top', 'right', 'bottom', 'left'], + description: 'The preferred side of the trigger to render against', }, open: { control: 'boolean', @@ -38,16 +44,8 @@ type Story = StoryObj export const Default: Story = { args: { - children: ( - <> - - - - -

Tooltip content

-
- - ), + title: 'Tooltip content', + children: , }, play: async ({ canvasElement }) => { const canvas = within(canvasElement) @@ -55,53 +53,3 @@ export const Default: Story = { await expect(button).toBeInTheDocument() }, } - -export const Variants: Story = { - args: { - children: ( -
-
- - - - - -

Tooltip on top

-
-
-
- -
- - - - - -

Tooltip on left

-
-
- - - - - - -

Tooltip on right

-
-
-
- -
- - - - - -

Tooltip on bottom

-
-
-
-
- ), - }, -}