本文へ移動
日本語

仕組み

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.

向いている場面

  • 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.

向かない場面

  • 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.

使い方

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>
  )
}

プロパティ

プロパティ型既定値説明
sizenumber72Icon 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.
durationnumber900Total animation time in ms; phases scale in proportion.
playKeystring | number—Replays the animation whenever it changes.
onDone() => void—Called when the animation ends; immediately under reduced motion.
labelstring'Success' / 'Failed' / 'Done' by variantAccessible name (aria-label of the role="img" root). Pass the concrete result, such as "Payment received".
...restHTMLAttributes<HTMLSpanElement>—Other attributes, such as className and style, go to the root element.

アクセシビリティ

  • 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.

モーション

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%.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

SuccessCheck.jsxsuccess-check.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

フィードバック
「紙吹雪」は Pro に含まれます。解除するとプレビューが表示されます。