Morphic Tooltip
1 バリエーション
A shared-layout tooltip primitive with one animated surface that morphs between triggers for polished hover and focus hints.
TSXcomponents/previews/premium/morphic-tooltip-preview.tsx
"use client";
import {
Frame,
Hand,
type LucideIcon,
MessageCircle,
MousePointer2,
PenTool,
Share2,
Type,
} from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/motion/button";
import {
MorphicTooltip,
MorphicTooltipProvider,
} from "@/components/premium/morphic-tooltip";
import { cn } from "@/lib/utils";
type Tool = { id: string; label: string; shortcut: string; icon: LucideIcon };
const TOOLS: Tool[] = [
{ id: "select", label: "Move", shortcut: "V", icon: MousePointer2 },
{ id: "hand", label: "Pan the canvas", shortcut: "H", icon: Hand },
{ id: "frame", label: "Frame", shortcut: "F", icon: Frame },
{ id: "pen", label: "Pen", shortcut: "P", icon: PenTool },
{ id: "text", label: "Text", shortcut: "T", icon: Type },
{
id: "comment",
label: "Leave a comment",
shortcut: "C",
icon: MessageCircle,
},
];
function TooltipLabel({
label,
shortcut,
}: {
label: string;
shortcut: string;
}) {
return (
<span className="inline-flex items-center gap-2 whitespace-nowrap">
{label}
<kbd className="rounded-full bg-background/15 px-1.5 font-mono text-background/70 text-xs">
{shortcut}
</kbd>
</span>
);
}
export function MorphicTooltipPreview() {
const [tool, setTool] = useState("select");
return (
<MorphicTooltipProvider>
<div className="flex items-center gap-1 rounded-full border border-border bg-background p-1">
{TOOLS.map(({ id, label, shortcut, icon: Icon }) => (
<MorphicTooltip
key={id}
content={<TooltipLabel label={label} shortcut={shortcut} />}
>
<Button
variant="ghost"
size="icon"
aria-label={label}
aria-pressed={tool === id}
aria-keyshortcuts={shortcut}
onClick={() => setTool(id)}
className={cn(
"size-9",
tool === id && "bg-muted text-foreground hover:bg-muted",
)}
>
<Icon className="size-4" aria-hidden="true" />
</Button>
</MorphicTooltip>
))}
<span aria-hidden="true" className="mx-1 h-5 w-px bg-border" />
<MorphicTooltip content="Share with your team">
<Button size="sm" className="h-9 gap-1.5 px-4 text-sm">
<Share2 className="size-3.5" aria-hidden="true" />
Share
</Button>
</MorphicTooltip>
</div>
</MorphicTooltipProvider>
);
}
インストール
shadcn CLI でこのコンポーネントを追加します。
$ bunx --bun shadcn add @beui-pro/morphic-tooltip