Capsule Toggles, animated React component
- Free
- Inputs & Controls
- Spring
Switches built as a ball sealed in a glass capsule. Flip one and the ball stretches into a pill mid-flight, then takes on the row's colour and glows as it lands.
Latches on when a switch turns on and off when it turns off. Sound is off on this site until you switch it on.
Like Capsule Toggles? 304 more are in Pro.
Pro unlocks all 304 Pro components, every template and block, and everything we release next. Capsule Toggles stays free.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| rows | CapsuleToggleRow[] | Wi-Fi, Bluetooth, Focus, Low Power | CapsuleToggles: rows as { id, label, hint, color, on }. |
| title | string | "Controls" | CapsuleToggles: small heading above the list. |
| autoplay | boolean | false | CapsuleToggles: flips the rows one after another until someone touches the panel. |
| checked | boolean | required | CapsuleToggle: whether the switch is on. |
| onChange | (v: boolean) => void | required | CapsuleToggle: called with the new value when pressed. |
| label | string | required | CapsuleToggle: accessible name of the switch. |
| onColor | string | "#34c759" | CapsuleToggle: ball colour and glow when on. |
| offColor | string | theme grey | CapsuleToggle: ball colour when off; defaults to a grey that adapts to dark mode. |
| 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
Run this once per project. It writes the Nexus UI entry into
components.jsonfor you:npx shadcn@latest registry add "@nexus-labs=https://www.nexus-ui.com/api/registry/{name}"Type it exactly as shown.
{name}is filled in by the CLI with the component you ask for, so you never replace it.
- 3
Add the component
Run this from your project root. It adds the component, the helpers it imports and its npm packages.
npx shadcn@latest add @nexus-labs/capsule-toggles
- 4
Check what was added
With a project made as in the Quick Start (a
src/folder), these files land in it:components/capsule-toggles/capsule-toggles.tsxindex.ts - 5
Copying by hand? Skip the registry
Instead of steps 2 and 3 you can copy the files yourself, with no registry and no API key. Step 1 still applies, so that
cn()exists. Install the packages:npm install framer-motion
Then show the source and create each file at the path it gives:
- 6
Use it in a page
Installing only adds the files. Import the component in a page and render it. The Usage tab on the preview shows a fuller example with props:
// src/app/page.tsx import { CapsuleToggle } from "@/components/capsule-toggles"; export default function Page() { return ( <main> <CapsuleToggle /> </main> ); }
Like Capsule Toggles? 304 more are in Pro.
Pro unlocks all 304 Pro components, every template and block, and everything we release next. Capsule Toggles stays free.
Capsule Toggles questions
How do I install Capsule Toggles?
Run `npx shadcn@latest add @nexus-labs/capsule-toggles`. It is free and installs framer-motion. The file exports both the single `CapsuleToggle` switch and the `CapsuleToggles` settings panel.
How do I use one switch on its own?
Render `CapsuleToggle` with `checked`, `onChange` and `label`, all required. It is a button with `role="switch"` and `aria-checked`, and `label` is its accessible name.
How do I set up the panel rows?
Pass `rows` as `{ id, label, hint, color, on }`. `on` is only the starting state, `hint` shows under the label while the row is on, and `title` (default "Controls") is the heading. The panel keeps its own state.
How do I change the colours?
`onColor` (default `#34c759`) sets the ball colour and glow when on, and `offColor` sets the ball when off. Without `offColor`, a grey that changes in dark mode is used. In the panel, each row's `color` is its `onColor`.
Does the animation run if I change `checked` from code?
Yes. The ball stretches into a pill whenever `checked` changes, whether the user pressed the switch or your own state updated it.
Does it make sound, and how do I turn it off?
Latches on when a switch turns on and off when it turns off. 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.

