Primitives
List
A vertical stack of focusable rows (watchOS list spirit). Keep it short: a glanceable HUD caps at 3 to 5 rows. Compose List with ListRow (leading glyph, label, trailing value).
Installation
npx @glasskit-ui/cli add listInstall 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/list.tsx"use client";import { useEffect, useRef, type ReactNode } from "react";import { cn } from "../lib/utils";/** * <List> — a vertical stack of focusable rows (watchOS list spirit) that fills * the stage and scrolls (D-pad scrollIntoView). A position indicator on the * inline-end edge tracks scroll — sized to the content and hidden when the list * fits. Compose with <ListRow>. */export function List({ children, className,}: { children: ReactNode; className?: string;}) { const scrollRef = useRef<HTMLDivElement>(null); const railRef = useRef<HTMLSpanElement>(null); const thumbRef = useRef<HTMLSpanElement>(null); useEffect(() => { const sc = scrollRef.current; const rail = railRef.current; const thumb = thumbRef.current; if (!sc || !rail || !thumb) return; const update = () => { const { scrollTop, scrollHeight, clientHeight } = sc; const overflow = scrollHeight - clientHeight; if (overflow <= 1) { rail.dataset.show = "false"; return; } rail.dataset.show = "true"; const trackH = rail.clientHeight; const thumbH = Math.max(trackH * (clientHeight / scrollHeight), 26); const pos = (scrollTop / overflow) * (trackH - thumbH); thumb.style.height = `${thumbH}px`; thumb.style.transform = `translateY(${pos}px)`; }; // Smooth scroll on focus: the D-pad engine moves the ring with // preventScroll, so the List owns the scroll. `block: "nearest"` keeps the // list still while the focused row is fully on screen and only glides once // the ring passes the visible page (then it slides just enough to reveal // the next row) — smooth, not the instant per-row jump native focus does. // Honors reduced-motion. const reduce = typeof matchMedia !== "undefined" && matchMedia("(prefers-reduced-motion: reduce)").matches; const onFocusIn = (e: FocusEvent) => { const row = (e.target as HTMLElement | null)?.closest("[data-list-row]"); if (row && sc.contains(row) && typeof row.scrollIntoView === "function") { row.scrollIntoView({ block: "nearest", behavior: reduce ? "auto" : "smooth", }); } }; update(); sc.addEventListener("scroll", update, { passive: true }); sc.addEventListener("focusin", onFocusIn); const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(update) : null; ro?.observe(sc); return () => { sc.removeEventListener("scroll", update); sc.removeEventListener("focusin", onFocusIn); ro?.disconnect(); }; }, []); return ( <div className={cn("relative size-full self-stretch", className)}> <div className="gk-list__scroll" ref={scrollRef}> {children} </div> <span className="gk-list__rail" ref={railRef} data-show="false" aria-hidden="true" > <span className="gk-list__bar" ref={thumbRef} /> </span> </div> );}/** * <ListRow> — a D-pad-focusable row: leading glyph, label, trailing value. * Renders a real <button> with the `focusable` class so `useDpad()` walks * it. Logical layout (leading = inline-start) for RTL safety. */export function ListRow({ children, leading, trailing, onClick, disabled, className,}: { /** The row label. */ children: ReactNode; /** Optional inline-start glyph — typically a <Icon>. */ leading?: ReactNode; /** Optional inline-end value/affordance. */ trailing?: ReactNode; onClick?: () => void; disabled?: boolean; className?: string;}) { return ( <button type="button" disabled={disabled} onClick={onClick} data-list-row="" className={cn( "focusable press-scale t-body surface flex w-full flex-none items-center gap-[13px] rounded-lens px-5 py-4 text-start min-h-[74px]", className, )} > {leading} <span className="min-w-0 flex-1">{children}</span> {trailing != null ? ( <span className="t-caption text-foreground-faint [font-variant-numeric:tabular-nums]"> {trailing} </span> ) : null} </button> );}Usage
<List> <ListRow leading={<Icon size="sm"><NavIcon /></Icon>}> Navigate </ListRow> <ListRow trailing="2">Messages</ListRow></List>Props
| Prop | Type | Default | Description |
|---|---|---|---|
List · children | ReactNode | — | ListRow elements. |
ListRow · children | ReactNode | — | The row label. |
ListRow · leading | ReactNode | — | Inline-start glyph. |
ListRow · trailing | ReactNode | — | Inline-end value. |
ListRow · onClick | () => void | — | Row activation. |
ListRow · disabled | boolean | — | Dims and skips D-pad focus. |
Segmented
Pick one of a few options (a watchOS-style segmented control). Each segment is a D-pad-focusable radio; the selected one lifts with the accent. Keep it to 2–4 options.
QuickReplyChips
Tappable canned replies (the comms job: there is no keyboard on the lens, text is voice). Each chip is D-pad-focusable. Keep the set short and glanceable.