Tooltip
Tooltip with thoughtful defaults, semantic styling, and editable source.
Make it yours.
Install the editable source and its dependencies into your React + Tailwind project.
Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/tooltip.jsonUse it
Scroll horizontally for long lines
"use client";
import { Tooltip } from "@/components/jez-ui/ui/tooltip";
import { Button } from "@/components/jez-ui/ui/button";
export default function Example() {
return (
<>
<Tooltip content="Save your current work">
<Button variant="outline">Hover or focus me</Button>
</Tooltip>
</>
);
}
Compose your own
These styled parts are included in the same install. Use children to build your layout; add className only when you want an override.
Scroll horizontally for long lines
import { Tooltip, TooltipProvider, TooltipTrigger, TooltipContent } from "@/components/jez-ui/ui/tooltip";Props & types
Scroll horizontally for long lines
React.ComponentProps<typeof P.Root> & {
content?: React.ReactNode;
className?: string;
}Source
View 2 source files
registry/ui/tooltip.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { Tooltip as P } from "radix-ui";
import { cn } from "./utils";
export const TooltipProvider = P.Provider;
export const TooltipTrigger = P.Trigger;
export function Tooltip({
children,
content,
className,
...props
}: React.ComponentProps<typeof P.Root> & {
content?: React.ReactNode;
className?: string;
}) {
if (content === undefined) return <P.Root {...props}>{children}</P.Root>;
return (
<P.Provider delayDuration={250}>
<P.Root {...props}>
{content !== undefined ? (
<>
<TooltipTrigger asChild>{children}</TooltipTrigger>
<TooltipContent className={className}>{content}</TooltipContent>
</>
) : (
children
)}
</P.Root>
</P.Provider>
);
}
export function TooltipContent({
className,
children,
...props
}: React.ComponentProps<typeof P.Content>) {
return (
<P.Portal>
<P.Content
sideOffset={6}
collisionPadding={8}
className={cn(
"jez-popover z-50 max-w-xs rounded-lg bg-foreground px-3 py-2 text-xs leading-relaxed text-background",
className,
)}
{...props}
>
{children}
<P.Arrow className="fill-foreground" />
</P.Content>
</P.Portal>
);
}
registry/ui/utils.ts
Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
return twMerge(clsx(values));
}
Dependencies
radix-ui@1.6.7 · clsx@2.1.1 · tailwind-merge@3.5.0
Accessibility & behaviour
Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.
Read the accessibility and performance guide →