本文へ移動
日本語
「紙吹雪」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

A position: relative wrapper with an absolute, pointer-transparent overlay, so it works inside scaled or clipped containers. fire() creates temporary nodes, each following projectile motion with air drag, sampled into 19 keyframes and animated with the Web Animations API (transform and opacity only). Pieces remove themselves and React never re-renders.

向いている場面

  • Moments worth celebrating: check-in done, task finished, reward claimed, level up.
  • The end of a key flow such as a successful payment or booking, together with a success message.
  • Learning apps: finishing a course, earning a certificate, hitting a streak.

向かない場面

  • Ordinary saved or copied confirmations: use a toast or the button's own state.
  • Actions repeated often on one page, such as likes or add-to-cart.
  • Failures and warnings: never celebrate a negative result.
  • A full-screen, continuous confetti rain: this is a one-shot burst, not a background.

使い方

import { useRef } from 'react'
import { ConfettiBurst } from './ConfettiBurst.jsx'

export function CheckInButton({ onCheckIn }) {
  const confetti = useRef(null)
  return (
    // Wrap the button: pieces burst upward from its centre without affecting layout
    <ConfettiBurst ref={confetti} count={28} spread={100}>
      <button
        type="button"
        onClick={async () => {
          await onCheckIn()
          confetti.current?.fire() // celebrate after success
        }}
      >
        Check in
      </button>
    </ConfettiBurst>
  )
}

// Wrapping a whole card: use a block element and burst from the clicked button
// <ConfettiBurst ref={confetti} style={{ display: 'block' }}> ... </ConfettiBurst>
// confetti.current?.fire({ from: e.currentTarget, count: 40 })

// No ref: pass a success counter to fireKey and it bursts whenever it changes
// <ConfettiBurst fireKey={successCount}>...</ConfettiBurst>

プロパティ

プロパティ型既定値説明
countnumber28Number of pieces per burst.
spreadnumber100Spread in degrees: the start direction falls within angle ± spread / 2. 360 explodes in every direction.
anglenumber90Centre direction in degrees: 90 up, 0 right, 180 left, 270 down.
distancenumberclamp(min(width, height) * 0.45, 60, 240)Burst distance in px: the fastest pieces travel about this far.
colorsstring[]chart-1 / chart-4 / chart-3 / chart-5 / chart-7 tokensPiece colours, any CSS colour. The defaults are var() with fallbacks and follow the theme.
durationnumber1400Time in ms from burst to disappearance for one piece.
origin{ x: number; y: number }{ x: 0.5, y: 0.5 }Burst point inside the wrapper, 0 to 1 (x left to right, y top to bottom).
fireKeystring | number—Fires a burst whenever it changes (not on first mount). Use it when you do not want a ref.
maxParticlesnumber120Cap on pieces alive at once. When repeated bursts exceed it, the oldest are removed first.
clipbooleanfalseClips pieces to the wrapper. By default they may fly outside; turn it on when the wrapper touches the page edge and pieces could cause scrollbars.
childrenReactNode—Wrapped content: a trigger button, a success card, and so on.
refRef<{ fire, clear }>—fire(options?) shoots a burst; options can override count, spread, angle, distance, colors, duration, origin, or set from (an element to burst from). clear() removes pieces still flying.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root element, such as className and style (use style={{ display: 'block' }} when wrapping a large block).

アクセシビリティ

  • The overlay is aria-hidden with pointer-events: none, so screen readers skip it and buttons below stay clickable.
  • Confetti is only visual emphasis: always show the success result as text too, in an aria-live region if needed.
  • With reduced motion, no pieces are fired; only a 720ms soft glow fades in and out at the burst point.
  • It never takes focus or changes layout, so the trigger button and keyboard use are unaffected.
  • The number of live pieces is capped (120 by default), so repeated taps on low-end phones do not pile up.

モーション

A piece lasts 1400ms by default: the first quarter shoots out with exponential slowdown, then it falls at near-constant speed and fades with an ease-in over the last 32%. Pieces start 0 to 60ms apart.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

ConfettiBurst.jsxconfetti-burst.csstokens.cssREADME.md

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

フィードバック
「ライブステータスピル」は Pro に含まれます。解除するとプレビューが表示されます。