Styled hover card
Five hover cards: a profile, glass, a preview, stats and media. Each is self-contained (no radix), sized, token-driven, and opens on hover or keyboard focus.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/hover-card-styledDependencies, the @ai2/tokens theme and the component file are installed together.
Copy the source
components/ui/hover-card-styled.tsx"use client"
import type * as React from "react"
import { cn } from "@/lib/utils"
/* HoverCard family: 5 decorative hover cards. Self-contained (no radix, no portal) - a trigger plus a card positioned below, opening on hover and focus through CSS (opacity plus a slight slide), with the transform transitions guarded by motion-reduce. Colour comes ONLY from tokens; alpha via color-mix. Size = the card width. trigger = the trigger, children = the card content. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const cardWidth: Record<StyledSize, string> = {
sm: "w-56",
md: "w-64",
lg: "w-72",
xl: "w-80",
}
const cardBase =
"invisible absolute left-1/2 top-full z-20 mt-2 -translate-x-1/2 translate-y-1 rounded-xl border border-border p-4 text-left opacity-0 shadow-lg transition-[opacity,transform] duration-(--motion-base) ease-(--motion-ease) group-hover:visible group-hover:translate-y-0 group-hover:opacity-100 group-focus-within:visible group-focus-within:translate-y-0 group-focus-within:opacity-100 motion-reduce:transition-none"
const triggerBase =
"inline-flex items-center rounded-md font-medium text-primary underline-offset-4 outline-none hover:underline focus-visible:ring-[3px] focus-visible:ring-ring/50"
interface Props {
size?: StyledSize
trigger?: React.ReactNode
children?: React.ReactNode
className?: string
}
function Wrapper({
trigger,
card,
}: {
trigger: React.ReactNode
card: React.ReactNode
}) {
const fallback = (
<button type="button" className={triggerBase}>
Hover me
</button>
)
return (
<span data-slot="styled-hover-card" className="group relative inline-flex">
{trigger ?? fallback}
{card}
</span>
)
}
/* Profile: bas harf avatar + isim + kisa bio + takip butonu. */
export function ProfileHoverCard({ size = "md", trigger, children, className }: Props) {
return (
<Wrapper
trigger={trigger}
card={
<span
role="dialog"
className={cn(cardBase, cardWidth[size], "block bg-popover text-popover-foreground", className)}
>
<span className="flex items-center gap-3">
<span className="flex size-10 shrink-0 items-center justify-center rounded-full bg-secondary text-sm font-medium text-secondary-foreground select-none">
AI
</span>
<span className="flex flex-col">
<span className="text-sm font-semibold">ai2 team</span>
<span className="text-xs text-muted-foreground">@ai2</span>
</span>
</span>
<span className="mt-3 block text-sm text-muted-foreground">
{children ?? "Designing a distributed component system you can trust."}
</span>
<span className="mt-3 inline-flex items-center rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground">
Follow
</span>
</span>
}
/>
)
}
/* Glass: buzlu cam kart + backdrop-blur, genel icerik. */
export function GlassHoverCard({ size = "md", trigger, children, className }: Props) {
return (
<Wrapper
trigger={trigger}
card={
<span
role="dialog"
className={cn(
cardBase,
cardWidth[size],
"block text-popover-foreground [background-color:color-mix(in_oklab,var(--popover)_70%,transparent)] supports-[backdrop-filter]:[background-color:color-mix(in_oklab,var(--popover)_45%,transparent)] supports-[backdrop-filter]:backdrop-blur-md",
className
)}
>
{children ?? (
<span className="block text-sm text-muted-foreground">
A frosted glass surface that layers softly over the content behind it.
</span>
)}
</span>
}
/>
)
}
/* Preview: a title plus a few lines of preview text. */
export function PreviewHoverCard({ size = "md", trigger, children, className }: Props) {
return (
<Wrapper
trigger={trigger}
card={
<span
role="dialog"
className={cn(cardBase, cardWidth[size], "block bg-popover text-popover-foreground", className)}
>
<span className="text-sm font-semibold">Preview</span>
<span className="mt-1.5 block text-sm leading-relaxed text-muted-foreground">
{children ??
"A short preview of the linked content. Just enough context to decide whether to open it in full."}
</span>
</span>
}
/>
)
}
/* Stats: 2-3 token istatistik blogu satiri. */
export function StatsHoverCard({ size = "md", trigger, children, className }: Props) {
return (
<Wrapper
trigger={trigger}
card={
<span
role="dialog"
className={cn(cardBase, cardWidth[size], "block bg-popover text-popover-foreground", className)}
>
{children ?? (
<span className="grid grid-cols-3 gap-2">
<span className="flex flex-col items-center rounded-lg bg-secondary px-2 py-2.5">
<span className="text-sm font-semibold text-secondary-foreground">128</span>
<span className="text-xs text-muted-foreground">Posts</span>
</span>
<span className="flex flex-col items-center rounded-lg bg-secondary px-2 py-2.5">
<span className="text-sm font-semibold text-secondary-foreground">4.2k</span>
<span className="text-xs text-muted-foreground">Followers</span>
</span>
<span className="flex flex-col items-center rounded-lg bg-secondary px-2 py-2.5">
<span className="text-sm font-semibold text-secondary-foreground">312</span>
<span className="text-xs text-muted-foreground">Following</span>
</span>
</span>
)}
</span>
}
/>
)
}
/* Media: ustte token thumbnail bloku + altta baslik. */
export function MediaHoverCard({ size = "md", trigger, children, className }: Props) {
return (
<Wrapper
trigger={trigger}
card={
<span
role="dialog"
className={cn(cardBase, cardWidth[size], "block bg-popover text-popover-foreground", className)}
>
<span
aria-hidden="true"
className="block h-28 w-full rounded-lg [background-image:linear-gradient(135deg,var(--surface-2),var(--surface-3))]"
/>
<span className="mt-3 block text-sm text-muted-foreground">
{children ?? "A thumbnail preview with a short caption below."}
</span>
</span>
}
/>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Profile
An avatar with a name, bio and follow button.
import { ProfileHoverCard } from "@/components/ui/hover-card-styled"
<ProfileHoverCard>A quick preview card that opens on hover or focus.</ProfileHoverCard>Glass
A frosted glass card with a blurred backdrop.
import { GlassHoverCard } from "@/components/ui/hover-card-styled"
<GlassHoverCard>A quick preview card that opens on hover or focus.</GlassHoverCard>Preview
A title with a couple of lines of preview text.
import { PreviewHoverCard } from "@/components/ui/hover-card-styled"
<PreviewHoverCard>A quick preview card that opens on hover or focus.</PreviewHoverCard>Stats
A small row of token stat blocks.
import { StatsHoverCard } from "@/components/ui/hover-card-styled"
<StatsHoverCard>A quick preview card that opens on hover or focus.</StatsHoverCard>Media
A token media block on top with a caption below.
import { MediaHoverCard } from "@/components/ui/hover-card-styled"
<MediaHoverCard>A quick preview card that opens on hover or focus.</MediaHoverCard>ai2 Styled hover card: 5 styled variations on the token system
The ai2 Styled hover card are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around cards that open on hover. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: the cards fade and rise on token CSS transitions when the trigger is hovered or focused. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the transitions are disabled and the card appears instantly.
What is in the ai2 Styled hover card?
5 exports in one file: Profile, Glass, Preview, Stats and Media. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: the cards fade and rise on token CSS transitions when the trigger is hovered or focused.
- Reduced-motion aware: Under prefers-reduced-motion, the transitions are disabled and the card appears instantly.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Styled hover card sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.