-}
-
-/**
- * The page around connecting, setup and recovery. On wider screens the card sits on a tinted page at a fixed height,
- * so the brand and step bar stay put while cards of different heights follow one another.
- */
-export function AuthPage({ header, children }: { header?: ReactNode; children: ReactNode }) {
- return
-
- {header}
- {children}
-
-
-}
-
-// For an element that replaces the control just pressed: focus would otherwise fall to .
-export function claimFocus(node: HTMLElement | null) {
- const active = node?.ownerDocument.activeElement
- if (node && (!active || active === node.ownerDocument.body)) node.focus({ preventScroll: true })
-}
-
-/** One step of first-time setup: a raised card under an icon title. */
-export function Panel({ icon: Icon, title, busy = false, children }: { icon: LucideIcon; title: string; busy?: boolean; children: ReactNode }) {
- // A phone has no room for a frame inside the page's own margins, so there the card is only its content.
- return
-
{title}
- {children}
-
-}
-
-/** A settings section: a short caption over one card of rows, with an optional note under it. */
-export function SettingsGroup({ title, footer, children, className }: { title?: string; footer?: ReactNode; children: ReactNode; className?: string }) {
- return
- {title ?
{title}
: null}
-
{children}
- {footer ?
{footer}
: null}
-
-}
-
-const rowTile: Record<"neutral" | "success" | "danger", string> = { neutral: "bg-muted text-muted-foreground", success: "bg-success-soft text-success", danger: "bg-danger-soft text-danger" }
-const rowLayout = "flex min-h-14 w-full min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-2.5 text-start"
-
-function RowLead({ icon: Icon, label, description, tone = "neutral" }: { icon: LucideIcon; label: ReactNode; description?: ReactNode; tone?: keyof typeof rowTile }) {
- return <>
-
-
- {label}
- {description ? {description} : null}
-
- >
-}
-
-/** One settings row: icon, label, then its value or control at the end. With `onClick` the whole row is a button; `expanded` marks one that folds out below itself. */
-/** `stacked`: on a phone the control gets its own full line under the label, lined up with it. */
-export function SettingsRow({ id, icon, label, description, tone, children, onClick, expanded, className, stacked = false, ref }: {
- id?: string; icon: LucideIcon; label: ReactNode; description?: ReactNode; tone?: keyof typeof rowTile; children?: ReactNode; onClick?: () => void; expanded?: boolean; className?: string; stacked?: boolean; ref?: Ref
-}) {
- const end = children ? {children} : null
- if (onClick) return
- return
{end}
-}
-
-/** A row that folds out what it holds below itself, inside the same card. */
-export function SettingsDisclosure({ icon, label, value, open, children }: { icon: LucideIcon; label: ReactNode; value?: ReactNode; open?: boolean; children: ReactNode }) {
- return
-
-
- {value ? {value} : null}
-
-
-
{children}
-
-}
-
-/**
- * A short set of mutually exclusive options on a muted track.
- * On a phone, options with icons show only the icon; pair it with `SegmentedValue` so the choice still reads in words.
- * `labels` keeps the words on a phone too, for options an icon alone can't explain.
- */
-export function Segmented({ label, value, options, onChange, disabled, labels = false, fill = false }: {
- label: string; value: T; options: Array<{ value: T; label: string; icon?: LucideIcon }>; onChange(value: T): void; disabled?: boolean; labels?: boolean
- /** On a phone, spread the options evenly across the full width. */ fill?: boolean
-}) {
- // WAI-ARIA radio group: one Tab stop on the checked option, arrows move and select.
- const tabStop = options.some((option) => option.value === value) ? value : options[0]?.value
- const move = (event: KeyboardEvent) => {
- const step = ({ ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 } as Record)[event.key]
- if (disabled || (!step && event.key !== "Home" && event.key !== "End")) return
- event.preventDefault()
- const radios = [...event.currentTarget.querySelectorAll("[role=radio]")]
- const current = radios.indexOf(event.target as HTMLElement)
- const next = event.key === "Home" ? 0 : event.key === "End" ? options.length - 1 : (current + step! + options.length) % options.length
- radios[next]?.focus()
- if (options[next].value !== value) onChange(options[next].value)
- }
- // One thumb slides to the checked option; it is measured, since options differ in width and the track may wrap.
- const track = useRef(null)
- const [thumb, setThumb] = useState()
- useLayoutEffect(() => {
- const element = track.current
- if (!element) return
- const place = () => {
- const checked = element.querySelector("[aria-checked=true]")
- setThumb(checked ? { width: checked.offsetWidth, height: checked.offsetHeight, translate: `${checked.offsetLeft}px ${checked.offsetTop}px` } : undefined)
- }
- place()
- const resize = new ResizeObserver(place)
- resize.observe(element)
- return () => resize.disconnect()
- }, [value])
- return
-}
-
-/** The chosen option of a `Segmented` in words, shown only where the control shrinks to icons. */
-export function SegmentedValue({ value, options }: { value: T; options: Array<{ value: T; label: string }> }) {
- return {options.find((option) => option.value === value)?.label}
-}
-
-/** Same shape as the real layout; fades in only after 300ms to avoid flicker. */
-export function Skeleton({ className }: { className?: string }) {
- return
-}
-
-export function InlineError({ error, action, className }: { error: unknown; action?: { label: string; onClick: () => void }; className?: string }) {
- if (!error) return null
- const text = messageOf(error), raw = rawError(error)
- return