# Swipe to complete row

> A list row you check by dragging it to the right and uncheck by dragging left, or with the arrow keys.

- Category: [Checkboxes](https://library.aimran.es/components/checkboxes)
- Built with: HTML + CSS
- Live editor: https://library.aimran.es/blocks/uv-chk-swipe
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Borrowed from mail and task apps, this checkbox is a whole list row with a status circle, a title, a hint and a time. Dragging it to the right reveals a green done panel and checks it, dragging left reveals undo and unchecks it, and a simple tap toggles it too. Arrow keys, Space and Enter work from the keyboard. It suits to-do lists, inboxes, delivery apps and mobile dashboards.

The main color is the done panel and the tick, the secondary color the undo side. The swipe threshold is about a third of the row width, so it feels intentional on phones without being hard to reach on desktop.

## Code

### HTML

```html
<label class="uvq02-swp"><input type="checkbox"><span class="bg" aria-hidden="true"><span class="l"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1"/></svg>Done</span><span class="r">Undo</span></span><span class="fg"><span class="dt" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1"/></svg></span><span class="tx"><b>Reply to Marta</b><small aria-hidden="true">Swipe to check</small></span><span class="tm" aria-hidden="true">09:40</span></span></label>
```

### CSS

```css
.uvq02-swp {
  --c1: #1fae6a;
  --c2: #8a8f98;
  --s: 16px;
  /* tamaño */
  --k: 1;
  /* velocidad */
  --fg: #1d1d1f;
  /* texto */
  --bg: #f5f5f7;
  /* fondo */
}

.uvq02-swp {
  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: block;
  width: 18em;
  border-radius: 1em;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent),0 .8em 1.6em -1.2em rgba(0,0,0,.5);
}

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

.uvq02-swp .bg {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.1em;
  font-size: .85em;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg,var(--c1) 50%,var(--c2) 50%);
}

.uvq02-swp .l {
  display: flex;
  align-items: center;
  gap: .4em;
}

.uvq02-swp .l svg {
  width: 1.2em;
  height: 1.2em;
}

.uvq02-swp .fg {
  position: relative;
  display: flex;
  align-items: center;
  gap: .8em;
  padding: .85em 1em;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  transition: transform calc(0.45s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq02-swp.dr .fg {
  transition: none;
}

.uvq02-swp .dt {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.4em;
  height: 1.4em;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px color-mix(in srgb,var(--fg) 24%,transparent);
  color: #fff;
  transition: background calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq02-swp .dt svg {
  width: .85em;
  height: .85em;
}

.uvq02-swp .dt path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq02-swp .tx {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .15em;
}

.uvq02-swp b {
  font-weight: 650;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq02-swp small {
  font-size: .72em;
  color: color-mix(in srgb,var(--fg) 50%,transparent);
}

.uvq02-swp .tm {
  align-self: flex-start;
  font-size: .75em;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb,var(--fg) 45%,transparent);
}

.uvq02-swp:hover input:not(:checked) ~ .fg {
  transform: translateX(.7em);
}

.uvq02-swp:hover input:checked ~ .fg {
  transform: translateX(-.7em);
}

.uvq02-swp input:checked ~ .fg .dt {
  background: var(--c1);
  box-shadow: inset 0 0 0 2px var(--c1);
}

.uvq02-swp input:checked ~ .fg .dt path {
  stroke-dashoffset: 0;
}

.uvq02-swp input:checked ~ .fg b {
  opacity: .5;
  text-decoration: line-through 1.5px;
}

.uvq02-swp:has(input:focus-visible) {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

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

### JavaScript

```js
document.querySelectorAll(".uvq02-swp").forEach(el => {
  const i = el.querySelector("input");
  const f = el.querySelector(".fg");
  let x0 = null, dx = 0, mv = false;
  const set = (v) => { if (i.checked !== v) { i.checked = v; i.dispatchEvent(new Event("change", { bubbles: true })); } };
  el.addEventListener("pointerdown", (e) => { x0 = e.clientX; dx = 0; mv = false; });
  el.addEventListener("pointermove", (e) => {
    if (x0 === null) return;
    dx = e.clientX - x0;
    if (!mv && Math.abs(dx) > 6) { mv = true; el.classList.add("dr"); el.setPointerCapture(e.pointerId); }
    if (mv) { const w = el.offsetWidth; f.style.transform = "translateX(" + Math.max(-w * 0.6, Math.min(w * 0.6, dx)) + "px)"; }
  });
  const up = () => {
    if (x0 === null) return;
    if (mv) { const w = el.offsetWidth; if (dx > w * 0.3) set(true); else if (dx < -w * 0.3) set(false); }
    x0 = null; f.style.transform = ""; el.classList.remove("dr");
  };
  el.addEventListener("pointerup", up);
  el.addEventListener("pointercancel", up);
  el.addEventListener("click", (e) => { if (mv) { e.preventDefault(); mv = false; } }, true);
  i.addEventListener("keydown", (e) => {
    if (e.key === "ArrowRight") { e.preventDefault(); set(true); }
    else if (e.key === "ArrowLeft") { e.preventDefault(); set(false); }
    else if (e.key === "Enter") { e.preventDefault(); set(!i.checked); }
  });
});
```

### 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 = `
.uvq02-swp {
  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: block;
  width: 18em;
  border-radius: 1em;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent),0 .8em 1.6em -1.2em rgba(0,0,0,.5);
}

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

.uvq02-swp .bg {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.1em;
  font-size: .85em;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg,var(--c1) 50%,var(--c2) 50%);
}

.uvq02-swp .l {
  display: flex;
  align-items: center;
  gap: .4em;
}

.uvq02-swp .l svg {
  width: 1.2em;
  height: 1.2em;
}

.uvq02-swp .fg {
  position: relative;
  display: flex;
  align-items: center;
  gap: .8em;
  padding: .85em 1em;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  transition: transform calc(0.45s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq02-swp.dr .fg {
  transition: none;
}

.uvq02-swp .dt {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.4em;
  height: 1.4em;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px color-mix(in srgb,var(--fg) 24%,transparent);
  color: #fff;
  transition: background calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq02-swp .dt svg {
  width: .85em;
  height: .85em;
}

.uvq02-swp .dt path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq02-swp .tx {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .15em;
}

.uvq02-swp b {
  font-weight: 650;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq02-swp small {
  font-size: .72em;
  color: color-mix(in srgb,var(--fg) 50%,transparent);
}

.uvq02-swp .tm {
  align-self: flex-start;
  font-size: .75em;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb,var(--fg) 45%,transparent);
}

.uvq02-swp:hover input:not(:checked) ~ .fg {
  transform: translateX(.7em);
}

.uvq02-swp:hover input:checked ~ .fg {
  transform: translateX(-.7em);
}

.uvq02-swp input:checked ~ .fg .dt {
  background: var(--c1);
  box-shadow: inset 0 0 0 2px var(--c1);
}

.uvq02-swp input:checked ~ .fg .dt path {
  stroke-dashoffset: 0;
}

.uvq02-swp input:checked ~ .fg b {
  opacity: .5;
  text-decoration: line-through 1.5px;
}

.uvq02-swp:has(input:focus-visible) {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq02-swp,.uvq02-swp *,.uvq02-swp *::before,.uvq02-swp *::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");
  const f = el.querySelector(".fg");
  let x0 = null, dx = 0, mv = false;
  const set = (v) => { if (i.checked !== v) { i.checked = v; i.dispatchEvent(new Event("change", { bubbles: true })); } };
  el.addEventListener("pointerdown", (e) => { x0 = e.clientX; dx = 0; mv = false; });
  el.addEventListener("pointermove", (e) => {
    if (x0 === null) return;
    dx = e.clientX - x0;
    if (!mv && Math.abs(dx) > 6) { mv = true; el.classList.add("dr"); el.setPointerCapture(e.pointerId); }
    if (mv) { const w = el.offsetWidth; f.style.transform = "translateX(" + Math.max(-w * 0.6, Math.min(w * 0.6, dx)) + "px)"; }
  });
  const up = () => {
    if (x0 === null) return;
    if (mv) { const w = el.offsetWidth; if (dx > w * 0.3) set(true); else if (dx < -w * 0.3) set(false); }
    x0 = null; f.style.transform = ""; el.classList.remove("dr");
  };
  el.addEventListener("pointerup", up);
  el.addEventListener("pointercancel", up);
  el.addEventListener("click", (e) => { if (mv) { e.preventDefault(); mv = false; } }, true);
  i.addEventListener("keydown", (e) => {
    if (e.key === "ArrowRight") { e.preventDefault(); set(true); }
    else if (e.key === "ArrowLeft") { e.preventDefault(); set(false); }
    else if (e.key === "Enter") { e.preventDefault(); set(!i.checked); }
  });
}

export default function ChkSwipe() {
  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": "#1fae6a",
          "--c2": "#8a8f98",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uvq02-swp"><input type="checkbox" /><span className="bg" aria-hidden="true"><span className="l"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1" /></svg>Done</span><span className="r">Undo</span></span><span className="fg"><span className="dt" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1" /></svg></span><span className="tx"><b>Reply to Marta</b><small aria-hidden="true">Swipe to check</small></span><span className="tm" aria-hidden="true">09:40</span></span></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 “Swipe to complete row” block (Checkboxes) from AIMRAN Library to my project.

## What it is
A list row you check by dragging it to the right and uncheck by dragging left, or with the arrow keys.

## Chosen settings
- Main color: #1fae6a
- Secondary color: #8a8f98
- Size: 16px (from 12 to 24px)
- Speed: 1x (from 0.5 to 2x)
- Text: "Responder a Marta"

## 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 = `
.uvq02-swp {
  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: block;
  width: 18em;
  border-radius: 1em;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  box-shadow: 0 0 0 1px color-mix(in srgb,var(--fg) 9%,transparent),0 .8em 1.6em -1.2em rgba(0,0,0,.5);
}

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

.uvq02-swp .bg {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.1em;
  font-size: .85em;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg,var(--c1) 50%,var(--c2) 50%);
}

.uvq02-swp .l {
  display: flex;
  align-items: center;
  gap: .4em;
}

.uvq02-swp .l svg {
  width: 1.2em;
  height: 1.2em;
}

.uvq02-swp .fg {
  position: relative;
  display: flex;
  align-items: center;
  gap: .8em;
  padding: .85em 1em;
  background: color-mix(in srgb,var(--fg) 3%,var(--bg));
  transition: transform calc(0.45s / var(--k)) cubic-bezier(.22,1,.36,1);
}

.uvq02-swp.dr .fg {
  transition: none;
}

.uvq02-swp .dt {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.4em;
  height: 1.4em;
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px color-mix(in srgb,var(--fg) 24%,transparent);
  color: #fff;
  transition: background calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1),box-shadow calc(0.25s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq02-swp .dt svg {
  width: .85em;
  height: .85em;
}

.uvq02-swp .dt path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq02-swp .tx {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .15em;
}

.uvq02-swp b {
  font-weight: 650;
  transition: opacity calc(0.3s / var(--k)) cubic-bezier(.25,.1,.25,1);
}

.uvq02-swp small {
  font-size: .72em;
  color: color-mix(in srgb,var(--fg) 50%,transparent);
}

.uvq02-swp .tm {
  align-self: flex-start;
  font-size: .75em;
  font-variant-numeric: tabular-nums;
  color: color-mix(in srgb,var(--fg) 45%,transparent);
}

.uvq02-swp:hover input:not(:checked) ~ .fg {
  transform: translateX(.7em);
}

.uvq02-swp:hover input:checked ~ .fg {
  transform: translateX(-.7em);
}

.uvq02-swp input:checked ~ .fg .dt {
  background: var(--c1);
  box-shadow: inset 0 0 0 2px var(--c1);
}

.uvq02-swp input:checked ~ .fg .dt path {
  stroke-dashoffset: 0;
}

.uvq02-swp input:checked ~ .fg b {
  opacity: .5;
  text-decoration: line-through 1.5px;
}

.uvq02-swp:has(input:focus-visible) {
  outline: 2px solid var(--c1);
  outline-offset: 3px;
}

@media (prefers-reduced-motion:reduce) {
  .uvq02-swp,.uvq02-swp *,.uvq02-swp *::before,.uvq02-swp *::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");
  const f = el.querySelector(".fg");
  let x0 = null, dx = 0, mv = false;
  const set = (v) => { if (i.checked !== v) { i.checked = v; i.dispatchEvent(new Event("change", { bubbles: true })); } };
  el.addEventListener("pointerdown", (e) => { x0 = e.clientX; dx = 0; mv = false; });
  el.addEventListener("pointermove", (e) => {
    if (x0 === null) return;
    dx = e.clientX - x0;
    if (!mv && Math.abs(dx) > 6) { mv = true; el.classList.add("dr"); el.setPointerCapture(e.pointerId); }
    if (mv) { const w = el.offsetWidth; f.style.transform = "translateX(" + Math.max(-w * 0.6, Math.min(w * 0.6, dx)) + "px)"; }
  });
  const up = () => {
    if (x0 === null) return;
    if (mv) { const w = el.offsetWidth; if (dx > w * 0.3) set(true); else if (dx < -w * 0.3) set(false); }
    x0 = null; f.style.transform = ""; el.classList.remove("dr");
  };
  el.addEventListener("pointerup", up);
  el.addEventListener("pointercancel", up);
  el.addEventListener("click", (e) => { if (mv) { e.preventDefault(); mv = false; } }, true);
  i.addEventListener("keydown", (e) => {
    if (e.key === "ArrowRight") { e.preventDefault(); set(true); }
    else if (e.key === "ArrowLeft") { e.preventDefault(); set(false); }
    else if (e.key === "Enter") { e.preventDefault(); set(!i.checked); }
  });
}

export default function ChkSwipe() {
  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": "#1fae6a",
          "--c2": "#8a8f98",
          "--s": "16px",
          "--k": "1",
          "--fg": "#1d1d1f",
          "--bg": "#f5f5f7",
        } as CSSProperties}
      >
        <label className="uvq02-swp"><input type="checkbox" /><span className="bg" aria-hidden="true"><span className="l"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1" /></svg>Done</span><span className="r">Undo</span></span><span className="fg"><span className="dt" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5" pathLength="1" /></svg></span><span className="tx"><b>Reply to Marta</b><small aria-hidden="true">Swipe to check</small></span><span className="tm" aria-hidden="true">09:40</span></span></label>
      </div>
    </>
  );
}
```

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