Skip to content

NewMCP server for your coding agent. Set it up ›

Nexus UI
Get Pro

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

Wed, Nov 12
Stages10:02 PM to 5:52 AM
Awake
REM
Core
Deep
11 PM1 AM3 AM5 AM

Awake

0h 3m

REM

1h 42m

Core

4h 46m

Deep

1h 19m

Props

PropTypeDefaultWhat it does
nightssample dataThe nights to step through, oldest first: { label, start, stages, bedtimeShift }.
enableSoundtrueSoft synthesised sounds as you use it. They also follow the site-wide sound switch.
volume0.8Sound level, 0 to 1.
autoplayfalsePlays a short demo by itself until the visitor touches it. Never runs under reduced motion.
className""Extra classes for the outer element.

Add it to your project

  1. 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 creates components.json and the cn() helper in src/lib/utils.ts:

    npx shadcn@latest init -d

    Starting from nothing? The Quick Start walks through the whole thing.

  2. 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:

    1. Create a key at nexus-ui.com/dashboard/api-key. Copy it straight away: it starts with nxs_ and is shown only once.
    2. In your project root, next to package.json, create a file named .env.local with this line, using your own key:
      NEXUS_API_KEY=nxs_your_key_here
    3. Open components.json and 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}"
          }
        }
      }

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.