Primitives
Toggle
A binary switch, D-pad-focusable. Controlled via checked + onChange. The knob slides on a logical margin, so it mirrors correctly under RTL.
Installation
npx @glasskit-ui/cli add toggleInstall the SDK (it provides GlassViewport, useDpad and the stylesheet), then copy these files into your project:
npm install @glasskit-ui/react// components/lib/utils.tsimport { clsx, type ClassValue } from "clsx";import { twMerge } from "tailwind-merge";export type { ClassValue };/** * Merge class names the shadcn way: clsx joins conditionals, tailwind-merge * de-dupes conflicting Tailwind utilities so a consumer's `className` override * wins (e.g. passing `px-2` beats the component's `px-6`). Lens components are * Tailwind utilities + `--gk-*` tokens, so this de-dupe matters. */export function cn(...inputs: ClassValue[]): string { return twMerge(clsx(inputs));}/** * Accessible name from a free-form `label` prop: the label itself when it's a * plain string, otherwise undefined (a ReactNode can't become an aria-label). */export function stringLabel(label: unknown): string | undefined { return typeof label === "string" ? label : undefined;}// components/glasskit/toggle.tsximport type { ReactNode } from "react";import { cn } from "../lib/utils";/** * <Toggle> — a binary switch, D-pad-focusable (renders a real button with the * focusable class; useDpad activates it on Enter/Space). Controlled: pass * `checked` + `onChange`. The knob slides via a logical margin, so it mirrors * correctly under RTL (a switch is UI chrome, not world-anchored). */export function Toggle({ checked, onChange, label, disabled, className,}: { checked: boolean; onChange?: (next: boolean) => void; label?: ReactNode; disabled?: boolean; className?: string;}) { return ( <button type="button" role="switch" aria-checked={checked} disabled={disabled} onClick={onChange ? () => onChange(!checked) : undefined} className={cn( "focusable t-body flex w-full items-center justify-between gap-4", // gk-toggle--on drives the track gradient + the knob's margin-auto slide. checked && "gk-toggle--on", className, )} > {label != null ? ( <span className="flex-1 text-start">{label}</span> ) : null} {/* Track + knob keep their gk-* classes: the track gradient/inset-shadow, * the knob's depth shadow, and the margin-inline-start slide transition * are bespoke visuals Tailwind can't express. */} <span className="gk-toggle__track"> <span className="gk-toggle__knob" /> </span> </button> );}Usage
<Toggle label="Notifications" checked={on} onChange={setOn}/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | On/off state (controlled). |
onChange | (next: boolean) => void | — | Fires on toggle. |
label | ReactNode | — | Row label. |
disabled | boolean | — | Excluded from D-pad focus. |
Pressable
The focusable wrapper for custom UI. Renders a real button carrying the focusable class, so useDpad walks it and fires onPress on Enter or the Neural Band pinch. Use it to make any custom content D-pad-interactive when no first-class component fits.
Slider
A continuous level control (volume, brightness, the quick controls). A native range tinted with accent-color; arrow keys / Neural-Band pinch-twist adjust it. Controlled via value + onChange.