# Pull cord lamp toggle

> A banker’s lamp with a pull cord: drag the bead down or tap it and the light comes on with a swing.

- Category: [Toggles](https://library.aimran.es/components/toggles)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-tg-pull-cord
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

This switch is a hanging green lamp with a small pull cord and a wooden bead. You can drag the bead down and release it, as with a real cord switch, or simply click or tap anywhere on the lamp. The bulb glows, a warm cone of light appears, and the cord swings back and forth before settling. A short script handles the drag for mouse and touch.

The main color is the shade and the second one is the light. Brass and amber give a library feel, while white and cool blue look like a modern pendant. Space still toggles it from the keyboard.

## Code

### HTML

```html
<label class="uvq03-pcd"><input type="checkbox" role="switch"><span class="lm"><i class="cn"></i><i class="cb"></i><i class="sh"></i><i class="bu"></i><span class="cd"><i class="bd"></i></span></span>Reading lamp</label>
```

### CSS

```css
.uvq03-pcd {
  --c1: #2f6f5e;
  --c2: #ffd27a;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq03-pcd {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .8em;
  cursor: pointer;
  user-select: none;
  font-weight: 550;
}

.uvq03-pcd input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.uvq03-pcd .lm {
  position: relative;
  display: block;
  flex: none;
  width: 4em;
  height: 5em;
  border-radius: .6em;
}

.uvq03-pcd .lm i {
  position: absolute;
  display: block;
}

.uvq03-pcd .cb {
  left: 50%;
  top: 0;
  width: .08em;
  height: 1.05em;
  margin-left: -.04em;
  background: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq03-pcd .sh {
  left: .6em;
  right: .6em;
  top: 1em;
  height: 1.3em;
  clip-path: polygon(30% 0,70% 0,100% 100%,0 100%);
  background: linear-gradient(90deg,color-mix(in srgb,var(--c1) 70%,#000),var(--c1) 35%,color-mix(in srgb,var(--c1) 60%,#fff) 55%,color-mix(in srgb,var(--c1) 80%,#000));
}

.uvq03-pcd .bu {
  left: 50%;
  top: 2.1em;
  width: .8em;
  height: .45em;
  margin-left: -.4em;
  border-radius: 0 0 .4em .4em;
  background: #e6e1d6;
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-pcd .cn {
  left: -.2em;
  right: -.2em;
  top: 2.25em;
  height: 2.75em;
  clip-path: polygon(34% 0,66% 0,100% 100%,0 100%);
  background: linear-gradient(180deg,color-mix(in srgb,var(--c2) 75%,transparent),transparent);
  opacity: 0;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-pcd .cd {
  position: absolute;
  left: 2.95em;
  top: 2.15em;
  width: .7em;
  height: calc(1.5em + var(--py,0px));
  margin-left: -.35em;
  transform-origin: 50% 0;
  touch-action: none;
  cursor: grab;
  transition: height calc(0.4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq03-pcd .cd::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: .4em;
  width: .05em;
  margin-left: -.025em;
  background: #9a9284;
}

.uvq03-pcd .bd {
  left: 50%;
  bottom: 0;
  width: .38em;
  height: .52em;
  margin-left: -.19em;
  border-radius: 45% 45% 50% 50%;
  background: radial-gradient(circle at 35% 30%,#ecd0a5,#9a6b3b);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-pcd:hover .bd {
  transform: scale(1.15);
}

.uvq03-pcd.pl .cd {
  transition: none;
  cursor: grabbing;
}

.uvq03-pcd.sw .cd {
  animation: uvq03-pcd calc(1.2s / var(--k)) ease-out;
}

@keyframes uvq03-pcd {
  15% {
    transform: rotate(14deg);
  }
  35% {
    transform: rotate(-9deg);
  }
  55% {
    transform: rotate(5deg);
  }
  75% {
    transform: rotate(-2deg);
  }
}

.uvq03-pcd input:checked + .lm .cn {
  opacity: 1;
}

.uvq03-pcd input:checked + .lm .bu {
  background: #fff8e1;
  box-shadow: 0 0 .6em .25em var(--c2);
}

.uvq03-pcd input:focus-visible + .lm {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq03-pcd,.uvq03-pcd *,.uvq03-pcd *::before,.uvq03-pcd *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
```

### JavaScript

```js
document.querySelectorAll(".uvq03-pcd").forEach(el => {
  const i=el.querySelector("input"),c=el.querySelector(".cd");let y0=0,dy=0,on=false,skip=0;
const sw=()=>{el.classList.remove("sw");void el.offsetWidth;el.classList.add("sw")};
const down=(e)=>{on=true;y0=e.clientY;dy=0;c.setPointerCapture(e.pointerId);el.classList.add("pl")};
const move=(e)=>{if(!on)return;dy=Math.max(0,Math.min(30,e.clientY-y0));el.style.setProperty("--py",dy+"px")};
const up=()=>{if(!on)return;on=false;el.classList.remove("pl");el.style.setProperty("--py","0px");if(dy>4){skip=Date.now();if(dy>14){i.checked=!i.checked;i.dispatchEvent(new Event("change",{bubbles:true}))}}};
const clk=(e)=>{if(Date.now()-skip<500)e.preventDefault()};
c.addEventListener("pointerdown",down);c.addEventListener("pointermove",move);c.addEventListener("pointerup",up);c.addEventListener("pointercancel",up);el.addEventListener("click",clk);i.addEventListener("change",sw);
return()=>{c.removeEventListener("pointerdown",down);c.removeEventListener("pointermove",move);c.removeEventListener("pointerup",up);c.removeEventListener("pointercancel",up);el.removeEventListener("click",clk);i.removeEventListener("change",sw)}
});
```

### React

```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq03-pcd {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .8em;
  cursor: pointer;
  user-select: none;
  font-weight: 550;
}

.uvq03-pcd input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.uvq03-pcd .lm {
  position: relative;
  display: block;
  flex: none;
  width: 4em;
  height: 5em;
  border-radius: .6em;
}

.uvq03-pcd .lm i {
  position: absolute;
  display: block;
}

.uvq03-pcd .cb {
  left: 50%;
  top: 0;
  width: .08em;
  height: 1.05em;
  margin-left: -.04em;
  background: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq03-pcd .sh {
  left: .6em;
  right: .6em;
  top: 1em;
  height: 1.3em;
  clip-path: polygon(30% 0,70% 0,100% 100%,0 100%);
  background: linear-gradient(90deg,color-mix(in srgb,var(--c1) 70%,#000),var(--c1) 35%,color-mix(in srgb,var(--c1) 60%,#fff) 55%,color-mix(in srgb,var(--c1) 80%,#000));
}

.uvq03-pcd .bu {
  left: 50%;
  top: 2.1em;
  width: .8em;
  height: .45em;
  margin-left: -.4em;
  border-radius: 0 0 .4em .4em;
  background: #e6e1d6;
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-pcd .cn {
  left: -.2em;
  right: -.2em;
  top: 2.25em;
  height: 2.75em;
  clip-path: polygon(34% 0,66% 0,100% 100%,0 100%);
  background: linear-gradient(180deg,color-mix(in srgb,var(--c2) 75%,transparent),transparent);
  opacity: 0;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-pcd .cd {
  position: absolute;
  left: 2.95em;
  top: 2.15em;
  width: .7em;
  height: calc(1.5em + var(--py,0px));
  margin-left: -.35em;
  transform-origin: 50% 0;
  touch-action: none;
  cursor: grab;
  transition: height calc(0.4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq03-pcd .cd::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: .4em;
  width: .05em;
  margin-left: -.025em;
  background: #9a9284;
}

.uvq03-pcd .bd {
  left: 50%;
  bottom: 0;
  width: .38em;
  height: .52em;
  margin-left: -.19em;
  border-radius: 45% 45% 50% 50%;
  background: radial-gradient(circle at 35% 30%,#ecd0a5,#9a6b3b);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-pcd:hover .bd {
  transform: scale(1.15);
}

.uvq03-pcd.pl .cd {
  transition: none;
  cursor: grabbing;
}

.uvq03-pcd.sw .cd {
  animation: uvq03-pcd calc(1.2s / var(--k)) ease-out;
}

@keyframes uvq03-pcd {
  15% {
    transform: rotate(14deg);
  }
  35% {
    transform: rotate(-9deg);
  }
  55% {
    transform: rotate(5deg);
  }
  75% {
    transform: rotate(-2deg);
  }
}

.uvq03-pcd input:checked + .lm .cn {
  opacity: 1;
}

.uvq03-pcd input:checked + .lm .bu {
  background: #fff8e1;
  box-shadow: 0 0 .6em .25em var(--c2);
}

.uvq03-pcd input:focus-visible + .lm {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq03-pcd,.uvq03-pcd *,.uvq03-pcd *::before,.uvq03-pcd *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const i=el.querySelector("input"),c=el.querySelector(".cd");let y0=0,dy=0,on=false,skip=0;
const sw=()=>{el.classList.remove("sw");void el.offsetWidth;el.classList.add("sw")};
const down=(e)=>{on=true;y0=e.clientY;dy=0;c.setPointerCapture(e.pointerId);el.classList.add("pl")};
const move=(e)=>{if(!on)return;dy=Math.max(0,Math.min(30,e.clientY-y0));el.style.setProperty("--py",dy+"px")};
const up=()=>{if(!on)return;on=false;el.classList.remove("pl");el.style.setProperty("--py","0px");if(dy>4){skip=Date.now();if(dy>14){i.checked=!i.checked;i.dispatchEvent(new Event("change",{bubbles:true}))}}};
const clk=(e)=>{if(Date.now()-skip<500)e.preventDefault()};
c.addEventListener("pointerdown",down);c.addEventListener("pointermove",move);c.addEventListener("pointerup",up);c.addEventListener("pointercancel",up);el.addEventListener("click",clk);i.addEventListener("change",sw);
return()=>{c.removeEventListener("pointerdown",down);c.removeEventListener("pointermove",move);c.removeEventListener("pointerup",up);c.removeEventListener("pointercancel",up);el.removeEventListener("click",clk);i.removeEventListener("change",sw)}
}

export default function TgPullCord() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#2f6f5e",
          "--c2": "#ffd27a",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uvq03-pcd"><input type="checkbox" role="switch" /><span className="lm"><i className="cn"></i><i className="cb"></i><i className="sh"></i><i className="bu"></i><span className="cd"><i className="bd"></i></span></span>Reading lamp</label>
      </div>
    </>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Pull cord lamp toggle” block (Toggles) from AIMRAN Library to my project.

## What it is
A banker’s lamp with a pull cord: drag the bead down or tap it and the light comes on with a swing.

## Chosen settings
- Main color: #2f6f5e
- Secondary color: #ffd27a
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Lámpara de lectura"

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with plain HTML and CSS (the reference wraps it in a React component with its CSS). If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
// @ts-nocheck: setup() es JavaScript del DOM sin tipos, el mismo de la pestaña JS.
import { useEffect, useRef, type CSSProperties } from "react";

const css = `
.uvq03-pcd {
  font-family: -apple-system,BlinkMacSystemFont,"SF Pro Text","Inter",system-ui,sans-serif;
  font-size: var(--s);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .8em;
  cursor: pointer;
  user-select: none;
  font-weight: 550;
}

.uvq03-pcd input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.uvq03-pcd .lm {
  position: relative;
  display: block;
  flex: none;
  width: 4em;
  height: 5em;
  border-radius: .6em;
}

.uvq03-pcd .lm i {
  position: absolute;
  display: block;
}

.uvq03-pcd .cb {
  left: 50%;
  top: 0;
  width: .08em;
  height: 1.05em;
  margin-left: -.04em;
  background: color-mix(in srgb,var(--fg) 55%,transparent);
}

.uvq03-pcd .sh {
  left: .6em;
  right: .6em;
  top: 1em;
  height: 1.3em;
  clip-path: polygon(30% 0,70% 0,100% 100%,0 100%);
  background: linear-gradient(90deg,color-mix(in srgb,var(--c1) 70%,#000),var(--c1) 35%,color-mix(in srgb,var(--c1) 60%,#fff) 55%,color-mix(in srgb,var(--c1) 80%,#000));
}

.uvq03-pcd .bu {
  left: 50%;
  top: 2.1em;
  width: .8em;
  height: .45em;
  margin-left: -.4em;
  border-radius: 0 0 .4em .4em;
  background: #e6e1d6;
  transition: background calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-pcd .cn {
  left: -.2em;
  right: -.2em;
  top: 2.25em;
  height: 2.75em;
  clip-path: polygon(34% 0,66% 0,100% 100%,0 100%);
  background: linear-gradient(180deg,color-mix(in srgb,var(--c2) 75%,transparent),transparent);
  opacity: 0;
  transition: opacity calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-pcd .cd {
  position: absolute;
  left: 2.95em;
  top: 2.15em;
  width: .7em;
  height: calc(1.5em + var(--py,0px));
  margin-left: -.35em;
  transform-origin: 50% 0;
  touch-action: none;
  cursor: grab;
  transition: height calc(0.4s / var(--k)) cubic-bezier(.34,1.56,.64,1);
}

.uvq03-pcd .cd::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: .4em;
  width: .05em;
  margin-left: -.025em;
  background: #9a9284;
}

.uvq03-pcd .bd {
  left: 50%;
  bottom: 0;
  width: .38em;
  height: .52em;
  margin-left: -.19em;
  border-radius: 45% 45% 50% 50%;
  background: radial-gradient(circle at 35% 30%,#ecd0a5,#9a6b3b);
  transition: transform calc(0.2s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq03-pcd:hover .bd {
  transform: scale(1.15);
}

.uvq03-pcd.pl .cd {
  transition: none;
  cursor: grabbing;
}

.uvq03-pcd.sw .cd {
  animation: uvq03-pcd calc(1.2s / var(--k)) ease-out;
}

@keyframes uvq03-pcd {
  15% {
    transform: rotate(14deg);
  }
  35% {
    transform: rotate(-9deg);
  }
  55% {
    transform: rotate(5deg);
  }
  75% {
    transform: rotate(-2deg);
  }
}

.uvq03-pcd input:checked + .lm .cn {
  opacity: 1;
}

.uvq03-pcd input:checked + .lm .bu {
  background: #fff8e1;
  box-shadow: 0 0 .6em .25em var(--c2);
}

.uvq03-pcd input:focus-visible + .lm {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq03-pcd,.uvq03-pcd *,.uvq03-pcd *::before,.uvq03-pcd *::after {
    animation-duration: .01ms!important;
    animation-iteration-count: 1!important;
    transition-duration: .01ms!important;
  }
}
`;

// Interacción en JavaScript del DOM: la misma que en la pestaña JS.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setup(el: any) {
  const i=el.querySelector("input"),c=el.querySelector(".cd");let y0=0,dy=0,on=false,skip=0;
const sw=()=>{el.classList.remove("sw");void el.offsetWidth;el.classList.add("sw")};
const down=(e)=>{on=true;y0=e.clientY;dy=0;c.setPointerCapture(e.pointerId);el.classList.add("pl")};
const move=(e)=>{if(!on)return;dy=Math.max(0,Math.min(30,e.clientY-y0));el.style.setProperty("--py",dy+"px")};
const up=()=>{if(!on)return;on=false;el.classList.remove("pl");el.style.setProperty("--py","0px");if(dy>4){skip=Date.now();if(dy>14){i.checked=!i.checked;i.dispatchEvent(new Event("change",{bubbles:true}))}}};
const clk=(e)=>{if(Date.now()-skip<500)e.preventDefault()};
c.addEventListener("pointerdown",down);c.addEventListener("pointermove",move);c.addEventListener("pointerup",up);c.addEventListener("pointercancel",up);el.addEventListener("click",clk);i.addEventListener("change",sw);
return()=>{c.removeEventListener("pointerdown",down);c.removeEventListener("pointermove",move);c.removeEventListener("pointerup",up);c.removeEventListener("pointercancel",up);el.removeEventListener("click",clk);i.removeEventListener("change",sw)}
}

export default function TgPullCord() {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current?.firstElementChild;
    return el ? setup(el) : undefined;
  }, []);

  return (
    <>
      <style>{css}</style>
      <div
        ref={ref} style={{
          "--c1": "#2f6f5e",
          "--c2": "#ffd27a",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uvq03-pcd"><input type="checkbox" role="switch" /><span className="lm"><i className="cn"></i><i className="cb"></i><i className="sh"></i><i className="bu"></i><span className="cd"><i className="bd"></i></span></span>Reading lamp</label>
      </div>
    </>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
