Header sheets
Five right-edge sheets that share the same slide-in and vary only the header and footer banding: a plain title band, a sticky header over long content, a sticky action footer, section dividers and a token accent strip. Each is self-contained (no radix), sized, token-driven, and closes on backdrop click or Escape.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/sheet-headerDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/sheet-header.tsx"use client"
import * as React from "react"
import { motion, AnimatePresence, useReducedMotion } from "motion/react"
import { X } from "lucide-react"
import { cn } from "@/lib/utils"
/* Header-themed sheet family: 5 right-edge panels, all carrying the same slide
mechanic from the right edge; the difference is ONLY in the layout of the
HEADER/FOOTER band. The panel is always clear/opaque (bg-card). Self-contained -
no radix, no portal. A fixed inset-0 backdrop + a fixed panel pinned to the edge
(z-50). Internal state (defaultOpen) or controlled (open + onOpenChange). A
backdrop click / Escape / the close button closes it. The panel takes focus on
open. The slide runs through AnimatePresence; under reduced-motion there is no
slide, only a fade. Color comes ONLY from tokens, with transparency via
color-mix. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
type Edge = "right" | "left" | "top" | "bottom"
const widthSize: Record<StyledSize, string> = {
sm: "w-72",
md: "w-80",
lg: "w-96",
xl: "w-[32rem]",
}
const heightSize: Record<StyledSize, string> = {
sm: "h-40",
md: "h-64",
lg: "h-80",
xl: "h-[32rem]",
}
const edgeAnchor: Record<Edge, string> = {
right: "inset-y-0 right-0",
left: "inset-y-0 left-0",
top: "inset-x-0 top-0",
bottom: "inset-x-0 bottom-0",
}
/* The slideOffset mechanism from essentials is preserved: the panel slides in from
100 percent outside its own edge. */
function slideOffset(edge: Edge) {
switch (edge) {
case "right":
return { x: "100%" }
case "left":
return { x: "-100%" }
case "top":
return { y: "-100%" }
case "bottom":
return { y: "100%" }
}
}
interface SheetProps {
size?: StyledSize
trigger?: React.ReactNode
title?: React.ReactNode
children?: React.ReactNode
className?: string
open?: boolean
defaultOpen?: boolean
onOpenChange?: (o: boolean) => void
}
function useControllableOpen(
open: boolean | undefined,
defaultOpen: boolean | undefined,
onOpenChange: ((o: boolean) => void) | undefined
) {
const [uncontrolled, setUncontrolled] = React.useState(defaultOpen ?? false)
const isControlled = open !== undefined
const value = isControlled ? open : uncontrolled
const setValue = React.useCallback(
(next: boolean) => {
if (!isControlled) setUncontrolled(next)
onOpenChange?.(next)
},
[isControlled, onOpenChange]
)
return [value, setValue] as const
}
/* Enough dummy text to scroll. Even when the content is short the panel is
always scrollable. */
const filler = [
"Sheets slide in from the edge and hold secondary tasks without leaving the current page.",
"Everything inside scrolls on its own, so a long form or a dense list never pushes the banded header or footer out of reach.",
"Use the banded layout to separate a persistent title from the body, and keep the primary actions anchored where the eye expects them.",
"Group related fields, review a summary, or read through a policy without losing the surrounding context.",
"Press Escape or click outside the panel at any time to dismiss it and return to the page underneath.",
"The panel stays opaque on the ai2 card surface, so text keeps its contrast in both the light and dark themes.",
]
/* Sample sections for the divider-separated body (DividerSheet). */
const dividerSections = [
{
heading: "Overview",
body: "A short summary sits at the top so the reader knows what the panel is for before scrolling.",
},
{
heading: "Details",
body: "Each block is separated by a token divider, which keeps long content readable without extra chrome.",
},
{
heading: "Notes",
body: "Dividers span the full width of the panel, so the sections line up with the banded header above.",
},
{
heading: "Next steps",
body: "Close the panel when you are done, or keep scrolling to review everything one more time.",
},
]
const triggerBtn =
"inline-flex h-9 shrink-0 select-none items-center justify-center gap-2 rounded-lg border border-border bg-secondary px-4 text-sm font-medium text-secondary-foreground outline-none whitespace-nowrap transition-[color,background-color] duration-(--motion-fast) ease-(--motion-ease) hover:bg-surface-3 focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_i]:text-base [&_i]:leading-none [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0"
/* The close button: pinned to the top right of the panel. A focus ring + icon
alignment (svg + i). */
const closeBtn =
"absolute right-4 top-4 z-20 inline-flex size-7 items-center justify-center rounded-md text-muted-foreground outline-none transition-[color,background-color] duration-(--motion-fast) ease-(--motion-ease) hover:bg-surface-3 hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_i]:text-base [&_i]:leading-none [&_svg]:size-4 [&_svg]:shrink-0"
/* Footer aksiyon butonlari. */
const footerGhostBtn =
"inline-flex h-9 select-none items-center justify-center rounded-lg border border-border bg-transparent px-4 text-sm font-medium text-foreground outline-none whitespace-nowrap transition-[color,background-color] duration-(--motion-fast) ease-(--motion-ease) hover:bg-surface-3 focus-visible:ring-[3px] focus-visible:ring-ring/50"
const footerPrimaryBtn =
"inline-flex h-9 select-none items-center justify-center rounded-lg bg-primary px-4 text-sm font-medium text-primary-foreground outline-none whitespace-nowrap transition-[color,background-color] duration-(--motion-fast) ease-(--motion-ease) hover:bg-[color-mix(in_oklab,var(--color-primary)_88%,transparent)] focus-visible:ring-[3px] focus-visible:ring-ring/50"
const solidBackdrop = "bg-[color-mix(in_oklab,var(--color-foreground)_50%,transparent)]"
/* Varsayilan govde: children + dolgu paragraflari. */
function defaultBody(children: React.ReactNode) {
return (
<div className="space-y-4 px-6 py-5 text-sm text-muted-foreground">
{children ? <div className="text-foreground">{children}</div> : null}
{filler.map((line, i) => (
<p key={i}>{line}</p>
))}
</div>
)
}
interface ShellProps {
props: SheetProps
/** Baslik bandini varyanta gore cizer. */
renderHeader: (title: React.ReactNode) => React.ReactNode
/** When true the header stays sticky top-0 inside the scroll container. */
stickyHeader?: boolean
/** A fixed action footer at the bottom. */
renderFooter?: () => React.ReactNode
/** Govde icerigi (varsayilan defaultBody). */
renderBody?: (children: React.ReactNode) => React.ReactNode
}
function SheetShell({
props,
renderHeader,
stickyHeader,
renderFooter,
renderBody = defaultBody,
}: ShellProps) {
const { size = "md", trigger, title, children, className } = props
const reduce = useReducedMotion()
const [isOpen, setOpen] = useControllableOpen(
props.open,
props.defaultOpen,
props.onOpenChange
)
const panelRef = React.useRef<HTMLDivElement>(null)
React.useEffect(() => {
if (!isOpen) return
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape") setOpen(false)
}
window.addEventListener("keydown", onKey)
return () => window.removeEventListener("keydown", onKey)
}, [isOpen, setOpen])
/* This family uses only the right edge; the slideOffset mechanism is preserved. */
const edge: Edge = "right"
const sizeClass = cn("h-full", widthSize[size])
const enter = slideOffset(edge)
const headerNode = title ? renderHeader(title) : null
const bodyInner = renderBody(children)
const footerNode = renderFooter?.()
return (
<div data-slot="styled-sheet" className="inline-flex">
{/* The ARIA state lives on the REAL trigger. There used to be a
span role="button" tabIndex={-1} wrapper, which produced TWO buttons
in the AX tree: one carrying the state (not focusable) and one that
took focus (stateless). A screen-reader user never heard "has dialog"
or "expanded" - measured with the CDP AX tree. */}
{React.isValidElement<React.ButtonHTMLAttributes<HTMLButtonElement>>(trigger) ? (
React.cloneElement(trigger, {
"aria-haspopup": "dialog",
"aria-expanded": isOpen,
onClick: (event: React.MouseEvent<HTMLButtonElement>) => {
trigger.props.onClick?.(event)
setOpen(true)
},
})
) : (
<button
type="button"
aria-haspopup="dialog"
aria-expanded={isOpen}
onClick={() => setOpen(true)}
className={triggerBtn}
>
{trigger ?? "Open"}
</button>
)}
<AnimatePresence>
{isOpen ? (
<div className="fixed inset-0 z-50">
<motion.div
data-slot="styled-sheet-backdrop"
onClick={() => setOpen(false)}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: reduce ? 0 : 0.2, ease: [0.4, 0, 0.2, 1] }}
className={cn("absolute inset-0", solidBackdrop)}
/>
<motion.div
ref={panelRef}
data-slot="styled-sheet-panel"
role="dialog"
aria-modal="true"
tabIndex={-1}
onAnimationComplete={() => panelRef.current?.focus()}
initial={reduce ? { opacity: 0 } : enter}
animate={reduce ? { opacity: 1 } : { x: 0, y: 0 }}
exit={reduce ? { opacity: 0 } : enter}
transition={
reduce
? { duration: 0 }
: { type: "spring", stiffness: 320, damping: 34 }
}
className={cn(
"fixed flex flex-col overflow-hidden border-l border-border bg-card text-card-foreground shadow-lg outline-none",
edgeAnchor[edge],
sizeClass,
className
)}
>
<button
type="button"
onClick={() => setOpen(false)}
aria-label="Close"
className={closeBtn}
>
<X />
</button>
{stickyHeader ? (
<div className="min-h-0 flex-1 overflow-y-auto">
{headerNode}
{bodyInner}
</div>
) : (
<>
{headerNode}
<div className="min-h-0 flex-1 overflow-y-auto">{bodyInner}</div>
{footerNode}
</>
)}
</motion.div>
</div>
) : null}
</AnimatePresence>
</div>
)
}
/* Title: ustte sade baslik bandi + border-b, govde altta kayar. */
export function TitleSheet(props: SheetProps) {
return (
<SheetShell
props={props}
renderHeader={(title) => (
<div
data-slot="styled-sheet-header"
className="border-b border-border px-6 py-4 pr-12 text-base font-semibold text-foreground"
>
{title}
</div>
)}
/>
)
}
/* Sticky: long scrollable content, the header stays sticky top-0 and flush
with the token (card) background. */
export function StickySheet(props: SheetProps) {
return (
<SheetShell
props={props}
stickyHeader
renderHeader={(title) => (
<div
data-slot="styled-sheet-header"
className="sticky top-0 z-10 border-b border-border bg-card px-6 py-4 pr-12 text-base font-semibold text-foreground"
>
{title}
</div>
)}
/>
)
}
/* Footer: a fixed action footer at the bottom plus border-t; the body scrolls
in the middle. */
export function FooterSheet(props: SheetProps) {
return (
<SheetShell
props={props}
renderHeader={(title) => (
<div
data-slot="styled-sheet-header"
className="border-b border-border px-6 py-4 pr-12 text-base font-semibold text-foreground"
>
{title}
</div>
)}
renderFooter={() => (
<div
data-slot="styled-sheet-footer"
className="flex items-center justify-end gap-2 border-t border-border px-6 py-4"
>
<button type="button" className={footerGhostBtn}>
Cancel
</button>
<button type="button" className={footerPrimaryBtn}>
Save changes
</button>
</div>
)}
/>
)
}
/* Divider: baslik bandi + govdede bolum ayraclari (border-t). */
export function DividerSheet(props: SheetProps) {
return (
<SheetShell
props={props}
renderHeader={(title) => (
<div
data-slot="styled-sheet-header"
className="border-b border-border px-6 py-4 pr-12 text-base font-semibold text-foreground"
>
{title}
</div>
)}
renderBody={(children) => (
<div className="text-sm text-muted-foreground">
{children ? (
<section className="px-6 py-5 text-foreground">{children}</section>
) : null}
{dividerSections.map((section, i) => (
<section
key={section.heading}
className={cn(
"px-6 py-5",
(children || i > 0) && "border-t border-border"
)}
>
<h3 className="mb-1 text-sm font-semibold text-foreground">
{section.heading}
</h3>
<p>{section.body}</p>
</section>
))}
</div>
)}
/>
)
}
/* Accent: baslik bandinin ustunde token accent seridi (bg-primary). */
export function AccentSheet(props: SheetProps) {
return (
<SheetShell
props={props}
renderHeader={(title) => (
<div data-slot="styled-sheet-header" className="border-b border-border">
<div className="h-1 w-full bg-primary" aria-hidden />
<div className="px-6 py-4 pr-12 text-base font-semibold text-foreground">
{title}
</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.
Title
A plain title band at the top with a bottom border.
import { TitleSheet } from "@/components/ui/sheet-header"
<TitleSheet title="Panel title">A self-contained side panel. Click the backdrop or press Escape to close.</TitleSheet>Sticky
Long scrollable content with a header pinned sticky to the top.
import { StickySheet } from "@/components/ui/sheet-header"
<StickySheet title="Panel title">A self-contained side panel. Click the backdrop or press Escape to close.</StickySheet>Footer
A sticky action footer anchored at the bottom with a top border.
import { FooterSheet } from "@/components/ui/sheet-header"
<FooterSheet title="Panel title">A self-contained side panel. Click the backdrop or press Escape to close.</FooterSheet>Divider
A title band plus token dividers between body sections.
import { DividerSheet } from "@/components/ui/sheet-header"
<DividerSheet title="Panel title">A self-contained side panel. Click the backdrop or press Escape to close.</DividerSheet>Accent
A token accent strip above the header title.
import { AccentSheet } from "@/components/ui/sheet-header"
<AccentSheet title="Panel title">A self-contained side panel. Click the backdrop or press Escape to close.</AccentSheet>ai2 Header sheets: 5 styled variations on the token system
The ai2 Header sheets are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around right-edge sheets that vary the header and footer banding. 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: framer-motion slides the panel in from the right edge; the backdrop fades. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the slide is skipped and the panel fades or shows instantly.
What is in the ai2 Header sheets?
5 exports in one file: Title, Sticky, Footer, Divider and Accent. 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: framer-motion slides the panel in from the right edge; the backdrop fades.
- Reduced-motion aware: Under prefers-reduced-motion, the slide is skipped and the panel fades or shows 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 Header sheets 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.