Cómo funciona
A 52×52 SVG that plays on a timeline: a soft aura opens, a solid disc in the status colour springs in, the check or cross is drawn across it in the contrasting ink (white on light, near-black on dark), then a ripple ring spreads out and fades (a shake on failure). Strokes use pathLength="1" and a dashoffset from 1 to 0, so no lengths are measured. Every delay is a fraction of one duration value. Default styles are the end state, so reduced motion simply shows the result.
Úsalo para
- Result pages or dialogs after key actions such as payment, checkout or submitting a form.
- Failures that need a clear signal (variant="error").
- Moments that deserve some ceremony without adding an animation library.
Busca otra opción cuando
- Small status icons on every list row: use a static icon.
- Frequent light feedback such as "copied": use a toast or the button's own state.
- While the result is still pending: show a loading state first.
Uso
import { useState } from 'react'
import { SuccessCheck } from './SuccessCheck.jsx'
export function PayResult({ ok }) {
const [play, setPlay] = useState(0)
return (
<div style={{ textAlign: 'center' }}>
<SuccessCheck
size={72}
variant={ok ? 'success' : 'error'}
playKey={play}
label={ok ? 'Payment received' : 'Payment failed'}
onDone={() => console.log('Animation finished')}
/>
<h3>{ok ? 'Payment received' : 'Payment failed'}</h3>
<button onClick={() => setPlay((n) => n + 1)}>Play again</button>
</div>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
size | number | 72 | Icon side length in px; line widths scale with it. |
variant | 'success' | 'error' | 'accent' | 'success' | success: green disc with a check; error: red disc with a cross and a shake; accent: accent disc with a check. |
duration | number | 900 | Total animation time in ms; phases scale in proportion. |
playKey | string | number | — | Replays the animation whenever it changes. |
onDone | () => void | — | Called when the animation ends; immediately under reduced motion. |
label | string | 'Success' / 'Failed' / 'Done' by variant | Accessible name (aria-label of the role="img" root). Pass the concrete result, such as "Payment received". |
...rest | HTMLAttributes<HTMLSpanElement> | — | Other attributes, such as className and style, go to the root element. |
Accesibilidad
- The root is role="img" with an aria-label that reads the result; the SVG itself is aria-hidden.
- The icon is only emphasis: show the result as text too, in a live region if needed.
- With reduced motion nothing animates, the end state shows, and onDone fires at once.
- Shape (check or cross) separates the outcomes as well as color.
Movimiento
900ms by default: aura 50% (scale 0.55 to 1), disc 45% from 5% on the spring curve (slight overshoot), check 40% from 36%, ripple 50% from 50% (scale to 1.75 while fading). The failure shake runs ease-in-out from 62%.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
SuccessCheck.jsxsuccess-check.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

