Updated
Sleep Stages
NewCustomize
Color
Width460px
Installation
npx shadcn@latest add https://uibrik.com/r/sleep-stages.jsonInstall the packages
npm install motionAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/sleep-stages/sleep-stages.tsx"use client"; // A night of sleep as a hypnogram: four rows (awake, REM, light, deep) with a // block for every stretch in each stage and a thin step joining them. The // score and time asleep sit above; below, each stage's share of the night // against its typical range. Hovering a stage, in the legend or by scrubbing // the chart, lifts its blocks and dims the rest; the scrub cursor reads the // clock time and stage under it. import { animate, motion, useMotionValue, useReducedMotion, useTransform } from "motion/react"; import { useEffect, useId, useMemo, useRef, useState, type CSSProperties, type PointerEvent } from "react"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; export type SleepStage = "awake" | "rem" | "light" | "deep"; export type SleepSegment = { stage: SleepStage; minutes: number }; export type SleepNight = { /** Short label for the week strip, e.g. "Mon". */ label: string; bedtime: string; score?: number;
Adds the files to
components/uibrik/sleep-stages and installs motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/sleep-stages.Usage
import { SleepStages } from "@/components/uibrik/sleep-stages/sleep-stages";<SleepStages title="Sleep" color="#6e56cf" hour24={false} width={460} // nights={[{ label: "…", bedtime: "…", segments: […] }]} // defaultNight={0} // onNightChange={(index) => {}} // segments={[{ stage: "awake", minutes: 0 }]}/>Where to use Sleep Stages
Health and wearable apps
The whole night reads in one chart, and scrubbing answers when each stage happened.
Pairs with Daily Rings
Wellness dashboards
Typical ranges next to each stage say whether a number is good without a separate legend.
Pairs with Streak Calendar
Sleep tracker landing pages
A hypnogram that draws in shows what the device measures before any copy does.
Props
SleepStages- title
- Type string
- "Sleep"
- Heading above the chart.
- color
- Type string
- "#6e56cf"
- Hue the stages are shaded from. Awake stays neutral.
- hour24
- Type boolean
- false
- Show times in 24-hour format.
- width
- Type number
- 460
- Width of the card; never wider than its container.
- nights
- Type { label: string; bedtime: string; score?: number; segments: SleepSegment[] }[]
- –
- Several nights, oldest first, with a strip to switch between them. Overrides segments, bedtime and score.
- defaultNight / onNightChange
- Type number / (index) => void
- –
- Night shown on mount (defaults to the last) and a callback when it changes.
- segments
- Type { stage: "awake" | "rem" | "light" | "deep"; minutes: number }[]
- –
- A single night in order, one entry per stretch in a stage; shown without the week strip.
- className
- Type string
- –
- Classes for the wrapper.