Blur drawers
Five bottom-edge drawers that keep an opaque panel and vary only the backdrop: a soft blur, a heavy blur, a dark scrim, a primary tint and a top-to-bottom gradient. Each is self-contained (no radix or vaul), 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/drawer-blurDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/drawer-blur.tsx"use client"
import * as React from "react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { X } from "lucide-react"
import { cn } from "@/lib/utils"
/* Blur drawer family: 5 decorative bottom drawers. The panel always stays
CLEAR/opaque (bg-card) - unlike the frosted Glass PANEL in essentials. The whole
difference is on the BACKDROP: each variant carries a different scrim + blur
technique (light blur, strong blur, dark scrim, primary tint, a top-to-bottom
gradient). They all slide up from the bottom edge. Self-contained - no radix, no
vaul, no portal. A fixed inset-0 backdrop + a fixed panel pinned to the bottom
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"
const panelHeight: Record<StyledSize, string> = {
sm: "h-[35vh]",
md: "h-[50vh]",
lg: "h-[68vh]",
xl: "h-[82vh]",
}
interface DrawerProps {
size?: StyledSize
trigger?: React.ReactNode
title?: React.ReactNode
children?: React.ReactNode
className?: string
open?: boolean
defaultOpen?: boolean
onOpenChange?: (o: boolean) => void
}
/* Controlled/uncontrolled acik durum yonetimi. */
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
}
interface ShellProps extends DrawerProps {
backdropClassName: string
}
/* Shared shell: trigger plus an AnimatePresence backdrop plus an opaque panel pinned to the bottom edge. The bottom-edge slide and close mechanism is kept from the Essentials drawer. */
function DrawerShell({
backdropClassName,
size = "md",
trigger,
title,
children,
className,
open,
defaultOpen,
onOpenChange,
}: ShellProps) {
const reduce = useReducedMotion()
const [isOpen, setOpen] = useControllableOpen(open, defaultOpen, 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)
const id = window.requestAnimationFrame(() => panelRef.current?.focus())
return () => {
window.removeEventListener("keydown", onKey)
window.cancelAnimationFrame(id)
}
}, [isOpen, setOpen])
/* Bottom edge: the panel slides up from below (y 100%). No slide under reduced. */
const enter = { y: "100%" }
return (
<div data-slot="styled-drawer-trigger" 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="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"
>
{trigger ?? "Open"}
</button>
)}
<AnimatePresence>
{isOpen ? (
<div className="fixed inset-0 z-50">
<motion.div
data-slot="styled-drawer-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", backdropClassName)}
/>
<motion.div
ref={panelRef}
data-slot="styled-drawer"
role="dialog"
aria-modal="true"
tabIndex={-1}
initial={reduce ? { opacity: 0 } : enter}
animate={reduce ? { opacity: 1 } : { y: 0 }}
exit={reduce ? { opacity: 0 } : enter}
transition={
reduce
? { duration: 0 }
: { type: "spring", stiffness: 320, damping: 34 }
}
className={cn(
"fixed inset-x-0 bottom-0 flex flex-col rounded-t-2xl border-t border-border bg-card text-card-foreground shadow-lg outline-none",
panelHeight[size],
className
)}
>
{/* Top handle bar: the identity of a bottom drawer (same as Essentials). */}
<div className="flex w-full shrink-0 items-center justify-center pt-3 pb-1">
<span className="h-1.5 w-12 rounded-full bg-[color-mix(in_oklab,var(--color-foreground)_25%,transparent)]" />
</div>
<div className="flex items-start justify-between gap-4 px-6 pt-1 pb-2">
{title ? (
<h2
data-slot="styled-drawer-title"
className="text-base font-semibold text-foreground"
>
{title}
</h2>
) : (
<span />
)}
<button
type="button"
onClick={() => setOpen(false)}
aria-label="Close"
className="relative -m-1 inline-flex size-7 shrink-0 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 after:absolute after:-inset-2 [&_i]:text-base [&_i]:leading-none [&_svg]:size-4"
>
<X />
</button>
</div>
<div className="min-h-0 flex-1 overflow-y-auto px-6 pb-6 text-sm text-muted-foreground">
{children}
</div>
</motion.div>
</div>
) : null}
</AnimatePresence>
</div>
)
}
/* SoftBlur: hafif backdrop-blur-sm + dusuk scrim. */
export function SoftBlurDrawer(props: DrawerProps) {
return (
<DrawerShell
{...props}
backdropClassName="bg-[color-mix(in_oklab,var(--color-foreground)_28%,transparent)] supports-[backdrop-filter]:backdrop-blur-sm"
/>
)
}
/* HeavyBlur: guclu backdrop-blur-xl + orta scrim. */
export function HeavyBlurDrawer(props: DrawerProps) {
return (
<DrawerShell
{...props}
backdropClassName="bg-[color-mix(in_oklab,var(--color-foreground)_36%,transparent)] supports-[backdrop-filter]:backdrop-blur-xl"
/>
)
}
/* DarkBlur: koyu scrim (foreground yuksek yuzde) + orta blur. */
export function DarkBlurDrawer(props: DrawerProps) {
return (
<DrawerShell
{...props}
backdropClassName="bg-[color-mix(in_oklab,var(--color-foreground)_70%,transparent)] supports-[backdrop-filter]:backdrop-blur-md"
/>
)
}
/* TintBlur: primary tonlu transluent scrim + blur. */
export function TintBlurDrawer(props: DrawerProps) {
return (
<DrawerShell
{...props}
backdropClassName="bg-[color-mix(in_oklab,var(--color-primary)_35%,transparent)] supports-[backdrop-filter]:backdrop-blur-md"
/>
)
}
/* GradientBlur: ustten alta gradient scrim + blur. */
export function GradientBlurDrawer(props: DrawerProps) {
return (
<DrawerShell
{...props}
backdropClassName="bg-gradient-to-b from-[color-mix(in_oklab,var(--color-foreground)_20%,transparent)] to-[color-mix(in_oklab,var(--color-foreground)_60%,transparent)] supports-[backdrop-filter]:backdrop-blur-md"
/>
)
}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.
Soft
A light backdrop-blur with a low scrim.
import { SoftBlurDrawer } from "@/components/ui/drawer-blur"
<SoftBlurDrawer title="Drawer title">A self-contained bottom drawer. Click the backdrop or press Escape to close.</SoftBlurDrawer>Heavy
A strong backdrop-blur that fully diffuses the page.
import { HeavyBlurDrawer } from "@/components/ui/drawer-blur"
<HeavyBlurDrawer title="Drawer title">A self-contained bottom drawer. Click the backdrop or press Escape to close.</HeavyBlurDrawer>Dark
A dark scrim with a medium blur.
import { DarkBlurDrawer } from "@/components/ui/drawer-blur"
<DarkBlurDrawer title="Drawer title">A self-contained bottom drawer. Click the backdrop or press Escape to close.</DarkBlurDrawer>Tint
A primary-tinted translucent scrim with blur.
import { TintBlurDrawer } from "@/components/ui/drawer-blur"
<TintBlurDrawer title="Drawer title">A self-contained bottom drawer. Click the backdrop or press Escape to close.</TintBlurDrawer>Gradient
A top-to-bottom gradient scrim with blur.
import { GradientBlurDrawer } from "@/components/ui/drawer-blur"
<GradientBlurDrawer title="Drawer title">A self-contained bottom drawer. Click the backdrop or press Escape to close.</GradientBlurDrawer>ai2 Blur drawers: 5 styled variations on the token system
The ai2 Blur drawers are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around bottom-edge drawers with an opaque panel and a blurred backdrop. 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 drawer up from the bottom 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 drawer fades or shows instantly.
What is in the ai2 Blur drawers?
5 exports in one file: Soft, Heavy, Dark, Tint and Gradient. 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 drawer up from the bottom edge; the backdrop fades.
- Reduced-motion aware: Under prefers-reduced-motion, the slide is skipped and the drawer 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 Blur drawers 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.