# Fridge magnet poetry

> An enamel fridge door with magnetic words you drag with a finger or move with the arrow keys to write lines of poetry.

- Category: [Text & scroll](https://library.aimran.es/components/text-scroll)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-tx-fridge-magnets
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Magnetic poetry kits turned kitchen doors into notebooks, and this block brings that game to the web. Each word is a small tilted tile on a glossy fridge door with a chrome handle; it lifts with a shadow while dragged and stays where it lands. It suits writing workshops, book festivals, brand campaigns that invite people to play and creative onboarding.

Write your phrase in the text field and the extra words in the hidden list; they become tiles automatically. The main color paints the door and the secondary one the accent tiles. Every tile is a button, so the arrow keys move it, and Shift moves it faster.

## Code

### HTML

```html
<div class="uvq14-mag"><div class="dr" role="group" aria-label="Word magnets" aria-describedby="uvq14-mag-h"><p class="sr">the sea keeps your name</p><p class="ex" hidden>slowly and today in blue salt</p><div class="ws" translate="no"></div><i class="hd" aria-hidden="true"></i></div><p class="hn" id="uvq14-mag-h">Drag the words or move them with the arrow keys</p></div>
```

### CSS

```css
.uvq14-mag {
  --c1: #9dd6c3;
  --c2: #f97316;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq14-mag {
  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;
  width: 20em;
  display: grid;
  gap: .8em;
}

.uvq14-mag .dr {
  position: relative;
  height: 13em;
  border-radius: 1.1em;
  background: linear-gradient(100deg,rgba(255,255,255,.45),transparent 30%,transparent 70%,rgba(0,0,0,.06)),var(--c1);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08),inset 0 -.4em .8em -.4em rgba(0,0,0,.15),0 1.4em 2.4em -1.4em rgba(0,0,0,.45);
}

.uvq14-mag .hd {
  position: absolute;
  right: .8em;
  top: 1.5em;
  bottom: 1.5em;
  width: .55em;
  border-radius: 1em;
  background: linear-gradient(90deg,#8d939c,#f3f4f6 40%,#b6bbc3);
  box-shadow: -.15em .2em .3em rgba(0,0,0,.2);
}

.uvq14-mag .ws {
  position: absolute;
  inset: 1em 2.2em 1em 1em;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 1.1em .7em;
}

.uvq14-mag .ws.abs {
  display: block;
}

.uvq14-mag .w {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  padding: .22em .5em .26em;
  border-radius: .12em;
  font: 500 1.12em/1.1 Georgia,"Times New Roman",serif;
  color: #111;
  background: #fffefa;
  box-shadow: 0 .08em 0 rgba(0,0,0,.18),0 .2em .3em -.1em rgba(0,0,0,.3);
  rotate: var(--r,0deg);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: rotate calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1),scale calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1),box-shadow calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq14-mag .abs .w {
  position: absolute;
}

.uvq14-mag .w:nth-child(5n+3) {
  color: #fff;
  background: var(--c2);
}

.uvq14-mag .w:hover {
  scale: 1.05;
}

.uvq14-mag .w.up {
  cursor: grabbing;
  rotate: 0deg;
  scale: 1.12;
  box-shadow: 0 .1em 0 rgba(0,0,0,.12),0 .9em 1em -.4em rgba(0,0,0,.4);
}

.uvq14-mag .w:focus-visible {
  outline: 2px solid #111;
  outline-offset: 2px;
}

.uvq14-mag .hn {
  margin: 0;
  font-size: .72em;
  font-weight: 600;
  text-align: center;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
}

.uvq14-mag .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

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

### JavaScript

```js
document.querySelectorAll(".uvq14-mag").forEach(el => {
  const ws=el.querySelector(".ws");let z=1;
const build=()=>{ws.classList.remove("abs");ws.textContent="";const words=[...el.querySelectorAll(".sr,.ex")].map(p=>p.textContent.trim()).join(" ").split(/\s+/).filter(Boolean);words.forEach((w,i)=>{const b=document.createElement("button");b.type="button";b.className="w";b.textContent=w;b.style.setProperty("--r",(((i*37)%9)-4)+"deg");ws.appendChild(b)});requestAnimationFrame(()=>{const ps=[...ws.children].map(b=>[b.offsetLeft,b.offsetTop]);ws.classList.add("abs");[...ws.children].forEach((b,i)=>{b.style.left=ps[i][0]+"px";b.style.top=ps[i][1]+"px"})})};
const move=(b,x,y)=>{b.style.left=Math.max(0,Math.min(ws.clientWidth-b.offsetWidth,x))+"px";b.style.top=Math.max(0,Math.min(ws.clientHeight-b.offsetHeight,y))+"px"};
let d=null;
ws.addEventListener("pointerdown",e=>{const b=e.target.closest(".w");if(!b)return;const r=el.getBoundingClientRect(),s=r.width/el.offsetWidth||1;d={b,s,x:e.clientX,y:e.clientY,l:b.offsetLeft,t:b.offsetTop};b.style.zIndex=++z;b.classList.add("up");b.setPointerCapture(e.pointerId)});
ws.addEventListener("pointermove",e=>{if(!d)return;move(d.b,d.l+(e.clientX-d.x)/d.s,d.t+(e.clientY-d.y)/d.s)});
const up=()=>{if(d){d.b.classList.remove("up");d=null}};ws.addEventListener("pointerup",up);ws.addEventListener("pointercancel",up);
ws.addEventListener("keydown",e=>{const b=e.target.closest(".w");const m={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[e.key];if(!b||!m)return;e.preventDefault();const k=e.shiftKey?24:6;b.style.zIndex=++z;move(b,b.offsetLeft+m[0]*k,b.offsetTop+m[1]*k)});
build();const mo=new MutationObserver(build);el.querySelectorAll(".sr,.ex").forEach(n=>mo.observe(n,{childList:true,characterData:true,subtree:true}));return()=>mo.disconnect()
});
```

### 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 = `
.uvq14-mag {
  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;
  width: 20em;
  display: grid;
  gap: .8em;
}

.uvq14-mag .dr {
  position: relative;
  height: 13em;
  border-radius: 1.1em;
  background: linear-gradient(100deg,rgba(255,255,255,.45),transparent 30%,transparent 70%,rgba(0,0,0,.06)),var(--c1);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08),inset 0 -.4em .8em -.4em rgba(0,0,0,.15),0 1.4em 2.4em -1.4em rgba(0,0,0,.45);
}

.uvq14-mag .hd {
  position: absolute;
  right: .8em;
  top: 1.5em;
  bottom: 1.5em;
  width: .55em;
  border-radius: 1em;
  background: linear-gradient(90deg,#8d939c,#f3f4f6 40%,#b6bbc3);
  box-shadow: -.15em .2em .3em rgba(0,0,0,.2);
}

.uvq14-mag .ws {
  position: absolute;
  inset: 1em 2.2em 1em 1em;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 1.1em .7em;
}

.uvq14-mag .ws.abs {
  display: block;
}

.uvq14-mag .w {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  padding: .22em .5em .26em;
  border-radius: .12em;
  font: 500 1.12em/1.1 Georgia,"Times New Roman",serif;
  color: #111;
  background: #fffefa;
  box-shadow: 0 .08em 0 rgba(0,0,0,.18),0 .2em .3em -.1em rgba(0,0,0,.3);
  rotate: var(--r,0deg);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: rotate calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1),scale calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1),box-shadow calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq14-mag .abs .w {
  position: absolute;
}

.uvq14-mag .w:nth-child(5n+3) {
  color: #fff;
  background: var(--c2);
}

.uvq14-mag .w:hover {
  scale: 1.05;
}

.uvq14-mag .w.up {
  cursor: grabbing;
  rotate: 0deg;
  scale: 1.12;
  box-shadow: 0 .1em 0 rgba(0,0,0,.12),0 .9em 1em -.4em rgba(0,0,0,.4);
}

.uvq14-mag .w:focus-visible {
  outline: 2px solid #111;
  outline-offset: 2px;
}

.uvq14-mag .hn {
  margin: 0;
  font-size: .72em;
  font-weight: 600;
  text-align: center;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
}

.uvq14-mag .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion:reduce) {
  .uvq14-mag,.uvq14-mag *,.uvq14-mag *::before,.uvq14-mag *::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 ws=el.querySelector(".ws");let z=1;
const build=()=>{ws.classList.remove("abs");ws.textContent="";const words=[...el.querySelectorAll(".sr,.ex")].map(p=>p.textContent.trim()).join(" ").split(/\s+/).filter(Boolean);words.forEach((w,i)=>{const b=document.createElement("button");b.type="button";b.className="w";b.textContent=w;b.style.setProperty("--r",(((i*37)%9)-4)+"deg");ws.appendChild(b)});requestAnimationFrame(()=>{const ps=[...ws.children].map(b=>[b.offsetLeft,b.offsetTop]);ws.classList.add("abs");[...ws.children].forEach((b,i)=>{b.style.left=ps[i][0]+"px";b.style.top=ps[i][1]+"px"})})};
const move=(b,x,y)=>{b.style.left=Math.max(0,Math.min(ws.clientWidth-b.offsetWidth,x))+"px";b.style.top=Math.max(0,Math.min(ws.clientHeight-b.offsetHeight,y))+"px"};
let d=null;
ws.addEventListener("pointerdown",e=>{const b=e.target.closest(".w");if(!b)return;const r=el.getBoundingClientRect(),s=r.width/el.offsetWidth||1;d={b,s,x:e.clientX,y:e.clientY,l:b.offsetLeft,t:b.offsetTop};b.style.zIndex=++z;b.classList.add("up");b.setPointerCapture(e.pointerId)});
ws.addEventListener("pointermove",e=>{if(!d)return;move(d.b,d.l+(e.clientX-d.x)/d.s,d.t+(e.clientY-d.y)/d.s)});
const up=()=>{if(d){d.b.classList.remove("up");d=null}};ws.addEventListener("pointerup",up);ws.addEventListener("pointercancel",up);
ws.addEventListener("keydown",e=>{const b=e.target.closest(".w");const m={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[e.key];if(!b||!m)return;e.preventDefault();const k=e.shiftKey?24:6;b.style.zIndex=++z;move(b,b.offsetLeft+m[0]*k,b.offsetTop+m[1]*k)});
build();const mo=new MutationObserver(build);el.querySelectorAll(".sr,.ex").forEach(n=>mo.observe(n,{childList:true,characterData:true,subtree:true}));return()=>mo.disconnect()
}

export default function TxFridgeMagnets() {
  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": "#9dd6c3",
          "--c2": "#f97316",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq14-mag"><div className="dr" role="group" aria-label="Word magnets" aria-describedby="uvq14-mag-h"><p className="sr">the sea keeps your name</p><p className="ex" hidden={true}>slowly and today in blue salt</p><div className="ws" translate="no"></div><i className="hd" aria-hidden="true"></i></div><p className="hn" id="uvq14-mag-h">Drag the words or move them with the arrow keys</p></div>
      </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 “Fridge magnet poetry” block (Text & scroll) from AIMRAN Library to my project.

## What it is
An enamel fridge door with magnetic words you drag with a finger or move with the arrow keys to write lines of poetry.

## Chosen settings
- Main color: #9dd6c3
- Secondary color: #f97316
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "el mar guarda tu nombre"

## 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 = `
.uvq14-mag {
  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;
  width: 20em;
  display: grid;
  gap: .8em;
}

.uvq14-mag .dr {
  position: relative;
  height: 13em;
  border-radius: 1.1em;
  background: linear-gradient(100deg,rgba(255,255,255,.45),transparent 30%,transparent 70%,rgba(0,0,0,.06)),var(--c1);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08),inset 0 -.4em .8em -.4em rgba(0,0,0,.15),0 1.4em 2.4em -1.4em rgba(0,0,0,.45);
}

.uvq14-mag .hd {
  position: absolute;
  right: .8em;
  top: 1.5em;
  bottom: 1.5em;
  width: .55em;
  border-radius: 1em;
  background: linear-gradient(90deg,#8d939c,#f3f4f6 40%,#b6bbc3);
  box-shadow: -.15em .2em .3em rgba(0,0,0,.2);
}

.uvq14-mag .ws {
  position: absolute;
  inset: 1em 2.2em 1em 1em;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 1.1em .7em;
}

.uvq14-mag .ws.abs {
  display: block;
}

.uvq14-mag .w {
  font: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  padding: .22em .5em .26em;
  border-radius: .12em;
  font: 500 1.12em/1.1 Georgia,"Times New Roman",serif;
  color: #111;
  background: #fffefa;
  box-shadow: 0 .08em 0 rgba(0,0,0,.18),0 .2em .3em -.1em rgba(0,0,0,.3);
  rotate: var(--r,0deg);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: rotate calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1),scale calc(0.25s / var(--k)) cubic-bezier(.34,1.56,.64,1),box-shadow calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq14-mag .abs .w {
  position: absolute;
}

.uvq14-mag .w:nth-child(5n+3) {
  color: #fff;
  background: var(--c2);
}

.uvq14-mag .w:hover {
  scale: 1.05;
}

.uvq14-mag .w.up {
  cursor: grabbing;
  rotate: 0deg;
  scale: 1.12;
  box-shadow: 0 .1em 0 rgba(0,0,0,.12),0 .9em 1em -.4em rgba(0,0,0,.4);
}

.uvq14-mag .w:focus-visible {
  outline: 2px solid #111;
  outline-offset: 2px;
}

.uvq14-mag .hn {
  margin: 0;
  font-size: .72em;
  font-weight: 600;
  text-align: center;
  color: color-mix(in srgb,var(--fg) 58%,transparent);
}

.uvq14-mag .sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion:reduce) {
  .uvq14-mag,.uvq14-mag *,.uvq14-mag *::before,.uvq14-mag *::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 ws=el.querySelector(".ws");let z=1;
const build=()=>{ws.classList.remove("abs");ws.textContent="";const words=[...el.querySelectorAll(".sr,.ex")].map(p=>p.textContent.trim()).join(" ").split(/\s+/).filter(Boolean);words.forEach((w,i)=>{const b=document.createElement("button");b.type="button";b.className="w";b.textContent=w;b.style.setProperty("--r",(((i*37)%9)-4)+"deg");ws.appendChild(b)});requestAnimationFrame(()=>{const ps=[...ws.children].map(b=>[b.offsetLeft,b.offsetTop]);ws.classList.add("abs");[...ws.children].forEach((b,i)=>{b.style.left=ps[i][0]+"px";b.style.top=ps[i][1]+"px"})})};
const move=(b,x,y)=>{b.style.left=Math.max(0,Math.min(ws.clientWidth-b.offsetWidth,x))+"px";b.style.top=Math.max(0,Math.min(ws.clientHeight-b.offsetHeight,y))+"px"};
let d=null;
ws.addEventListener("pointerdown",e=>{const b=e.target.closest(".w");if(!b)return;const r=el.getBoundingClientRect(),s=r.width/el.offsetWidth||1;d={b,s,x:e.clientX,y:e.clientY,l:b.offsetLeft,t:b.offsetTop};b.style.zIndex=++z;b.classList.add("up");b.setPointerCapture(e.pointerId)});
ws.addEventListener("pointermove",e=>{if(!d)return;move(d.b,d.l+(e.clientX-d.x)/d.s,d.t+(e.clientY-d.y)/d.s)});
const up=()=>{if(d){d.b.classList.remove("up");d=null}};ws.addEventListener("pointerup",up);ws.addEventListener("pointercancel",up);
ws.addEventListener("keydown",e=>{const b=e.target.closest(".w");const m={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[e.key];if(!b||!m)return;e.preventDefault();const k=e.shiftKey?24:6;b.style.zIndex=++z;move(b,b.offsetLeft+m[0]*k,b.offsetTop+m[1]*k)});
build();const mo=new MutationObserver(build);el.querySelectorAll(".sr,.ex").forEach(n=>mo.observe(n,{childList:true,characterData:true,subtree:true}));return()=>mo.disconnect()
}

export default function TxFridgeMagnets() {
  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": "#9dd6c3",
          "--c2": "#f97316",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <div className="uvq14-mag"><div className="dr" role="group" aria-label="Word magnets" aria-describedby="uvq14-mag-h"><p className="sr">the sea keeps your name</p><p className="ex" hidden={true}>slowly and today in blue salt</p><div className="ws" translate="no"></div><i className="hd" aria-hidden="true"></i></div><p className="hn" id="uvq14-mag-h">Drag the words or move them with the arrow keys</p></div>
      </div>
    </>
  );
}
```

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