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.
pnpm dlx shadcn@latest add @caliper/moon-phaseWhen 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
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.
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.
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.
Related
- Weather sceneThe sky behind a forecast, drawn in the ink of the theme: a slow sun with turning rays, clouds that drift in layers, rain in two depths, snow that sways, and a storm's rain with an occasional soft flash of lightning. A change of condition blends across.
- Clock wallA wall of small analog clocks whose hands line up to draw digits. When the value changes every hand sweeps into a slanting wave across the wall, then turns on into the new figure, always clockwise, rippling from left to right.
- Date pickerA date field that opens a calendar, with min, max and today shortcuts.