Settings panel
Settings with a save bar that appears on change.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/, installsradix-ui@base-ui/reactand the colour tokens go into your CSS. This is the Radix build. Drop --radix for Base UI.This is the Base UI build, the default. Want Radix? Add --radix.$ pnpm dlx asta-ui@latest add settings-panel --radixOr install the package
Don’t want the file? Import from
asta-uiasta-ui/baseand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-ui radix-ui @base-ui/reactimport { SettingsPanel } from "asta-ui";import { SettingsPanel } from "asta-ui/base";Or copy it by hand
Install
radix-ui@base-ui/react, then copy these files. Keep the paths, or fix the@/imports. Then add the tokens fromglobals.css."use client"; import { forwardRef, useEffect, useId, useImperativeHandle, useRef, useState, type ReactNode } from "react"; import { Button } from "@/components/kit/button"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); const RING = "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent)]"; const EASE = "ease-[cubic-bezier(.16,1,.3,1)]"; export interface Settings { name: string; email: string; notify: { product: boolean; mentions: boolean; digest: boolean }; theme: "light" | "dark" | "system"; language: string; } /* ---------- small private pieces ---------- */ function Toggle({ checked, onChange, label, hint }: { checked: boolean; onChange: (v: boolean) => void; label: string; hint?: string }) { const id = useId(); return ( <div className="flex items-center justify-between gap-4 py-2.5"> <label htmlFor={id} className="min-w-0 cursor-pointer"> <span className="block text-[14px] text-ink">{label}</span> {hint && <span className="mt-0.5 block text-[12.5px] leading-snug text-mute">{hint}</span>} </label> <button id={id} type="button" role="switch" aria-checked={checked} onClick={() => onChange(!checked)} className={cx( "group relative h-6 w-10 shrink-0 rounded-full outline-none transition-colors duration-300 focus-visible:ring-2 focus-visible:ring-brand/50 focus-visible:ring-offset-2 focus-visible:ring-offset-paper", checked ? "bg-brand" : "bg-[color-mix(in_srgb,var(--color-ink)_16%,transparent)]", )} > <span className={cx( // perf-ok: the thumb stretches a few px on press, a tiny element that only moves on interaction. "absolute left-0.5 top-0.5 h-5 w-5 rounded-full bg-white shadow-[0_1px_3px_rgb(0_0_0/0.25)] transition-[transform,width] duration-300 group-active:w-6", EASE, checked ? "translate-x-4 group-active:translate-x-3" : "translate-x-0", )} /> </button> </div> ); } const THEMES: { value: Settings["theme"]; label: string; swatch: string }[] = [ { value: "light", label: "Light", swatch: "bg-[#fcfcfb]" }, { value: "dark", label: "Dark", swatch: "bg-[#151516]" }, { value: "system", label: "System", swatch: "bg-[linear-gradient(135deg,#fcfcfb_50%,#151516_50%)]" }, ]; function ThemePicker({ value, onChange }: { value: Settings["theme"]; onChange: (v: Settings["theme"]) => void }) { const refs = useRef<(HTMLButtonElement | null)[]>([]); const move = (d: number) => { const i = (THEMES.findIndex((t) => t.value === value) + d + THEMES.length) % THEMES.length; onChange(THEMES[i].value); refs.current[i]?.focus(); }; return ( <div role="radiogroup" aria-label="Theme" className="grid grid-cols-3 gap-2"> {THEMES.map((t, i) => { const on = t.value === value; return ( <button key={t.value} ref={(el) => { refs.current[i] = el; }} type="button" role="radio" aria-checked={on} tabIndex={on ? 0 : -1} onClick={() => onChange(t.value)} onKeyDown={(e) => { if (e.key === "ArrowRight" || e.key === "ArrowDown") move(1); else if (e.key === "ArrowLeft" || e.key === "ArrowUp") move(-1); else return; e.preventDefault(); }} className={cx( "flex flex-col items-start gap-2 rounded-[10px] p-2 text-left outline-none transition-shadow duration-300 focus-visible:ring-2 focus-visible:ring-brand/50", on ? "shadow-[inset_0_0_0_2px_var(--color-brand)]" : `${RING} hover:shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_26%,transparent)]`, )} > <span className={cx("h-10 w-full rounded-lg shadow-[inset_0_0_0_1px_rgb(0_0_0/0.08)]", t.swatch)} /> <span className="flex w-full items-center justify-between px-0.5 text-[13px] text-ink"> {t.label} <span className={cx("h-3.5 w-3.5 rounded-full transition-[background-color,box-shadow] duration-300", on ? "bg-brand shadow-[inset_0_0_0_3.5px_var(--color-brand),inset_0_0_0_6px_white]" : RING)} /> </span> </button> ); })} </div> ); } function Section({ title, children }: { title: string; children: ReactNode }) { return ( <section className="py-5 first:pt-0"> <h4 className="mb-3 text-[12px] font-medium uppercase tracking-[0.06em] text-mute">{title}</h4> {children} </section> ); } const inputCls = cx("h-10 w-full rounded-lg bg-paper px-3 text-[16px] sm:text-[14px] text-ink outline-none transition-shadow placeholder:text-mute focus-visible:ring-2 focus-visible:ring-brand/50", RING); /* ---------- the panel ---------- */ export interface SettingsPanelHandle { /** Returns false (and nudges the save bar) when there are unsaved changes. */ requestLeave: () => boolean; } export interface SettingsPanelProps { initial: Settings; /** Persist the settings; the bar shows a spinner until it resolves. */ onSave?: (s: Settings) => Promise<void>; languages?: string[]; className?: string; } /** * A settings form whose save bar slides up as soon as anything differs from the saved values. Reset puts * everything back; Save shows progress, then "Saved", then the bar slides away. `requestLeave()` (via ref) * shakes the bar when there are unsaved changes. */ export const SettingsPanel = forwardRef<SettingsPanelHandle, SettingsPanelProps>(function SettingsPanel( { initial, onSave, languages = ["English", "Bahasa Indonesia", "Deutsch", "日本語"], className }, ref, ) { const [saved, setSaved] = useState(initial); const [draft, setDraft] = useState(initial); const [status, setStatus] = useState<"idle" | "saving" | "saved">("idle"); const bar = useRef<HTMLDivElement>(null); const nameId = useId(); const emailId = useId(); const langId = useId(); const dirty = JSON.stringify(saved) !== JSON.stringify(draft); const showBar = dirty || status !== "idle"; const dirtyRef = useRef(dirty); useEffect(() => { dirtyRef.current = dirty; }, [dirty]); const nudge = () => { if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return; bar.current?.animate( [{ transform: "none" }, { transform: "translateX(-8px)" }, { transform: "translateX(7px)" }, { transform: "translateX(-4px)" }, { transform: "translateX(2px)" }, { transform: "none" }], { duration: 450, easing: "cubic-bezier(.16,1,.3,1)" }, ); }; useImperativeHandle(ref, () => ({ requestLeave: () => { if (dirtyRef.current) nudge(); return !dirtyRef.current; }, })); useEffect(() => { if (status !== "saved") return; const t = setTimeout(() => setStatus("idle"), 1400); return () => clearTimeout(t); }, [status]); const set = <K extends keyof Settings>(k: K, v: Settings[K]) => { setDraft((d) => ({ ...d, [k]: v })); if (status === "saved") setStatus("idle"); }; const save = async () => { setStatus("saving"); await (onSave?.(draft) ?? new Promise((r) => setTimeout(r, 900))); setSaved(draft); setStatus("saved"); }; return ( <div className={cx( "relative w-full max-w-[520px] overflow-hidden rounded-xl bg-paper shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent),0_18px_40px_-24px_rgb(0_0_0/0.3)]", className, )} > <form onSubmit={(e) => { e.preventDefault(); if (dirty) save(); }} > <div className="max-h-[440px] overflow-y-auto px-5 pb-24 pt-5 sm:px-6 [&>section+section]:shadow-[inset_0_1px_0_color-mix(in_srgb,var(--color-ink)_7%,transparent)]"> <Section title="Profile"> <div className="grid gap-3 sm:grid-cols-2"> <div className="flex flex-col gap-1.5"> <label htmlFor={nameId} className="text-[13px] font-medium text-ink"> Display name </label> <input id={nameId} name="name" value={draft.name} onChange={(e) => set("name", e.target.value)} className={inputCls} autoComplete="name" /> </div> <div className="flex flex-col gap-1.5"> <label htmlFor={emailId} className="text-[13px] font-medium text-ink"> Email </label> <input id={emailId} name="email" type="email" value={draft.email} onChange={(e) => set("email", e.target.value)} className={inputCls} autoComplete="email" inputMode="email" autoCapitalize="none" spellCheck={false} /> </div> </div> </Section> <Section title="Notifications"> <Toggle label="Product updates" hint="New features, once a month." checked={draft.notify.product} onChange={(v) => set("notify", { ...draft.notify, product: v })} /> <Toggle label="Mentions" hint="When someone tags you in a comment." checked={draft.notify.mentions} onChange={(v) => set("notify", { ...draft.notify, mentions: v })} /> <Toggle label="Weekly digest" checked={draft.notify.digest} onChange={(v) => set("notify", { ...draft.notify, digest: v })} /> </Section> <Section title="Appearance"> <ThemePicker value={draft.theme} onChange={(v) => set("theme", v)} /> <div className="mt-4 flex items-center justify-between gap-4"> <label htmlFor={langId} className="text-[14px] text-ink"> Language </label> <div className="relative"> <select id={langId} name="language" value={draft.language} onChange={(e) => set("language", e.target.value)} className={cx(inputCls, "w-auto cursor-pointer appearance-none pr-9")} > {languages.map((l) => ( <option key={l}>{l}</option> ))} </select> <svg viewBox="0 0 24 24" className="pointer-events-none absolute right-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-mute" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m6 9.5 6 6 6-6" /> </svg> </div> </div> </Section> </div> {/* Save bar: slides up while there are changes. */} <div className={cx( "pointer-events-none absolute inset-x-3 bottom-3 transition-[transform,opacity] duration-500", EASE, showBar ? "translate-y-0 opacity-100" : "translate-y-[calc(100%+16px)] opacity-0", )} aria-hidden={!showBar} > <div ref={bar} role="region" aria-label="Unsaved changes" className="pointer-events-auto flex items-center gap-2 rounded-[10px] bg-ink py-2 pl-4 pr-2 text-paper shadow-[0_12px_30px_-10px_rgb(0_0_0/0.5)]" > <span className="flex min-w-0 flex-1 items-center gap-2 text-[13.5px]" aria-live="polite"> {status === "saved" ? ( <> <svg viewBox="0 0 24 24" className="h-4 w-4 shrink-0 text-paper" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m5 12.5 4.5 4.5L19 7.5" /> </svg> Saved </> ) : ( <> <span className="h-1.5 w-1.5 shrink-0 rounded-full bg-brand" /> <span className="truncate">Unsaved changes</span> </> )} </span> {status !== "saved" && ( <> <Button variant="ghost" size="sm" tabIndex={showBar ? 0 : -1} disabled={status === "saving"} onClick={() => setDraft(saved)} className="text-paper/70 hover:bg-paper/10 hover:text-paper" > Reset </Button> <Button type="submit" variant="accent" size="sm" tabIndex={showBar ? 0 : -1} loading={status === "saving"}> Save </Button> </> )} </div> </div> </form> </div> ); }); export default SettingsPanel;"use client"; import { forwardRef, useEffect, useId, useImperativeHandle, useRef, useState, type ReactNode } from "react"; import { Button } from "@/components/kit/base/button"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); const RING = "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent)]"; const EASE = "ease-[cubic-bezier(.16,1,.3,1)]"; export interface Settings { name: string; email: string; notify: { product: boolean; mentions: boolean; digest: boolean }; theme: "light" | "dark" | "system"; language: string; } /* ---------- small private pieces ---------- */ function Toggle({ checked, onChange, label, hint }: { checked: boolean; onChange: (v: boolean) => void; label: string; hint?: string }) { const id = useId(); return ( <div className="flex items-center justify-between gap-4 py-2.5"> <label htmlFor={id} className="min-w-0 cursor-pointer"> <span className="block text-[14px] text-ink">{label}</span> {hint && <span className="mt-0.5 block text-[12.5px] leading-snug text-mute">{hint}</span>} </label> <button id={id} type="button" role="switch" aria-checked={checked} onClick={() => onChange(!checked)} className={cx( "group relative h-6 w-10 shrink-0 rounded-full outline-none transition-colors duration-300 focus-visible:ring-2 focus-visible:ring-brand/50 focus-visible:ring-offset-2 focus-visible:ring-offset-paper", checked ? "bg-brand" : "bg-[color-mix(in_srgb,var(--color-ink)_16%,transparent)]", )} > <span className={cx( // perf-ok: the thumb stretches a few px on press, a tiny element that only moves on interaction. "absolute left-0.5 top-0.5 h-5 w-5 rounded-full bg-white shadow-[0_1px_3px_rgb(0_0_0/0.25)] transition-[transform,width] duration-300 group-active:w-6", EASE, checked ? "translate-x-4 group-active:translate-x-3" : "translate-x-0", )} /> </button> </div> ); } const THEMES: { value: Settings["theme"]; label: string; swatch: string }[] = [ { value: "light", label: "Light", swatch: "bg-[#fcfcfb]" }, { value: "dark", label: "Dark", swatch: "bg-[#151516]" }, { value: "system", label: "System", swatch: "bg-[linear-gradient(135deg,#fcfcfb_50%,#151516_50%)]" }, ]; function ThemePicker({ value, onChange }: { value: Settings["theme"]; onChange: (v: Settings["theme"]) => void }) { const refs = useRef<(HTMLButtonElement | null)[]>([]); const move = (d: number) => { const i = (THEMES.findIndex((t) => t.value === value) + d + THEMES.length) % THEMES.length; onChange(THEMES[i].value); refs.current[i]?.focus(); }; return ( <div role="radiogroup" aria-label="Theme" className="grid grid-cols-3 gap-2"> {THEMES.map((t, i) => { const on = t.value === value; return ( <button key={t.value} ref={(el) => { refs.current[i] = el; }} type="button" role="radio" aria-checked={on} tabIndex={on ? 0 : -1} onClick={() => onChange(t.value)} onKeyDown={(e) => { if (e.key === "ArrowRight" || e.key === "ArrowDown") move(1); else if (e.key === "ArrowLeft" || e.key === "ArrowUp") move(-1); else return; e.preventDefault(); }} className={cx( "flex flex-col items-start gap-2 rounded-[10px] p-2 text-left outline-none transition-shadow duration-300 focus-visible:ring-2 focus-visible:ring-brand/50", on ? "shadow-[inset_0_0_0_2px_var(--color-brand)]" : `${RING} hover:shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_26%,transparent)]`, )} > <span className={cx("h-10 w-full rounded-lg shadow-[inset_0_0_0_1px_rgb(0_0_0/0.08)]", t.swatch)} /> <span className="flex w-full items-center justify-between px-0.5 text-[13px] text-ink"> {t.label} <span className={cx("h-3.5 w-3.5 rounded-full transition-[background-color,box-shadow] duration-300", on ? "bg-brand shadow-[inset_0_0_0_3.5px_var(--color-brand),inset_0_0_0_6px_white]" : RING)} /> </span> </button> ); })} </div> ); } function Section({ title, children }: { title: string; children: ReactNode }) { return ( <section className="py-5 first:pt-0"> <h4 className="mb-3 text-[12px] font-medium uppercase tracking-[0.06em] text-mute">{title}</h4> {children} </section> ); } const inputCls = cx("h-10 w-full rounded-lg bg-paper px-3 text-[16px] sm:text-[14px] text-ink outline-none transition-shadow placeholder:text-mute focus-visible:ring-2 focus-visible:ring-brand/50", RING); /* ---------- the panel ---------- */ export interface SettingsPanelHandle { /** Returns false (and nudges the save bar) when there are unsaved changes. */ requestLeave: () => boolean; } export interface SettingsPanelProps { initial: Settings; /** Persist the settings; the bar shows a spinner until it resolves. */ onSave?: (s: Settings) => Promise<void>; languages?: string[]; className?: string; } /** * A settings form whose save bar slides up as soon as anything differs from the saved values. Reset puts * everything back; Save shows progress, then "Saved", then the bar slides away. `requestLeave()` (via ref) * shakes the bar when there are unsaved changes. */ export const SettingsPanel = forwardRef<SettingsPanelHandle, SettingsPanelProps>(function SettingsPanel( { initial, onSave, languages = ["English", "Bahasa Indonesia", "Deutsch", "日本語"], className }, ref, ) { const [saved, setSaved] = useState(initial); const [draft, setDraft] = useState(initial); const [status, setStatus] = useState<"idle" | "saving" | "saved">("idle"); const bar = useRef<HTMLDivElement>(null); const nameId = useId(); const emailId = useId(); const langId = useId(); const dirty = JSON.stringify(saved) !== JSON.stringify(draft); const showBar = dirty || status !== "idle"; const dirtyRef = useRef(dirty); useEffect(() => { dirtyRef.current = dirty; }, [dirty]); const nudge = () => { if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return; bar.current?.animate( [{ transform: "none" }, { transform: "translateX(-8px)" }, { transform: "translateX(7px)" }, { transform: "translateX(-4px)" }, { transform: "translateX(2px)" }, { transform: "none" }], { duration: 450, easing: "cubic-bezier(.16,1,.3,1)" }, ); }; useImperativeHandle(ref, () => ({ requestLeave: () => { if (dirtyRef.current) nudge(); return !dirtyRef.current; }, })); useEffect(() => { if (status !== "saved") return; const t = setTimeout(() => setStatus("idle"), 1400); return () => clearTimeout(t); }, [status]); const set = <K extends keyof Settings>(k: K, v: Settings[K]) => { setDraft((d) => ({ ...d, [k]: v })); if (status === "saved") setStatus("idle"); }; const save = async () => { setStatus("saving"); await (onSave?.(draft) ?? new Promise((r) => setTimeout(r, 900))); setSaved(draft); setStatus("saved"); }; return ( <div className={cx( "relative w-full max-w-[520px] overflow-hidden rounded-xl bg-paper shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent),0_18px_40px_-24px_rgb(0_0_0/0.3)]", className, )} > <form onSubmit={(e) => { e.preventDefault(); if (dirty) save(); }} > <div className="max-h-[440px] overflow-y-auto px-5 pb-24 pt-5 sm:px-6 [&>section+section]:shadow-[inset_0_1px_0_color-mix(in_srgb,var(--color-ink)_7%,transparent)]"> <Section title="Profile"> <div className="grid gap-3 sm:grid-cols-2"> <div className="flex flex-col gap-1.5"> <label htmlFor={nameId} className="text-[13px] font-medium text-ink"> Display name </label> <input id={nameId} name="name" value={draft.name} onChange={(e) => set("name", e.target.value)} className={inputCls} autoComplete="name" /> </div> <div className="flex flex-col gap-1.5"> <label htmlFor={emailId} className="text-[13px] font-medium text-ink"> Email </label> <input id={emailId} name="email" type="email" value={draft.email} onChange={(e) => set("email", e.target.value)} className={inputCls} autoComplete="email" inputMode="email" autoCapitalize="none" spellCheck={false} /> </div> </div> </Section> <Section title="Notifications"> <Toggle label="Product updates" hint="New features, once a month." checked={draft.notify.product} onChange={(v) => set("notify", { ...draft.notify, product: v })} /> <Toggle label="Mentions" hint="When someone tags you in a comment." checked={draft.notify.mentions} onChange={(v) => set("notify", { ...draft.notify, mentions: v })} /> <Toggle label="Weekly digest" checked={draft.notify.digest} onChange={(v) => set("notify", { ...draft.notify, digest: v })} /> </Section> <Section title="Appearance"> <ThemePicker value={draft.theme} onChange={(v) => set("theme", v)} /> <div className="mt-4 flex items-center justify-between gap-4"> <label htmlFor={langId} className="text-[14px] text-ink"> Language </label> <div className="relative"> <select id={langId} name="language" value={draft.language} onChange={(e) => set("language", e.target.value)} className={cx(inputCls, "w-auto cursor-pointer appearance-none pr-9")} > {languages.map((l) => ( <option key={l}>{l}</option> ))} </select> <svg viewBox="0 0 24 24" className="pointer-events-none absolute right-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-mute" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m6 9.5 6 6 6-6" /> </svg> </div> </div> </Section> </div> {/* Save bar: slides up while there are changes. */} <div className={cx( "pointer-events-none absolute inset-x-3 bottom-3 transition-[transform,opacity] duration-500", EASE, showBar ? "translate-y-0 opacity-100" : "translate-y-[calc(100%+16px)] opacity-0", )} aria-hidden={!showBar} > <div ref={bar} role="region" aria-label="Unsaved changes" className="pointer-events-auto flex items-center gap-2 rounded-[10px] bg-ink py-2 pl-4 pr-2 text-paper shadow-[0_12px_30px_-10px_rgb(0_0_0/0.5)]" > <span className="flex min-w-0 flex-1 items-center gap-2 text-[13.5px]" aria-live="polite"> {status === "saved" ? ( <> <svg viewBox="0 0 24 24" className="h-4 w-4 shrink-0 text-paper" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m5 12.5 4.5 4.5L19 7.5" /> </svg> Saved </> ) : ( <> <span className="h-1.5 w-1.5 shrink-0 rounded-full bg-brand" /> <span className="truncate">Unsaved changes</span> </> )} </span> {status !== "saved" && ( <> <Button variant="ghost" size="sm" tabIndex={showBar ? 0 : -1} disabled={status === "saving"} onClick={() => setDraft(saved)} className="text-paper/70 hover:bg-paper/10 hover:text-paper" > Reset </Button> <Button type="submit" variant="accent" size="sm" tabIndex={showBar ? 0 : -1} loading={status === "saving"}> Save </Button> </> )} </div> </div> </form> </div> ); }); export default SettingsPanel;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Settings panel component to my project. Settings with a save bar that appears on change. It includes: switches, radio, save bar. Install it (Radix build): ```sh pnpm dlx asta-ui@latest add settings-panel --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/settings-panel.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { SettingsPanel, type Settings, type SettingsPanelHandle } from "@/components/astabyte/settings-panel"; ``` Usage example and props: https://ui.astabyte.com/settings-panel Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Radix primitives from the radix-ui package). - Stay on Radix: install other Astabyte UI components with `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Add the Astabyte UI Settings panel component to my project. Settings with a save bar that appears on change. It includes: switches, radio, save bar. Install it (Base UI build): ```sh pnpm dlx asta-ui@latest add settings-panel ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/settings-panel.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { SettingsPanel, type Settings, type SettingsPanelHandle } from "@/components/astabyte/settings-panel"; ``` Usage example and props: https://ui.astabyte.com/settings-panel Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Base UI primitives from the @base-ui/react package). - Stay on Base UI: install other Astabyte UI components without `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<!-- Needs asta.js for the unsaved-changes bar; the form posts to /settings. --> <div style="max-width:520px"> <form id="settings" data-asta-settings hx-indicator="find [data-asta-settings-save]" action="/settings" method="post" hx-post="/settings" hx-swap="none" class="asta-settings-panel"> <div class="asta-settings-body"> <section class="asta-settings-section"><h4 class="asta-settings-heading">Appearance</h4><div class="asta-settings-rows"><div role="radiogroup" aria-label="Theme" class="asta-settings-theme"><label class="asta-settings-theme-option"><input type="radio" name="theme" value="light" class="asta-sr-only" checked><span class="asta-settings-swatch "></span><span class="asta-settings-theme-label">Light<span class="asta-settings-theme-radio"></span></span></label><label class="asta-settings-theme-option"><input type="radio" name="theme" value="dark" class="asta-sr-only"><span class="asta-settings-swatch asta-settings-swatch-dark"></span><span class="asta-settings-theme-label">Dark<span class="asta-settings-theme-radio"></span></span></label><label class="asta-settings-theme-option"><input type="radio" name="theme" value="system" class="asta-sr-only"><span class="asta-settings-swatch asta-settings-swatch-system"></span><span class="asta-settings-theme-label">System<span class="asta-settings-theme-radio"></span></span></label></div></div></section> <section class="asta-settings-section"><h4 class="asta-settings-heading">Notifications</h4><p class="asta-settings-desc">Where Astabyte tells you about deploys.</p><div class="asta-settings-rows"><div class="asta-settings-row"><div><label for="n-email" class="asta-settings-row-label">Email</label><p class="asta-settings-row-desc">A summary when a deploy finishes.</p></div><div><span class="asta-switch-track"><input type="checkbox" role="switch" class="asta-switch-input" id="n-email" name="n-email" checked><span class="asta-switch-thumb" aria-hidden="true"></span></span></div></div><div class="asta-settings-row"><div><label for="n-push" class="asta-settings-row-label">Push</label><p class="asta-settings-row-desc">Only when something fails.</p></div><div><span class="asta-switch-track"><input type="checkbox" role="switch" class="asta-switch-input" id="n-push" name="n-push"><span class="asta-switch-thumb" aria-hidden="true"></span></span></div></div></div></section> <section class="asta-settings-section"><h4 class="asta-settings-heading">Region</h4><div class="asta-settings-rows"><div class="asta-settings-row"><div><label for="lang" class="asta-settings-row-label">Language</label><p class="asta-settings-row-desc">Used across the app.</p></div><div><div style="width:150px"><div class="asta-select asta-select-sm"><select class="asta-select-control" id="lang" name="lang"><option value="english" selected>English</option><option value="bahasa indonesia">Bahasa Indonesia</option></select><svg class="asta-select-icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m4 6 4 4 4-4"/></svg></div></div></div></div></div></section> </div> <div data-asta-settings-bar class="asta-settings-savebar"><div role="region" aria-label="Unsaved changes" class="asta-settings-toast"> <span class="asta-settings-status" aria-live="polite"><span data-asta-settings-saved class="asta-settings-saved-msg"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3.5 8.5l3 3 6-7"/></svg>Saved</span><span data-asta-settings-unsaved class="asta-settings-unsaved-msg"><span class="asta-settings-dot"></span><span>Unsaved changes</span></span></span> <span data-asta-settings-unsaved class="asta-settings-actions"><button class="asta-btn asta-btn-ghost asta-btn-sm asta-settings-reset" type="reset" tabindex="-1"><span class="asta-btn-label">Reset</span><span class="asta-btn-spinner" aria-hidden="true"><svg viewBox="0 0 16 16" fill="none" aria-hidden="true"><circle cx="8" cy="8" r="6" stroke="currentColor" stroke-opacity="0.25" stroke-width="2"/><path d="M14 8a6 6 0 0 0-6-6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></span></button><button class="asta-btn asta-btn-accent asta-btn-sm" type="submit" data-asta-settings-save tabindex="-1"><span class="asta-btn-label">Save</span><span class="asta-btn-spinner" aria-hidden="true"><svg viewBox="0 0 16 16" fill="none" aria-hidden="true"><circle cx="8" cy="8" r="6" stroke="currentColor" stroke-opacity="0.25" stroke-width="2"/><path d="M14 8a6 6 0 0 0-6-6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></span></button></span> </div></div> </form> </div>
Usage
The demo above, as code.
"use client";
import { useRef, useState } from "react";
import { SettingsPanel, type Settings, type SettingsPanelHandle } from "@/components/astabyte/settings-panel";
const INITIAL: Settings = {
name: "Rani Pratama",
email: "[email protected]",
notify: { product: true, mentions: true, digest: false },
theme: "system",
language: "English",
};
export default function SettingsPanelDemo() {
const panel = useRef<SettingsPanelHandle>(null);
const [note, setNote] = useState("");
return (
<div className="relative flex min-h-[420px] w-full flex-col items-center justify-center gap-3 p-4 sm:p-8">
<div className="flex w-full max-w-[520px] items-center justify-between px-1">
<p className="text-[15px] font-medium tracking-[-0.01em] text-ink">Settings</p>
{/* A fake navigation: blocked (and the save bar shakes) while there are unsaved changes. */}
<button
type="button"
onClick={() => setNote(panel.current?.requestLeave() ? "Left the page" : "Save or reset first")}
className="rounded-lg px-2 py-1 text-[13px] text-mute outline-none transition-colors hover:bg-paper-2 hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50"
>
← Back to dashboard
</button>
</div>
<SettingsPanel ref={panel} initial={INITIAL} onSave={() => new Promise((r) => setTimeout(r, 900))} />
<p className="h-4 text-[12.5px] text-mute" aria-live="polite">
{note || "Change anything and the save bar slides up."}
</p>
</div>
);
}