Sleep Score, animated React component
Last night's sleep under a real night sky: a cratered moon with its terminator, the Milky Way, stars of different colours with four-point spikes, a shooting star after a good night. The score sits in a gauge of three glowing glass channels, energy running along what you earned to a bright head. Below, the night as a staircase of lit capsules you can scrub. Step between nights and everything flows.
- Pro
- Dashboards
- Hover
- Spring
Soft chimes as the gauge fills and as you step between nights. Sound is off on this site until you switch it on.
Play with it
Move the controls and watch it change. Copy code gives you a snippet with only the props you changed.
Sleep score
Excellent
Awake
0h 3m
REM
1h 42m
Core
4h 46m
Deep
1h 19m
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| nights | SleepNight[] | sample data | The nights to step through, oldest first: { label, start, stages, bedtimeShift }. |
| enableSound | boolean | true | Soft synthesised sounds as you use it. They also follow the site-wide sound switch. |
| volume | number | 0.8 | Sound level, 0 to 1. |
| autoplay | boolean | false | Plays a short demo by itself until the visitor touches it. Never runs under reduced motion. |
| className | string | "" | Extra classes for the outer element. |
Add it to your project
- 1
Set up your project once
You need a Next.js project with Tailwind CSS and the
@/import alias. In its root folder, run this once. It createscomponents.jsonand thecn()helper insrc/lib/utils.ts:npx shadcn@latest init -d
Starting from nothing? The Quick Start walks through the whole thing.
- 2
Connect the registry with your API key
Sleep Score is a Pro item, so the CLI has to send your API key. Do this once per project:
- Create a key at nexus-ui.com/dashboard/api-key. Copy it straight away: it starts with
nxs_and is shown only once. - In your project root, next to
package.json, create a file named.env.localwith this line, using your own key:NEXUS_API_KEY=nxs_your_key_here
- Open
components.jsonand add this entry inside the outermost braces, next to"aliases". Leave{name}and${NEXUS_API_KEY}exactly as written; the CLI fills them in:"registries": { "@nexus-labs": { "url": "https://www.nexus-ui.com/api/registry/{name}", "headers": { "Authorization": "Bearer ${NEXUS_API_KEY}" } } }
- Create a key at nexus-ui.com/dashboard/api-key. Copy it straight away: it starts with
How Sleep Score works
Last night's sleep, on a night-sky card. The score sits inside a gauge of three segments, one for each part of it (how long you slept, how close to your usual bedtime, how often you woke), each as long as the points it's worth and filled to what you earned, glowing softly. Point at a part in the list and its segment brightens and the middle reads that part. Below, the night it to read the time and stage.
The source, the install command and the build prompt come with Pro.
Sleep Score questions
Does it make sound, and how do I turn it off?
Soft chimes as the gauge fills and as you step between nights. Sounds are synthesised with the Web Audio API, so there are no audio files, and they only play after a click or key press. Pass `enableSound={false}` to silence this component, or call `setSoundsEnabled(false)` from `@/lib/ui-sounds` to switch every sound off at once. The CLI installs `@/lib/ui-sounds` with the component.