Pull Cord, animated React component
- Pro
- Inputs & Controls
A light switch on a cord: a small verlet rope you grab by its bead, pull past its slack and let go to toggle the light. The panel lights up or goes dark and the cord swings and settles; Enter or Space tugs it from the keyboard.
Clicks on when the light comes on and off when it goes out, once per pull. Sound is off on this site until you switch it on.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| defaultOn | boolean | false | Whether the light starts on. |
| onChange | (on: boolean) => void | — | Called with the new state when the user pulls the cord or presses Enter/Space on it. |
| onText | string | "Lights on." | Headline while the light is on. |
| offText | string | "Lights off." | Headline while the light is off. |
| hint | string | "Pull the cord." | Small line under the headline. |
| className | string | — | Extra classes for the 320px-wide outer wrapper. |
| autoplay | boolean | false | Tugs the cord every 2.6s until someone grabs it. |
| 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
Pull Cord 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 Pull Cord works
pull it down past its slack and let go, and the room lights up (or goes dark). It swings and settles like a real cord. Enter or Space tugs it for keyboard users. The light only ever fills this panel, never the page.
The source, the install command and the build prompt come with Pro.
Pull Cord questions
How do I install Pull Cord?
Run `npx shadcn@latest add @nexus-labs/pull-cord`. It installs framer-motion. Pull Cord 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 run code when the light switches?
Pass `onChange`. It receives the new boolean when the cord is pulled or Enter/Space is pressed, but not for the `autoplay` demo. `defaultOn` sets the starting state and defaults to `false`.
How do I change the text on the panel?
Use `onText` (default "Lights on."), `offText` (default "Lights off.") and `hint` (default "Pull the cord."). The panel is 320px wide and scales down to fit a narrower parent.
Can I use it from the keyboard?
Yes. The bead is a button with `role="switch"`, and Enter or Space tugs the cord and toggles the light. With a pointer you grab the bead, pull it past its slack and let go.
How is the cord animated?
The cord is a 12-segment verlet rope stepped in a `requestAnimationFrame` loop and drawn as an SVG path. Framer Motion fades the panel colour and glow. The light only fills the panel, never the page.
Does it make sound, and how do I turn it off?
Clicks on when the light comes on and off when it goes out, once per pull. 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.

