# Resend cooldown

Subtle web animation sketch from [https://mighil.com/animations](https://mighil.com/animations).

- **Live demo:** https://mighil.com/animations/resend-cooldown
- **Standalone HTML:** https://mighil.com/animations/resend-cooldown?download=1
- **This file:** https://mighil.com/animations/resend-cooldown/resend-cooldown.md
- **Technique:** `wait`

## What it does

After send, the border traces while the cooldown runs.

## Instructions for AI / coding agents

Implement this micro-interaction in the user's stack (vanilla HTML, React, Vue, Svelte, etc.).

1. Use the **HTML** as the DOM structure (adapt JSX/templates as needed; keep class names and ids).
2. Include the **Theme** CSS (or map the same variables into the host design system). It switches light/dark with `prefers-color-scheme`.
3. Apply the **CSS** as-is when possible. It uses `var(--text-color)`, `var(--heading-color)`, `var(--background-color)`, etc. from the theme so both modes work.
4. Run the **JavaScript** after the markup mounts. Prefer `DOMContentLoaded` or a framework `useEffect` / `onMount`.
5. Keep motion respectful of `prefers-reduced-motion` if the snippet already checks it.
6. Do not depend on mighil.com runtime or fonts. Theme variables are enough for color.
7. If porting to a component, expose the interactive root via a ref and preserve accessibility attributes (`aria-*`, `role`, `button` types).

## Theme (auto light / dark)

```css
/* Auto light / dark — follows prefers-color-scheme */
:root{
  color-scheme: light dark;
  --text-color: hsl(0, 0%, 18%);
  --heading-color: hsl(0, 0%, 18%);
  --background-color: hsl(0, 0%, 99%);
  --bg-color: hsl(0, 0%, 99%);
  --link-color: hsl(0, 0%, 18%);
  --visited-color: hsl(0, 0%, 18%);
  --blockquote-color: hsl(0, 0%, 18%);
  --code-bg-color: hsl(0, 0%, 95%);
  --code-color: hsl(0, 0%, 18%);
  --sub-color: hsl(0, 0%, 29%);
}
@media (prefers-color-scheme: dark){
:root{
  --text-color: hsl(35, 25%, 85%);
  --heading-color: hsl(35.2, 32.6%, 82.5%);
  --background-color: hsl(60, 2.2%, 8.8%);
  --bg-color: hsl(60, 2.2%, 8.8%);
  --link-color: hsl(34.7, 55.3%, 79.8%);
  --visited-color: hsla(34.7, 55.3%, 79.8%, 0.85);
  --blockquote-color: hsl(35, 30%, 75%);
  --code-bg-color: hsl(30, 5%, 7.8%);
  --code-color: limegreen;
  --sub-color: hsla(34.7, 24.7%, 84.9%, 0.78);
}
}
```

## HTML

```html
<button type="button" class="resend-btn" id="resend-btn">
        <i class="resend-ring" aria-hidden="true"></i>
        <span class="resend-txt">Resend code</span>
      </button>
```

## CSS

```css
.resend-btn{
  appearance:none;-webkit-appearance:none;position:relative;
  height:40px;min-width:132px;padding:0 16px;border-radius:8px;cursor:pointer;
  font:inherit;font-size:.88rem;font-weight:500;line-height:1;color:inherit;
  border:1px solid color-mix(in srgb,var(--text-color) 14%,transparent);
  background:color-mix(in srgb,var(--text-color) 4%,transparent);
}

.resend-btn:disabled{cursor:default}

.resend-btn.is-wait{
  cursor:default;
  color:color-mix(in srgb,var(--text-color) 48%,transparent);
  background:color-mix(in srgb,var(--text-color) 2.5%,transparent);
  border-color:color-mix(in srgb,var(--text-color) 8%,transparent);
}

.resend-btn .resend-ring{
  position:absolute;inset:-1px;border-radius:9px;padding:1px;box-sizing:border-box;
  pointer-events:none;opacity:0;
  color:var(--text-color);
  background:conic-gradient(from -90deg, currentColor calc(var(--p, 0) * 1%), transparent 0);
  -webkit-mask:linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0);
  -webkit-mask-composite:xor;
  mask:linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0);
  mask-composite:exclude;
  transition:opacity .2s ease;
}

.resend-btn.is-wait .resend-ring{opacity:.8}

.resend-btn .resend-txt{position:relative;z-index:1}
```

## JavaScript

```js
// Resend cooldown
  const resendBtn = document.getElementById('resend-btn');
  let resendTimer = null;
  let resendRaf = 0;
  function resetResend() {
    if (!resendBtn) return;
    clearInterval(resendTimer);
    cancelAnimationFrame(resendRaf);
    resendBtn.disabled = false;
    resendBtn.classList.remove('is-wait');
    resendBtn.style.setProperty('--p', '0');
    const t = resendBtn.querySelector('.resend-txt');
    if (t) t.textContent = 'Resend code';
  }
  function startResend() {
    if (!resendBtn || resendBtn.disabled) return;
    const total = reduce ? 400 : 10000;
    const start = performance.now();
    resendBtn.disabled = true;
    resendBtn.classList.add('is-wait');
    const tick = (now) => {
      const p = Math.min(1, (now - start) / total);
      resendBtn.style.setProperty('--p', String(p * 100));
      const left = Math.ceil((total - (now - start)) / 1000);
      const t = resendBtn.querySelector('.resend-txt');
      if (t) t.textContent = left > 0 ? 'Wait ' + left + 's' : 'Resend code';
      if (p < 1) resendRaf = requestAnimationFrame(tick);
      else {
        resendBtn.disabled = false;
        resendBtn.classList.remove('is-wait');
        resendBtn.style.setProperty('--p', '0');
      }
    };
    resendRaf = requestAnimationFrame(tick);
  }
  if (resendBtn) resendBtn.addEventListener('click', startResend);

document.querySelectorAll('[data-act]').forEach((btn) => {
    btn.addEventListener('click', (e) => {
      e.stopPropagation();
      const act = btn.getAttribute('data-act');
      if (act === 'resend') resetResend();
    });
  });
```

---

_Source: https://mighil.com/animations/resend-cooldown_
