Pull-cord Bulb
Light and dark mode switch
A pendant lamp that is a switch. Pull the acorn on its textile cord or ball chain: the detent resists and snaps, and the filament warms from dull red to white while the lamp sways. It can switch the whole page’s finish, the new one opening from the bulb.
What it is for
A toggle people want to touch.
npx shadcn add https://tactileui.dev/r/pull-cord.json Everything you set here is what the Code and Prompt tabs give you.
Where it fits
- A site's headerthe switch between light and dark, remembered for the next visit
- A smart-home or IoT panellights on for a room
- An agent or devtools consolea focus-mode toggle you pull
Datasheet
- Mechanism
- Mass spring rope, Detent plunger latch, Hand spring coupling, Damped pendulum, Filament thermal model, Blackbody colour, Per pixel turned shading, Room fixed sheen, Screen blended light, Rim cutoff wall light, Finish switch, Ball chain threading, View transition reveal, Sleeping loop
- Stack
- Vanilla ES modules, Canvas 2D, CSS
- Needs
- Nothing, no dependencies
- States
- 14 documented
- Version
- 0.1.0
- Licence
- Free, source open to everyone
States
- At restThe lamp hangs plumb from its ceiling cup, the cord straight, the switch seated; the loop is asleep and costs nothing.
- LitThe filament burns at its blackbody colour, the inside of the shade glows, the rim's lip catches it, and a soft pool of warm light falls on the wall below, screen-blended onto the page, fading out before the edge of the object's box.
- DarkThe glass reads as glass: the room lamp's softbox in it, a smaller inverted reflection from the back of the envelope, the stem, leads and coil inside a clear bulb.
- TugA pull that does not reach the trip point stretches the cord out of the switch and tilts the lamp, then springs back without switching.
- PullUnder the detent the acorn visibly lags the pointer; at the trip the force drops and the acorn catches up: the snap; the lamp toggles and fires change.
- ReleaseThe plunger returns and re-arms with a softer tick, the cord bounces slack and swings, the lamp sways, and all of it settles and sleeps within about three seconds.
- Warming and coolingHeating against T⁴ radiation: on in about 130 ms through red and orange; off, a fast fade and then a dull ember that lingers.
- Keyboard and clickSpace, Enter or a click anywhere run the same physical pull, animated; the state changes when the switch trips, not when the key goes down.
- Finish switchWith a target it writes data-finish (on = aluminium, off = graphite), remembers the choice in localStorage['tui-finish'] on the page root, and follows a finish changed elsewhere.
- Ball chainWith pull: "chain" the acorn hangs on a metal ball chain: polished beads at a fixed pitch, each with its highlight and its shaded side from the room lamp and a warm glint from the bulb when lit; heavier than the cord, it swings a little longer and comes out of the switch bead by bead as it is pulled.
- RevealWith reveal and the page root as target: lights on, the light page opens out of the bulb in a soft-edged circle; lights off, it shrinks back into the bulb over the dark one, the filament's afterglow the last light left (View Transitions, 700 ms); without the API or under reduced motion it flips at once.
- Header toggleIn a 56–64 px host under a nav it hangs on a long cable with its cord and acorn drawn heavier, and keeps a 44 px grip.
- Off screen or hiddenThe loop pauses; a returning tab advances one clamped frame.
- Reduced motionThe switch still works: the state flips at once, the glow steps instead of ramping, nothing swings, and no frame is requested.
Notes
Its first job is the finish switch of a Tactile UI site (lit is aluminium, dark is graphite, remembered like the site's own key) hanging from the nav. The same switch is dark mode for any app, "lights on" for a room in a smart-home or IoT panel, or a focus-mode toggle in an agent or devtools console. It is a real role="switch" with aria-checked, a label, Space/Enter and a change event.
Original. Canvas 2D on four layers: room-lamp shadows and the bulb's light on the wall at half resolution, the lamp, and the filament's light; the two light layers are mix-blend-mode: screen, so light adds to the page instead of covering it. Physics in metres, seconds and newtons at 1/16000 s sub-steps; every turned part is shaded per pixel once per size and finish. The integrator assigns cut (0 is not a valid cut, so the field is left out).
Using it
Copy the pull-cord folder from its package next to your page, link its stylesheet and construct it on an element. The Code tab above writes the example at any settings, and for React, Vue, Svelte or a custom element (Using a framework).
Options
| Option | Type | Default | What it does |
|---|---|---|---|
| on | boolean | true | Where the switch starts. Pull the cord in the preview to change it. |
| shade | dome · tube · bare | 'dome' | A spun dome, a tube, or a bare lamp holder with its switch pod on an arm. |
| bulb | clear · frosted | 'clear' | Clear shows the filament; frosted glows all over. |
| finish | auto · aluminium · graphite | 'auto' | Auto follows the page: the lamp is made in its finish (white on a porcelain page, black on a black one); without the kit’s tokens, aluminium on a light page and graphite on a dark one. |
| warmth | number, 2200 to 3200 | 2700 | The filament’s colour temperature when fully lit. |
| cord | number, 0.6 to 1.5 | 1 | The pull cord, as a share of the lamp’s own. |
| pull | cord · chain | 'cord' | Cord: a braided textile cord. Chain: a metal ball chain, a little heavier, every bead catching the room lamp. |
| light | number, 0 to 345 | 315 | 0 is from above, clockwise. Every highlight and shadow follows it. |
| target | none · html | null | html: pulling it sets the page’s data-finish (on = aluminium, off = graphite) and remembers the choice. |
| reveal | boolean | false | With the finish switch on the page root: lights on, the light page opens out of the bulb; lights off, it shrinks back into it. Instant without View Transitions or with reduced motion. The stage here is not the page root, so it switches without it. |
| label | text | 'Light' | What a screen reader calls the switch. |
| sound | boolean | false | A synthesised snap as the switch trips. Starts only after you touch the page. |
Methods
new PullCord(element, options)- Builds it inside the element with these options.
checked- Whether the lamp is lit.
state- What the bulb is doing now, as its root's data-state.
pull()- Pull the cord: the same physical pull a hand makes, animated.
toggle()- The hand goes to where the pull hangs at rest and pulls from there, not from wherever the bounce has it: a pull while the chain still swings or springs back up must reach the trip like any other.
set(on, { instant = false } = {})- Set the lamp without a pull (no
changeevent). update(opts = {})- Change options in place.
destroy()- Stops it and cleans up after it.
Events it fires, which bubble from the element: change.
Accessibility
What its own source does: the roles it sets, the keys it answers, the ARIA it writes while it runs, and how its script and stylesheet treat reduced motion. It describes the code, and claims nothing past it.
- Roles it sets:
role="switch". - Keys it handles:
Enter,Space. - ARIA it writes while it runs:
aria-hidden,aria-checked,aria-label. - Reduced motion: its script reads
prefers-reduced-motion.