Components
Spirit level
A carpenter's level. The bubble drifts to the high side and settles with one small overshoot; inside the tolerance the tube turns green and reads Level.
pnpm dlx shadcn@latest add @caliper/spirit-levelWhen to use
Use it for
- Alignment, calibration and device-orientation screens.
- A friendly readout for any value that should sit near zero.
Skip it when
- Readings that need precision; the number beside the tube carries it.
- Values with no natural centre.
Decisions
Why it is built this way, so you know what to keep when you change your copy.
Behaviour
- One overshoot, then rest
- The bubble overshoots by a little and settles; it never wobbles, so a steady reading looks steady.
Usage
- The reading is text
- The tilt is written beside the tube and exposed as a meter, so the bubble is never the only carrier.
Installation
pnpm dlx shadcn@latest add @caliper/spirit-level
Adds its 2 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.
Usage
This is the code behind the preview above.
import { useState, type ReactNode } from "react" import { Button } from "@/components/ui/button" import { SpiritLevel } from "@/components/ui/spirit-level" function Panel({ title, context, className = "max-w-md", children }: { title: string; context: string; className?: string; children: ReactNode }) { return ( <section className={`grid w-full gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting max-sm:p-4 ${className}`}> <div className="grid gap-1"> <p className="font-medium">{title}</p> <p className="text-sm text-muted-foreground">{context}</p> </div> {children} </section> ); } export function SpiritLevelDemo() { const [tilt, setTilt] = useState(6.4); return ( <Panel title="Shelf" context="Tilt the surface; the bubble follows."> <SpiritLevel value={tilt} label="Shelf level" className="max-w-full" /> <label className="grid gap-2 text-sm text-muted-foreground"> Tilt <input type="range" min={-10} max={10} step={0.1} value={tilt} onChange={(event) => setTilt(Number(event.target.value))} className="w-full" aria-label="Tilt in degrees" /> </label> <div className="flex gap-2"> <Button variant="secondary" size="sm" onClick={() => setTilt(0)}> Level it </Button> <Button variant="secondary" size="sm" onClick={() => setTilt(-7.5)}> Tip left </Button> </div> </Panel> ); }
API reference
SpiritLevel
component
Also accepts the native props of its root element and a ref.
Accessibility
It exposes meter semantics, with aria-label, aria-valuemin, aria-valuemax, aria-valuenow, aria-valuetext and aria-hidden kept in step with state.
No custom key handling; Tab and the native activation keys do the work.
Motion
It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.
Related
- Rotary knobA rotary control with a real edge. The knob is a short cylinder seen from above: a stack of discs gives it thickness, a ring of ticks lights up to the value, and the number is always written beside it. Drag it or use the keys; with detents on it clicks through every tenth.
- Elastic sliderA slider with give. Drag past either end and the track stretches toward your finger, the end icon leans with it, and both spring back when you let go. The value is always clamped; only the drawing stretches.
- Ruler sliderA tape of ticks that slides under a fixed needle. Drag it and let go: it keeps the speed you gave it, slows, and clicks into the nearest step while the number above rolls to the new value. For picking a measurement where the scale itself helps.