Media cards
Five cards built around a media region: an image block, a cover with a lifted panel, an overlay with a scrim, a horizontal split and a centred avatar. The media is always drawn from tokens and inline SVG, so there is no remote image to load and nothing breaks offline.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/card-mediaDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install lucide-reactCopy the source
components/ui/card-media.tsx"use client"
import * as React from "react"
import { ImageIcon, Play } from "lucide-react"
import { cn } from "@/lib/utils"
/* Media card family: 5 cards carrying an image or media region. There are no remote images at all (offline and CSP safe): the media area is drawn as a token-coloured placeholder surface plus an inline SVG pattern. Colour comes ONLY from semantic tokens, transparency through color-mix. size = the padding plus radius scale (the same as card-styled). */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const radii: Record<StyledSize, string> = {
sm: "rounded-lg",
md: "rounded-xl",
lg: "rounded-2xl",
xl: "rounded-2xl",
}
const pads: Record<StyledSize, string> = {
sm: "p-4",
md: "p-5",
lg: "p-6",
xl: "p-8",
}
const mediaHeights: Record<StyledSize, string> = {
sm: "h-20",
md: "h-24",
lg: "h-28",
xl: "h-36",
}
/* The Overlay variant puts the text on the media, so it wants a taller media area. */
const overlayHeights: Record<StyledSize, string> = {
sm: "h-36",
md: "h-40",
lg: "h-44",
xl: "h-52",
}
type Props = React.ComponentProps<"div"> & { size?: StyledSize }
const shell =
"relative w-64 overflow-hidden border border-border bg-card text-card-foreground"
/* A token-colored placeholder surface: no remote src, only a gradient + an inline
SVG pattern + a lucide icon. */
function MediaSurface({
className,
children,
}: {
className?: string
children?: React.ReactNode
}) {
/* The pattern id must be unique per instance, otherwise two cards on the same page share the same SVG id. */
const patternId = `ai2-media-grid-${React.useId().replace(/:/g, "")}`
return (
<div
aria-hidden="true"
className={cn(
"relative flex items-center justify-center overflow-hidden bg-[linear-gradient(135deg,color-mix(in_oklab,var(--color-primary)_30%,transparent),color-mix(in_oklab,var(--color-foreground)_10%,transparent))] text-muted-foreground",
className
)}
>
<svg
className="pointer-events-none absolute inset-0 size-full text-foreground"
aria-hidden="true"
>
<defs>
<pattern id={patternId} width="12" height="12" patternUnits="userSpaceOnUse">
<path
d="M12 0H0V12"
fill="none"
stroke="currentColor"
strokeOpacity="0.14"
strokeWidth="1"
/>
</pattern>
</defs>
<rect width="100%" height="100%" fill={`url(#${patternId})`} />
</svg>
<span className="relative [&>svg]:size-6 [&>i]:text-2xl [&>i]:leading-none">
{children}
</span>
</div>
)
}
function Heading({ children }: { children: React.ReactNode }) {
return <span className="text-sm font-semibold text-foreground">{children}</span>
}
function Sub({ children }: { children: React.ReactNode }) {
return (
<span className="text-xs leading-relaxed text-muted-foreground">{children}</span>
)
}
const defaultBody = (
<div className="flex flex-col gap-1">
<Heading>Card title</Heading>
<Sub>A short description that sits under the media region.</Sub>
</div>
)
/* Image: medya bolgesi ustte, metin altta. Klasik dizilim. */
export function ImageCard({ className, size = "md", children, ...props }: Props) {
return (
<div
data-slot="styled-card"
className={cn(shell, radii[size], className)}
{...props}
>
<MediaSurface className={cn("w-full", mediaHeights[size])}>
<ImageIcon />
</MediaSurface>
<div className={pads[size]}>{children ?? defaultBody}</div>
</div>
)
}
/* Cover: full-width cover media with the text panel riding up over it. */
export function CoverCard({ className, size = "md", children, ...props }: Props) {
return (
<div
data-slot="styled-card"
className={cn(shell, "bg-surface-2", radii[size], className)}
{...props}
>
<MediaSurface className={cn("w-full", mediaHeights[size])}>
<Play />
</MediaSurface>
<div className={cn("relative -mt-4 rounded-t-xl bg-card", pads[size])}>
{children ?? defaultBody}
</div>
</div>
)
}
/* Overlay: the text sits on the media and stays readable thanks to a token scrim gradient underneath. */
export function OverlayCard({ className, size = "md", children, ...props }: Props) {
return (
<div
data-slot="styled-card"
className={cn(shell, radii[size], className)}
{...props}
>
<MediaSurface className={cn("w-full", overlayHeights[size])}>
<ImageIcon />
</MediaSurface>
<div
aria-hidden="true"
className="pointer-events-none absolute inset-0 bg-[linear-gradient(to_top,color-mix(in_oklab,var(--color-foreground)_75%,transparent),transparent_70%)]"
/>
<div className={cn("absolute inset-x-0 bottom-0", pads[size])}>
{children ?? (
<div className="flex flex-col gap-1">
<span className="text-sm font-semibold text-background">Card title</span>
<span className="text-xs leading-relaxed text-background/80">
Text that sits on the media behind a token scrim.
</span>
</div>
)}
</div>
</div>
)
}
/* Split: medya solda dar bir serit, metin sagda. Yatay dizilim. */
export function SplitCard({ className, size = "md", children, ...props }: Props) {
return (
<div
data-slot="styled-card"
className={cn(shell, "flex w-80 items-stretch", radii[size], className)}
{...props}
>
<MediaSurface className="w-24 shrink-0">
<ImageIcon />
</MediaSurface>
<div className={cn("flex-1", pads[size])}>{children ?? defaultBody}</div>
</div>
)
}
/* Avatar: yuvarlak token placeholder avatar + isim/rol, ortalanmis profil
karti. */
export function AvatarCard({ className, size = "md", children, ...props }: Props) {
return (
<div
data-slot="styled-card"
className={cn(shell, "text-center", radii[size], pads[size], className)}
{...props}
>
<div className="flex flex-col items-center gap-3">
<span
aria-hidden="true"
className="flex size-14 items-center justify-center rounded-full border border-border bg-[linear-gradient(135deg,color-mix(in_oklab,var(--color-primary)_35%,transparent),color-mix(in_oklab,var(--color-foreground)_12%,transparent))] text-sm font-semibold text-foreground"
>
AI
</span>
{children ?? (
<div className="flex flex-col gap-1">
<Heading>Full name</Heading>
<Sub>Role or title</Sub>
</div>
)}
</div>
</div>
)
}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.
Image
A media region on top with the text underneath.
import { ImageCard } from "@/components/ui/card-media"
<ImageCard />Cover
A full-width cover with the text panel lifted over its edge.
import { CoverCard } from "@/components/ui/card-media"
<CoverCard />Overlay
Text sitting on the media behind a token scrim gradient.
import { OverlayCard } from "@/components/ui/card-media"
<OverlayCard />Split
A narrow media strip on the left with the text beside it.
import { SplitCard } from "@/components/ui/card-media"
<SplitCard />Avatar
A centred profile card with a round token avatar.
import { AvatarCard } from "@/components/ui/card-media"
<AvatarCard />ai2 Media cards: 5 styled variations on the token system
The ai2 Media cards are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around cards with a media region drawn entirely from tokens. 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 layouts are static, so no animation runs by default. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the cards look and behave exactly the same.
What is in the ai2 Media cards?
5 exports in one file: Image, Cover, Overlay, Split and Avatar. 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 layouts are static, so no animation runs by default.
- Reduced-motion aware: Under prefers-reduced-motion, the cards look and behave exactly the same.
- 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 Media cards 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.