Skip to content
caliper ui docs

Components

Moon phase

The moon for a date, or for a phase you give it. The lit part is a half disc closed by the terminator; when the date changes, the terminator sweeps to the new phase by the shortest way round.

Free
pnpm dlx shadcn@latest add @caliper/moon-phase

Garden planner

Step through the month.

24 November 2026

Installs components/ui/moon-phase.tsxDepends on none beyond ReactMotion honours reduced motion

When to use

Use it for

  • Calendars, planners, tide and garden apps.
  • Detail on a date picker or an almanac screen.

Skip it when

  • Astronomy that needs minutes; the phase is good to about a day.
  • Any place the date has no meaning.

Decisions

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

Behaviour

Shortest way round
From a waning crescent to a new moon it keeps waning; it does not wind back through full.

Styling

The same pale grey in both themes
The moon is fixed neutral discs, not theme colours, because it looks the same by day and by night.

Usage

Phase and share lit as words
It is an image named with the phase and the percentage lit, and the same line is written under it.

Installation

terminal
pnpm dlx shadcn@latest add @caliper/moon-phase

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. It is built from MoonPhase, moonPhase, phaseName and litPath.

example.tsx
import { useState, type ReactNode } from "react"
import { Button } from "@/components/ui/button"
import { MoonPhase } from "@/components/ui/moon-phase"

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>
  );
}

const MOON_BASE = Date.UTC(2026, 10, 24);

export function MoonPhaseDemo() {
  const [offset, setOffset] = useState(0);
  const date = new Date(MOON_BASE + offset * 86_400_000);
  return (
    <Panel title="Garden planner" context="Step through the month.">
      <div className="grid justify-items-center gap-1 py-2">
        <MoonPhase date={date} size={120} />
        <p className="text-sm text-muted-foreground">{date.toLocaleDateString("en-GB", { day: "numeric", month: "long", year: "numeric", timeZone: "UTC" })}</p>
      </div>
      <div className="flex flex-wrap justify-center gap-2">
        <Button variant="secondary" size="sm" onClick={() => setOffset((value) => value - 7)}>
          Week back
        </Button>
        <Button variant="secondary" size="sm" onClick={() => setOffset((value) => value - 1)}>
          Day back
        </Button>
        <Button variant="secondary" size="sm" onClick={() => setOffset((value) => value + 1)}>
          Day on
        </Button>
        <Button variant="secondary" size="sm" onClick={() => setOffset((value) => value + 7)}>
          Week on
        </Button>
      </div>
    </Panel>
  );
}

API reference

MoonPhase

component

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

PropTypeDefaultDescription
datestring | number | Date—A date to show the moon for. Ignored when `phase` is given.
phasenumber—The phase directly: 0 is new, 0.25 first quarter, 0.5 full, 0.75 last quarter.
sizenumber96Diameter in pixels.
showNamebooleantrueWrites the phase name and lit share under the moon.

moonPhase

component

No props of its own; it accepts the native props of its root element.

phaseName

component

No props of its own; it accepts the native props of its root element.

litPath

component

No props of its own; it accepts the native props of its root element.

Accessibility

It exposes img semantics, with aria-label and aria-hidden kept in step with state.

No custom key handling; Tab and the native activation keys do the work.

Motion

It checks prefers-reduced-motion itself and settles immediately instead of travelling. Every state is still reachable.

All Media examples