-
Notifications
You must be signed in to change notification settings - Fork 12
feat: Add Tooltip primitive #611
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
Open
jordanarldt
wants to merge
1
commit into
makeswift:main
Choose a base branch
from
jordanarldt:ja/add-tooltip
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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,53 @@ | ||
| --- | ||
| title: Tooltip | ||
| preview: tooltip-example | ||
| previewSize: sm | ||
| --- | ||
|
|
||
| ## Usage | ||
|
|
||
| {/* prettier-ignore-start */} | ||
|
|
||
| <CodeBlock lang="ts">{` | ||
|
|
||
| import { Tooltip } from '@/vibes/soul/primitives/tooltip'; | ||
|
|
||
| function Usage() { | ||
| return ( | ||
| <Tooltip trigger={<div>Tooltip trigger</div>}> | ||
| Tooltip content | ||
| </Tooltip> | ||
| ); | ||
| } | ||
| `} | ||
| </CodeBlock> | ||
|
|
||
| {/* prettier-ignore-end */} | ||
|
|
||
| ## API Reference | ||
|
|
||
| This comoponent uses the Sonner toast component. For more information, please refer to the [Sonner documentation](https://sonner.emilkowal.ski/). | ||
|
|
||
| ### TooltipProps | ||
|
|
||
| | Prop | Type | Default | | ||
| | ------------------- | ---------------------------------------- | ---------- | | ||
| | `align` | `'center' \| 'end' \| 'start'` | `'center'` | | ||
| | `className` | `string` | | | ||
| | `delayDuration` | `number` | | | ||
| | `skipDelayDuration` | `number` | | | ||
| | `trigger` | `React.ReactNode` | | | ||
| | `open` | `boolean` | | | ||
| | `setOpen` | `(open: boolean) => void` | | | ||
| | `side` | `'top' \| 'right' \| 'bottom' \| 'left'` | `'top'` | | ||
| | `sideOffset` | `number` | `6` | | ||
|
|
||
| ### CSS Variables | ||
|
|
||
| This component supports various CSS variables for theming. Here's a comprehensive list. | ||
|
|
||
| ```css | ||
| :root { | ||
| --tooltip-background: hsl(var(--background)); | ||
| } | ||
| ``` |
This file contains hidden or 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 hidden or 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,13 @@ | ||
| import { Tooltip } from '@/vibes/soul/primitives/tooltip'; | ||
|
|
||
| export default function Preview() { | ||
| return ( | ||
| <div className="bg-background p-8 @container"> | ||
| <div className="mx-auto flex max-w-screen-md flex-col items-center gap-8"> | ||
| <Tooltip trigger={<div>Hover me!</div>} delayDuration={0}> | ||
| <p className="text-sm text-contrast-500">Put your tooltip content here!</p> | ||
| </Tooltip> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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,62 @@ | ||
| import * as TooltipPrimitive from '@radix-ui/react-tooltip'; | ||
| import { clsx } from 'clsx'; | ||
|
|
||
| interface TooltipProps extends React.PropsWithChildren { | ||
| align?: 'center' | 'end' | 'start'; | ||
| className?: string; | ||
| delayDuration?: number; | ||
| skipDelayDuration?: number; | ||
| trigger?: React.ReactNode; | ||
| open?: boolean; | ||
| setOpen?: (open: boolean) => void; | ||
| side?: 'top' | 'right' | 'bottom' | 'left'; | ||
| sideOffset?: number; | ||
| } | ||
|
|
||
| // eslint-disable-next-line valid-jsdoc | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove this eslint-disable in VIBES?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ope yep! Good call |
||
| /** | ||
| * This component supports various CSS variables for theming. Here's a comprehensive list, along | ||
| * with their default values: | ||
| * | ||
| * ```css | ||
| * :root { | ||
| * --tooltip-background: hsl(var(--background)); | ||
| * ``` | ||
| */ | ||
| export const Tooltip = ({ | ||
| align = 'center', | ||
| className = '', | ||
| delayDuration, | ||
| skipDelayDuration, | ||
| trigger, | ||
| open, | ||
| setOpen, | ||
| side = 'top', | ||
| sideOffset = 6, | ||
| children, | ||
| }: TooltipProps) => { | ||
| return ( | ||
| <TooltipPrimitive.Provider delayDuration={delayDuration} skipDelayDuration={skipDelayDuration}> | ||
| <TooltipPrimitive.Root onOpenChange={setOpen} open={open}> | ||
| {trigger != null && ( | ||
| <TooltipPrimitive.Trigger asChild={typeof trigger !== 'string'}> | ||
| {trigger} | ||
| </TooltipPrimitive.Trigger> | ||
| )} | ||
| <TooltipPrimitive.Portal> | ||
| <TooltipPrimitive.Content | ||
| align={align} | ||
| className={clsx( | ||
| 'z-50 max-h-80 rounded-2xl border border-contrast-100 bg-[var(--tooltip-background,hsl(var(--background)))] p-3 shadow-xl data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95', | ||
| className, | ||
| )} | ||
| side={side} | ||
| sideOffset={sideOffset} | ||
| > | ||
| {children} | ||
| </TooltipPrimitive.Content> | ||
| </TooltipPrimitive.Portal> | ||
| </TooltipPrimitive.Root> | ||
| </TooltipPrimitive.Provider> | ||
| ); | ||
| }; | ||
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.
In what scenarios would we want a trigger being optional for tooltip?
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.
If it's being controlled externally by some other state or if the trigger needs to be detached from the component. For our use-case in catalyst it doesn't need to be optional, so I can make it required if needed!
But also, the trigger isn't required in the underlying Radix UI component IIRC!