Frost Button
A frosted-glass button for React, built on the DuskUI Button with Motion and Tailwind CSS. A soft ripple spreads from where you press, an optional faint light sweep runs on hover and focus, and loading states, sizes and every shadcn/ui Button prop keep working.
- Built on Button
- Press ripple
- Light sweep
- Loading state
- prefers-reduced-motion
import { ArrowRight } from "lucide-react";
import { FrostButton } from "@/components/dusk/glass/frost-button";
import { GlassBackdrop } from "@/components/demos/glass-card/glass-backdrop";
export default function FrostButtonDemo() {
return (
<>
<GlassBackdrop />
<div className="relative flex flex-wrap items-center justify-center gap-3">
<FrostButton size="lg">
Get started
<ArrowRight />
</FrostButton>
<FrostButton size="lg" tone="primary">
Upgrade
</FrostButton>
<FrostButton size="lg" tone="dark">
Learn more
</FrostButton>
</div>
</>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/frost-button.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/glass/frost-button.tsx.frost-button.tsx "use client"; import * as React from "react"; import { motion, useAnimate, useReducedMotion } from "motion/react"; import { Button, type ButtonProps } from "@/components/ui/button"; import { cn } from "@/lib/utils"; const tones = { clear: [ "border-white/25 text-white", "bg-zinc-900/85 supports-[backdrop-filter]:bg-white/10", "hover:bg-zinc-800/90 supports-[backdrop-filter]:hover:bg-white/[0.16]", ], dark: [ "border-white/12 text-white", "bg-zinc-950/90 supports-[backdrop-filter]:bg-black/30", "hover:bg-zinc-900/90 supports-[backdrop-filter]:hover:bg-black/40", ], primary: [ "border-primary/35 text-white", "bg-[color-mix(in_oklab,var(--primary)_30%,var(--background))] supports-[backdrop-filter]:bg-primary/20", "hover:bg-[color-mix(in_oklab,var(--primary)_38%,var(--background))] supports-[backdrop-filter]:hover:bg-primary/[0.28]", ], } as const; type Ripple = { id: number; x: number; y: number; size: number }; export interface FrostButtonProps extends Omit<ButtonProps, "variant"> { /** Glass color. `clear` is white frost, `dark` smoked glass, `primary` a mint-tinted pane. */ tone?: keyof typeof tones; /** Press and hover effects: a faint light sweep on hover/focus, a ripple on press (default), or both. */ effect?: "sweep" | "ripple" | "both" | "none"; } /** * A frosted-glass button built on the DuskUI Button, so `loading`, * `loadingText`, sizes and focus styles all keep working. * * A ripple spreads from the press point (from the center for keyboard * presses); optionally a faint band of light sweeps across on hover / focus. With reduced * motion the sweep is skipped and the ripple becomes a soft flash. * Effects are not rendered with `asChild`, since Slot needs a single child. */ export function FrostButton({ tone = "clear", effect = "ripple", size, asChild, loading, disabled, className, children, onPointerEnter, onPointerDown, onFocus, onClick, ...props }: FrostButtonProps) { const reduceMotion = useReducedMotion(); const [sweepScope, animate] = useAnimate<HTMLSpanElement>(); const [ripples, setRipples] = React.useState<Ripple[]>([]); const nextId = React.useRef(0); const sweeps = effect === "sweep" || effect === "both"; const ripplesOn = effect === "ripple" || effect === "both"; const inactive = loading || disabled; const sweep = () => { if (!sweeps || reduceMotion || inactive || !sweepScope.current) return; animate( sweepScope.current, { x: ["-120%", "120%"] }, { duration: 0.75, ease: [0.4, 0, 0.2, 1] } ); }; const addRipple = (target: HTMLElement, clientX?: number, clientY?: number) => { if (!ripplesOn || inactive) return; const rect = target.getBoundingClientRect(); const x = clientX === undefined ? rect.width / 2 : clientX - rect.left; const y = clientY === undefined ? rect.height / 2 : clientY - rect.top; // Big enough to cover the farthest corner from the press point. const size = 2 * Math.hypot(Math.max(x, rect.width - x), Math.max(y, rect.height - y)); const id = nextId.current++; setRipples((list) => [...list, { id, x, y, size }]); }; const effects = !asChild && effect !== "none" ? ( <span aria-hidden className="pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit]" > {sweeps && ( <span ref={sweepScope} className="absolute inset-y-0 left-0 w-full bg-[linear-gradient(105deg,transparent_30%,rgb(255_255_255/0.1)_45%,rgb(255_255_255/0.16)_50%,rgb(255_255_255/0.1)_55%,transparent_70%)]" style={{ transform: "translateX(-120%)" }} /> )} {ripples.map((r) => ( <motion.span key={r.id} className="absolute rounded-full bg-white/20" style={{ left: r.x - r.size / 2, top: r.y - r.size / 2, width: r.size, height: r.size }} initial={{ scale: reduceMotion ? 1 : 0, opacity: reduceMotion ? 0.2 : 0.35 }} animate={{ scale: 1, opacity: 0 }} transition={{ scale: { duration: 0.55, ease: [0.2, 0.7, 0.3, 1] }, opacity: { duration: reduceMotion ? 0.35 : 0.7, ease: "easeOut" }, }} onAnimationComplete={() => setRipples((list) => list.filter((item) => item.id !== r.id)) } /> ))} </span> ) : null; return ( <Button // No base variant: the tone classes below provide the whole fill. variant={null} data-variant="frost" size={size} asChild={asChild} loading={loading} disabled={disabled} data-tone={tone} className={cn( "overflow-hidden border font-medium [text-shadow:0_1px_2px_rgb(0_0_0/0.35)]", "supports-[backdrop-filter]:backdrop-blur-md supports-[backdrop-filter]:backdrop-saturate-150", "shadow-[inset_0_1px_0_rgb(255_255_255/0.12),0_1px_2px_rgb(0_0_0/0.3)]", tones[tone], className )} onPointerEnter={(event) => { onPointerEnter?.(event); if (event.pointerType !== "touch") sweep(); }} onFocus={(event) => { onFocus?.(event); if (event.currentTarget.matches(":focus-visible")) sweep(); }} onPointerDown={(event) => { onPointerDown?.(event); addRipple(event.currentTarget, event.clientX, event.clientY); }} onClick={(event) => { // detail === 0 means the click came from the keyboard (Enter / Space). if (event.detail === 0) addRipple(event.currentTarget); onClick?.(event); }} {...props} > {asChild ? ( children ) : ( <> {effects} {children} </> )} </Button> ); }
Builds on the DuskUI Button; the CLI installs it automatically. Installing by hand? Add components/ui/button.tsx from the Button page first.
Usage
import { FrostButton } from "@/components/dusk/glass/frost-button"
export function HeroActions() {
return (
<FrostButton size="lg" tone="primary" className="rounded-full">
Start building
</FrostButton>
)
}Examples
Loading
loading and loadingText come straight from the base Button: the content crossfades to a spinner without changing width, and the button stays focusable.
"use client";
import * as React from "react";
import { CloudUpload } from "lucide-react";
import { FrostButton } from "@/components/dusk/glass/frost-button";
import { GlassBackdrop } from "@/components/demos/glass-card/glass-backdrop";
export default function FrostButtonLoading() {
const [loading, setLoading] = React.useState(false);
return (
<>
<GlassBackdrop />
<FrostButton
size="lg"
tone="primary"
className="min-w-40"
loading={loading}
loadingText="Publishing…"
onClick={() => {
setLoading(true);
setTimeout(() => setLoading(false), 2000);
}}
>
<CloudUpload />
Publish
</FrostButton>
</>
);
}Effects & icon buttons
Choose the interaction with effect: sweep, ripple, both or none. Icon sizes work too — give them an aria-label.
import { Heart, Play, Share2 } from "lucide-react";
import { FrostButton } from "@/components/dusk/glass/frost-button";
import { GlassBackdrop } from "@/components/demos/glass-card/glass-backdrop";
export default function FrostButtonEffects() {
return (
<>
<GlassBackdrop />
<div className="relative flex flex-col items-center gap-5">
<div className="flex flex-wrap justify-center gap-3">
<FrostButton effect="sweep">Sweep</FrostButton>
<FrostButton>Ripple</FrostButton>
<FrostButton effect="none">None</FrostButton>
</div>
<div className="flex gap-3">
<FrostButton size="icon-lg" className="rounded-full" aria-label="Play">
<Play />
</FrostButton>
<FrostButton size="icon-lg" tone="primary" className="rounded-full" aria-label="Like">
<Heart />
</FrostButton>
<FrostButton size="icon-lg" tone="dark" className="rounded-full" aria-label="Share">
<Share2 />
</FrostButton>
</div>
</div>
</>
);
}API Reference
Accepts every DuskUI Button prop except variant — including size, loading, loadingText and asChild (effects are skipped with asChild, since Slot needs a single child).
| Prop | Type | Default | Description |
|---|---|---|---|
| tone | "clear" | "dark" | "primary" | "clear" | White frost, smoked glass or a primary-tinted pane. |
| effect | "sweep" | "ripple" | "both" | "none" | "ripple" | Ripple on press, light sweep on hover/focus, both or neither. |
| loading | boolean | false | Spinner without a width change; clicks are blocked but focus is kept. |
Accessibility
- It's the DuskUI Button underneath: a native <button> with focus-visible ring, aria-busy and aria-disabled while loading.
- Keyboard presses (Enter / Space) get the ripple from the center, and keyboard focus triggers the light sweep when it is on.
- White text gets a soft text-shadow, and browsers without backdrop-filter get an opaque fill, so the label stays readable on any background.
- With reduced motion the sweep is skipped and the ripple becomes a soft flash.