jbmui

ReplayButton

  • Interactive
  • replayable

Controlled replay icon whose arrow charges from tail to arrowhead as the host animation progresses, then unlocks.

Click to replay · 100%

Install

npx shadcn@latest add @jbm/replay-button

Needs the @jbm entry in components.json; see Install once.

Also installs @jbm/tokens.

Usage

Wire to any animation
import { ReplayButton } from "@/jbm/ui/replay-button"<ReplayButton  progress={progress} // 0–1 from your animation  charging={isPlaying}  onReplay={restartAnimation}  label="Replay animation"/>
Larger icon
import { ReplayButton } from "@/jbm/ui/replay-button"<ReplayButton progress={1} charging={false} onReplay={() => player.seekTo(0)} iconSize={52} />

Props

Stage px
Declared at the documented defaults
Landscape
44 by 44
Vertical
44 by 44
Basis

iconSize 26 plus 9px padding on each side gives 44×44, which is also the enforced minimum hit area. Size grows with iconSize (iconSize + 18); the gallery demo uses iconSize 52 for a 70×70 button.

Ink replay button with a 44px minimum hit area. While charging, the circular shaft draws on over the first 85% of progress and the arrowhead over the last 15%; clicks are ignored and the button stays focusable with aria-disabled. When not charging it shows the complete icon and calls onReplay on click. No internal timer and no Remotion dependency.

PropTypeDefaultDescription
progressnumberrequiredNormalized progress of the host animation, 0–1. Clamped; non-finite values count as 0. Ignored (treated as 1) when charging is false.
chargingbooleanrequiredTrue while the host animation plays: shows the partial charge and blocks activation (aria-disabled, still focusable). False shows the complete icon and allows replay.
onReplay() => voidrequiredCalled on click only when neither charging nor disabled is set; restart your animation here.
labelstring"Replay animation"Accessible name (aria-label) for the button.
iconSizenumber26Width and height of the icon in pixels; the button adds 9px padding on each side.

Also accepts Omit< React.ButtonHTMLAttributes<HTMLButtonElement>, "children" | "onClick" | "type" | "aria-label" >.

QA checks

  • Click replay and watch the charge: the shaft draws from its tail to the top-right, then the two arrowhead strokes draw in after 85% progress; at 100% the complete icon returns.
  • While charging, click and press Enter/Space: nothing restarts, focus stays on the button, and it announces as disabled.
  • Tab to the button and confirm the visible focus treatment on cream; check the 44×44 hit area at the default iconSize.
  • Pass progress values below 0, above 1, and NaN while charging: the icon clamps instead of overdrawing or disappearing.