Sula Segmented

SulaSegmented is a segmented control (radio group) whose sliding indicator is rendered as a gooey, liquid-like pill on a WebGL canvas, with a plain CSS-sliding pill fallback when fluid rendering is off, reduced motion is requested, or WebGL context fails. It is a drop-in replacement for a standard segmented toggle with keyboard arrow navigation.

Sula Segmented
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @usva/sula-segmented

Requires @usva in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { useState } from "react";import { SulaSegmented } from "@/components/ui/sula-segmented";export function Example() {  const [view, setView] = useState("list");  return (    <SulaSegmented      items={[        { value: "list", label: "List" },        { value: "grid", label: "Grid" },      ]}      value={view}      onValueChange={setView}    />  );}
  • Switching between two to about five mutually exclusive views or modes (e.g. list/grid, day/week/month) where a playful, liquid indicator suits the brand.
  • Compact toggles in toolbars or settings headers that need a clear single selection with visible motion.
  • Places where you want a polished sliding indicator but must still degrade to a simple CSS slide for reduced-motion users or unsupported devices.
  • Controlled or uncontrolled single-select state with optional icons alongside labels.

Examples

Uncontrolled with default value

Uses defaultValue to set the initial selection and lets the component manage its own state.

uncontrolled-with-default-value.tsx
import { SulaSegmented } from "@/components/ui/sula-segmented";export function PeriodPicker() {  return (    <SulaSegmented      defaultValue="week"      items={[        { value: "day", label: "Day" },        { value: "week", label: "Week" },        { value: "month", label: "Month" },      ]}    />  );}

Icons with labels and small size

Shows an icon before each label and uses the sm size with a bare surface for embedding in a header.

icons-with-labels-and-small-size.tsx
import { useState } from "react";import { SulaSegmented } from "@/components/ui/sula-segmented";export function ViewToggle() {  const [mode, setMode] = useState("grid");  return (    <SulaSegmented      size="sm"      bare      value={mode}      onValueChange={setMode}      items={[        { value: "list", label: "List", icon: <span aria-hidden="true">≡</span> },        { value: "grid", label: "Grid", icon: <span aria-hidden="true">▦</span> },      ]}    />  );}

Plain indicator with fluid disabled

Turns off the canvas field so only the CSS sliding pill renders, mounting no canvas.

plain-indicator-with-fluid-disabled.tsx
import { useState } from "react";import { SulaSegmented } from "@/components/ui/sula-segmented";export function PlainToggle() {  const [tab, setTab] = useState("all");  return (    <SulaSegmented      fluid={false}      value={tab}      onValueChange={setTab}      items={[        { value: "all", label: "All" },        { value: "open", label: "Open" },        { value: "closed", label: "Closed" },      ]}    />  );}

API reference

PropTypeDefaultDescription
itemsSulaSegmentedItem[]—Segments to render. Each item has value (string), label (React.ReactNode) and optional icon (React.ReactNode).
valuestring—Controlled selected value. When provided, the component does not manage its own selection state.
defaultValuestringitems[0]?.valueInitial selected value when uncontrolled.
onValueChange(value: string) => void—Called with the newly selected value when a segment is clicked or reached via arrow keys.
size"sm" | "md""md"Segment height and horizontal padding: sm is h-8 px-3, md is h-9 px-4.
fluidbooleantrueWhen false, or when reduced motion is preferred or the WebGL context fails, renders the plain sliding pill and mounts no canvas.
barebooleanfalseRemoves the track border and surface fill, leaving the indicator on a bare surface.
accentColorstring—Overrides the accent color used for the indicator; otherwise reads --usva-accent.
backdropstring—Overrides the backdrop color used for the field; otherwise reads --usva-bg.
tintstring—Overrides the tint color of the indicator fill; otherwise reads --usva-surface-2 with a --usva-surface fallback.
shinenumber—Overrides the shine amount; otherwise derived from the backdrop color.
classNamestring—Additional classes merged onto the root radiogroup element.

Accessibility

  • The root element has role="radiogroup" and each segment is a button with role="radio" and aria-checked reflecting selection.
  • Roving tabindex: only the checked segment is tabbable (tabIndex 0), others are -1.
  • Arrow Left/Up and Arrow Right/Down move focus and select the adjacent segment with wrap-around; Home and End jump to the first and last segments.
  • The canvas stage and icon wrappers are aria-hidden, so screen readers announce only the labels.
  • Reduced motion (useReducedMotion) disables the fluid field and uses the plain pill, which also respects motion-reduce transition classes.
  • Provide a visible accessible name for the group via aria-label or aria-labelledby passed through props, since the root has no built-in label.
  • Focus is shown with focus-visible ring styles on each segment.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Sula Segmented" component (usva/sula-segmented) from its shadcn registry.1. Install it with: npx shadcn@latest add @usva/sula-segmented2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: items, value, defaultValue, onValueChange, size, fluid, bare, accentColor, backdrop, tint, shine, className.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { useState } from "react";import { SulaSegmented } from "@/components/ui/sula-segmented";export function Example() {  const [view, setView] = useState("list");  return (    <SulaSegmented      items={[        { value: "list", label: "List" },        { value: "grid", label: "Grid" },      ]}      value={view}      onValueChange={setView}    />  );}```

Files & dependencies

  • segmented-geometry.ts→ components/ui/segmented-geometry.ts
  • sula-segmented.tsx→ components/ui/sula-segmented.tsx
dependenciesclsxmotionogltailwind-merge
registryDependencieshttps://usva.build/r/sula-motion.jsonhttps://usva.build/r/sula-core.json

Looks similar, elsewhere