{
  "format": "css.observer/playground@1",
  "id": "de0ae442-f431-5aee-b091-14b75ba88376",
  "url": "https://css.observer/s/resend-cooldown",
  "title": "Resend cooldown",
  "description": "After send, the border traces while the cooldown runs.",
  "category": "animations",
  "tags": [
    "wait",
    "micro-interaction"
  ],
  "visibility": "public",
  "status": "published",
  "revision": 1,
  "author": "mighil",
  "forked_from": null,
  "created_at": "2026-12-02T11:59:29.000Z",
  "updated_at": "2026-12-02T11:59:29.000Z",
  "published_at": "2026-12-02T11:59:29.000Z",
  "source": {
    "html": "<button type=\"button\" class=\"resend-btn\" id=\"resend-btn\">\n        <i class=\"resend-ring\" aria-hidden=\"true\"></i>\n        <span class=\"resend-txt\">Resend code</span>\n      </button>\n",
    "css": "/* Auto light / dark — follows prefers-color-scheme */\n:root{\n  color-scheme: light dark;\n  --text-color: hsl(0, 0%, 18%);\n  --heading-color: hsl(0, 0%, 18%);\n  --background-color: hsl(0, 0%, 99%);\n  --bg-color: hsl(0, 0%, 99%);\n  --link-color: hsl(0, 0%, 18%);\n  --visited-color: hsl(0, 0%, 18%);\n  --blockquote-color: hsl(0, 0%, 18%);\n  --code-bg-color: hsl(0, 0%, 95%);\n  --code-color: hsl(0, 0%, 18%);\n  --sub-color: hsl(0, 0%, 29%);\n}\n@media (prefers-color-scheme: dark){\n:root{\n  --text-color: hsla(0, 0%, 93%, 1);\n  --heading-color: hsla(0, 0%, 93%, 1);\n  --background-color: hsla(0, 0%, 0%, 1);\n  --bg-color: hsla(0, 0%, 0%, 1);\n  --link-color: hsla(0, 0%, 93%, 1);\n  --visited-color: hsla(0, 0%, 93%, 0.85);\n  --blockquote-color: hsla(0, 0%, 93%, 1);\n  --code-bg-color: hsla(0, 0%, 8%, 1);\n  --code-color: limegreen;\n  --sub-color: hsla(0, 0%, 93%, 0.78);\n}\n}\n\n/* Preview layout */\nbody {\n  margin: 0;\n  min-height: 100vh;\n  display: grid;\n  place-items: center;\n  padding: 24px;\n  box-sizing: border-box;\n  background: var(--background-color);\n  color: var(--text-color);\n  font: 15px/1.5 system-ui, -apple-system, \"Segoe UI\", sans-serif;\n}\n\n.resend-btn{\n  appearance:none;-webkit-appearance:none;position:relative;\n  height:40px;min-width:132px;padding:0 16px;border-radius:8px;cursor:pointer;\n  font:inherit;font-size:.88rem;font-weight:500;line-height:1;color:inherit;\n  border:1px solid color-mix(in srgb,var(--text-color) 14%,transparent);\n  background:color-mix(in srgb,var(--text-color) 4%,transparent);\n}\n\n.resend-btn:disabled{cursor:default}\n\n.resend-btn.is-wait{\n  cursor:default;\n  color:color-mix(in srgb,var(--text-color) 48%,transparent);\n  background:color-mix(in srgb,var(--text-color) 2.5%,transparent);\n  border-color:color-mix(in srgb,var(--text-color) 8%,transparent);\n}\n\n.resend-btn .resend-ring{\n  position:absolute;inset:-1px;border-radius:9px;padding:1px;box-sizing:border-box;\n  pointer-events:none;opacity:0;\n  color:var(--text-color);\n  background:conic-gradient(from -90deg, currentColor calc(var(--p, 0) * 1%), transparent 0);\n  -webkit-mask:linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0);\n  -webkit-mask-composite:xor;\n  mask:linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0);\n  mask-composite:exclude;\n  transition:opacity .2s ease;\n}\n\n.resend-btn.is-wait .resend-ring{opacity:.8}\n\n.resend-btn .resend-txt{position:relative;z-index:1}\n",
    "js": "// Resend cooldown\n  const resendBtn = document.getElementById('resend-btn');\n  let resendTimer = null;\n  let resendRaf = 0;\n  function resetResend() {\n    if (!resendBtn) return;\n    clearInterval(resendTimer);\n    cancelAnimationFrame(resendRaf);\n    resendBtn.disabled = false;\n    resendBtn.classList.remove('is-wait');\n    resendBtn.style.setProperty('--p', '0');\n    const t = resendBtn.querySelector('.resend-txt');\n    if (t) t.textContent = 'Resend code';\n  }\n  function startResend() {\n    if (!resendBtn || resendBtn.disabled) return;\n    const total = reduce ? 400 : 10000;\n    const start = performance.now();\n    resendBtn.disabled = true;\n    resendBtn.classList.add('is-wait');\n    const tick = (now) => {\n      const p = Math.min(1, (now - start) / total);\n      resendBtn.style.setProperty('--p', String(p * 100));\n      const left = Math.ceil((total - (now - start)) / 1000);\n      const t = resendBtn.querySelector('.resend-txt');\n      if (t) t.textContent = left > 0 ? 'Wait ' + left + 's' : 'Resend code';\n      if (p < 1) resendRaf = requestAnimationFrame(tick);\n      else {\n        resendBtn.disabled = false;\n        resendBtn.classList.remove('is-wait');\n        resendBtn.style.setProperty('--p', '0');\n      }\n    };\n    resendRaf = requestAnimationFrame(tick);\n  }\n  if (resendBtn) resendBtn.addEventListener('click', startResend);\n\ndocument.querySelectorAll('[data-act]').forEach((btn) => {\n    btn.addEventListener('click', (e) => {\n      e.stopPropagation();\n      const act = btn.getAttribute('data-act');\n      if (act === 'resend') resetResend();\n    });\n  });"
  }
}