Skip to content
caliper ui docs

Components

Newton cradle

A desk cradle as a loading indicator. The end ball swings out and falls back, the row passes the knock along and the ball at the other end swings in turn. The swing slows at the top and quickens through the bottom, as a real pendulum does.

Free
pnpm dlx shadcn@latest add @caliper/newton-cradle

Import

Waiting that takes a moment, kept calm.

Importing contacts
Installs components/ui/newton-cradle.tsxDepends on none beyond ReactMotion none in component source

When to use

Use it for

  • Waiting that will take a moment: syncing, importing, generating.
  • Quiet states in a dashboard where a spinner would feel frantic.

Skip it when

  • Progress you can measure; show a bar or ring with a value.
  • Buttons and inline text, where a small `Loader` fits better.

Decisions

Why it is built this way, so you know what to keep when you change your copy.

Behaviour

Real pendulum timing
Each swing eases out going up and in coming down, and the two ends take half a cycle each, so the rhythm looks physical.

Usage

A status with a name
It is a status named "Loading" by default; pass a label that says what is happening, or an empty one when text beside it does.
Still under reduced motion
The balls hold still with one raised, so the picture still says that something is pending.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/newton-cradle

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 { NewtonCradle } from "@/components/ui/newton-cradle"

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 NewtonCradleDemo() {
  const [paused, setPaused] = useState(false);
  return (
    <Panel title="Import" context="Waiting that takes a moment, kept calm.">
      <div className="grid justify-items-center py-4">
        <NewtonCradle size="lg" paused={paused} label="Importing 2,418 contacts" />
      </div>
      <div className="flex items-center justify-between gap-3 border-t border-border pt-4 text-sm">
        <span className="flex items-center gap-3">
          <NewtonCradle size="sm" balls={3} paused={paused} label="" />
          <span className="text-muted-foreground">{paused ? "Paused" : "Importing contacts"}</span>
        </span>
        <Button variant="secondary" size="sm" aria-pressed={paused} onClick={() => setPaused((value) => !value)}>
          {paused ? "Resume" : "Pause"}
        </Button>
      </div>
    </Panel>
  );
}

API reference

NewtonCradle

component

Also accepts the native props of its root element and a ref.

PropTypeDefaultDescription
labelstring"Loading"Names what is happening, e.g. "Syncing". Pass "" when a visible label sits beside it.
ballsnumber5Balls in the row, 3 to 7.
pausedboolean—Holds the balls at rest.
size"sm" | "md" | "lg""md"

Accessibility

It is built on native elements and keeps aria-label and aria-hidden 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 Surfaces examples