-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce tooltip component #1
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
910ba9f
chore: Install dependencies
DGiannaris e6637b3
feature: Add new tooltip component
DGiannaris 77295cc
chore: Add a storybook story for the tooltip component
DGiannaris ed5f62d
fix: postcss preventing some css classes from being applied
DGiannaris 53413ab
feature: allow tooltip content to be overiden
DGiannaris d99288c
chore: Add story for customized tooltip content
DGiannaris f8e691b
chore: add radix ui tooltip as external in rollupOptions in vite configs
DGiannaris cdee24a
chore: housekeeping
DGiannaris 915095f
chore: format files
DGiannaris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️