Ruler Picker, animated React component
A duration picker you fling like a ruler: it glides with momentum and snaps to whole units, the big number rolls in the direction you moved, and presets spring the ruler into place.
- Pro
- Inputs & Controls
- Spring
Ticks as the ruler passes each unit while you drag, fling or press arrows, and taps on a preset. Sound is off on this site until you switch it on.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| min | number | 0 | Smallest value. |
| max | number | 90 | Largest value. |
| defaultValue | number | 25 | Starting value. |
| unit | string | "min" | Unit shown after the number. Values of 60 and up show as hours. |
| presets | number[] | [5, 15, 30, 60] | Quick-pick buttons under the ruler. |
| accent | string | "#ff9f0a" | Needle and selected preset colour. |
| onChange | (value: number) => void | — | Called as the value changes. |
| autoplay | boolean | false | Glides between presets until someone interacts. |
| enableSound | boolean | true | Plays interface sounds on interaction. They follow the sound switch (setSoundsEnabled, on by default) and stay silent on hover. Autoplay makes the same sounds once the visitor has used the page. Pass false to silence this component. |
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
Ruler Picker 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
Ruler Picker questions
How do I install Ruler Picker?
Run `npx shadcn@latest add @nexus-labs/ruler-picker`. It installs framer-motion. Ruler Picker is a Pro component, so it needs a Pro plan and an API key; key setup is on the CLI docs page (/docs/cli).
How do I set the range and read the value?
`min` (default 0), `max` (default 90) and `defaultValue` (default 25) set the range and start. `onChange` is called with the new number as it changes. It is uncontrolled, so there is no `value` prop.
What happens at 60 and above?
The big number switches to an hours format such as 1:05 with an "hr" label; below 60 it shows the number with `unit` (default "min"). Preset buttons read "N min", or "N hr" from 60.
How do I change the presets and colour?
`presets` is an array of numbers (default `[5, 15, 30, 60]`); tapping one springs the ruler there. `accent` (default `#ff9f0a`) colours the needle and the selected preset.
How do I move it with drag or keyboard?
Drag or fling the ruler and it glides with momentum, then snaps to a whole unit. The ruler is focusable with `role="slider"`, and the Left and Right arrow keys move it one unit.
Does it make sound, and how do I turn it off?
Ticks as the ruler passes each unit while you drag, fling or press arrows, and taps on a preset. 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.