-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: Install dependencies * feature: Add new tooltip component * chore: Add a storybook story for the tooltip component * fix: postcss preventing some css classes from being applied * feature: allow tooltip content to be overiden * chore: Add story for customized tooltip content * chore: add radix ui tooltip as external in rollupOptions in vite configs * chore: housekeeping * chore: format files
- Loading branch information
1 parent
c95bc1e
commit 5e707da
Showing
10 changed files
with
227 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export const plugins = { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import * as React from "react"; | ||
import { Tooltip, type TooltipProps } from "@synopsisapp/symbiosis-ui"; | ||
|
||
const meta: Meta<typeof Tooltip.Root> = { | ||
title: "Components/Tooltip", | ||
component: Tooltip.Root, | ||
tags: ["autodocs"], | ||
decorators: [ | ||
(Story) => ( | ||
<div className="flex flex-col gap-4 items-start"> | ||
<Story /> | ||
</div> | ||
), | ||
], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof Tooltip.Root>; | ||
|
||
export const Uncontrolled: Story = { | ||
render: (args: TooltipProps["Root"]) => ( | ||
<Tooltip.Root {...args}> | ||
<Tooltip.Trigger> | ||
<span>Hover me</span> | ||
</Tooltip.Trigger> | ||
<Tooltip.Content label="Tooltip label" /> | ||
</Tooltip.Root> | ||
), | ||
argTypes: { | ||
defaultOpen: { | ||
control: false, | ||
table: { | ||
defaultValue: { summary: "false" }, | ||
type: { summary: "boolean" }, | ||
}, | ||
description: | ||
"The open state of the tooltip when it is initially rendered. Use when you do not need to control its open state.", | ||
required: false, | ||
}, | ||
open: { | ||
control: { | ||
type: "boolean", | ||
}, | ||
table: { | ||
defaultValue: { summary: "false" }, | ||
}, | ||
type: "boolean", | ||
description: "The controlled open state of the tooltip. Must be used in conjunction with onOpenChange.", | ||
defaultValue: false, | ||
required: false, | ||
}, | ||
onOpenChange: { | ||
table: { | ||
type: { summary: "(open: boolean) => void" }, | ||
}, | ||
description: "Event handler called when the open state of the tooltip changes.", | ||
control: false, | ||
required: false, | ||
}, | ||
}, | ||
}; | ||
|
||
export const Controlled: Story = { | ||
render: (args) => { | ||
const [open, setOpen] = React.useState(false); | ||
return ( | ||
<Tooltip.Root {...args} open={open} onOpenChange={setOpen}> | ||
<Tooltip.Trigger> | ||
<span>Hover me</span> | ||
</Tooltip.Trigger> | ||
<Tooltip.Content label="Controlled Tooltip" /> | ||
</Tooltip.Root> | ||
); | ||
}, | ||
parameters: { | ||
docs: { | ||
source: { | ||
code: ` | ||
const ControlledTooltip = () => { | ||
const [open, setOpen] = React.useState(false); | ||
return ( | ||
<Tooltip.Root open={open} onOpenChange={setOpen}> | ||
<Tooltip.Trigger> | ||
<span>Hover me</span> | ||
</Tooltip.Trigger> | ||
<Tooltip.Content label="Controlled Tooltip" /> | ||
</Tooltip.Root> | ||
); | ||
}; | ||
`, | ||
language: "jsx", | ||
type: "code", | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const CustomContent: Story = { | ||
render: (args: TooltipProps["Root"]) => ( | ||
<Tooltip.Root {...args}> | ||
<Tooltip.Trigger> | ||
<span>Hover me</span> | ||
</Tooltip.Trigger> | ||
<Tooltip.Content className="bg-mainColors-light-200 rounded-none"> | ||
<div>Popover content</div> | ||
</Tooltip.Content> | ||
</Tooltip.Root> | ||
), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"; | ||
import { Text } from "../Text"; | ||
import { cn } from "../../utils/cn"; | ||
import type { TooltipRootProps, TooltipContentProps, TooltipTriggerProps } from "./types"; | ||
import { sharedTooltipStyles } from "./styles"; | ||
|
||
export const TooltipRoot = ({ children, defaultOpen, open, onOpenChange }: TooltipRootProps) => { | ||
return ( | ||
<TooltipPrimitive.Provider> | ||
<TooltipPrimitive.Root delayDuration={100} open={open} onOpenChange={onOpenChange} defaultOpen={defaultOpen}> | ||
{children} | ||
</TooltipPrimitive.Root> | ||
</TooltipPrimitive.Provider> | ||
); | ||
}; | ||
|
||
TooltipRoot.displayName = "Tooltip.Root"; | ||
|
||
export const TooltipContent = ({ children, label, className }: TooltipContentProps) => { | ||
return ( | ||
<TooltipPrimitive.Portal> | ||
<TooltipPrimitive.Content sideOffset={5} forceMount className={cn(sharedTooltipStyles, className)}> | ||
{label ? ( | ||
<Text variant="body-small-200" noTranslations className="m-0 p-0"> | ||
{label} | ||
</Text> | ||
) : ( | ||
children | ||
)} | ||
</TooltipPrimitive.Content> | ||
</TooltipPrimitive.Portal> | ||
); | ||
}; | ||
|
||
TooltipContent.displayName = "Tooltip.Content"; | ||
|
||
export const TooltipTrigger = ({ children }: TooltipTriggerProps) => { | ||
return ( | ||
<TooltipPrimitive.Trigger asChild> | ||
<div>{children}</div> | ||
</TooltipPrimitive.Trigger> | ||
); | ||
}; | ||
|
||
TooltipTrigger.displayName = "Tooltip.Trigger"; | ||
|
||
export const Tooltip = { | ||
Root: TooltipRoot, | ||
Content: TooltipContent, | ||
Trigger: TooltipTrigger, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { cn } from "../../utils/cn"; | ||
|
||
export const sharedTooltipStyles = cn( | ||
"py-2 px-3 rounded-md bg-gray-700 text-white max-w-[200px]", | ||
"will-change-[transform,opacity]", | ||
"data-[state=delayed-open]:data-[side=top]:animate-slide-up-and-fade", | ||
"data-[state=delayed-open]:data-[side=right]:animate-slide-right-and-fade", | ||
"data-[state=delayed-open]:data-[side=left]:animate-slide-left-and-fade", | ||
"data-[state=delayed-open]:data-[side=bottom]:animate-slide-down-and-fade", | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export type TooltipRootProps = { | ||
children: React.ReactNode; | ||
defaultOpen?: boolean; | ||
open?: boolean; | ||
onOpenChange?: (open: boolean) => void; | ||
}; | ||
|
||
export type TooltipContentProps = { | ||
children?: React.ReactNode; | ||
label?: string; | ||
className?: string; | ||
}; | ||
|
||
export type TooltipTriggerProps = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
export type TooltipProps = { | ||
Root: TooltipRootProps; | ||
Content: TooltipContentProps; | ||
Trigger: TooltipTriggerProps; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters