Skip to content
caliper ui docs

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.

Free
pnpm dlx shadcn@latest add @caliper/spirit-level

Shelf

Tilt the surface; the bubble follows.

Installs components/ui/spirit-level.tsxDepends on none beyond ReactMotion none in component source

When 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

terminal
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.

example.tsx
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.

PropTypeDefaultDescription
value *number—Tilt in degrees: negative leans left, positive leans right.
maxnumber10Tilt at which the bubble reaches the end of the tube.
tolerancenumber0.5Tilt within which the surface counts as level.
labelstring"Level"

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.

All Changing values examples