ValyroUI Русская версия

Scratch Reveal

Scratch off a cover to reveal text or a picture. Free, MIT · Animated components › Stickers, tickets and boards

A card under a coat that the reader scratches off with a finger or the mouse; past the threshold the rest disappears. The Show button reveals it at once. The coat is a visual effect, not protection: the content is in the page, and whether a prize is due is the app's decision.

Installation

npx valyro-cli@latest add scratch-reveal
npx shadcn@latest add https://valyro.xyz/r/scratch-reveal.json
npm install valyro-ui

import 'valyro-ui/styles.css';
import { ScratchReveal } from 'valyro-ui';

Props

PropTypeDefault
children *ReactNodeWhat the cover hides: text, a picture or a card. It cannot be focused until revealed.
coverScratchCoverLook of the coat.
brushSizenumber36Brush diameter in CSS px. Default 36.
thresholdnumber0.6Share of the card that must be cleared to reveal it all. Default 0.6.
revealedbooleanControlled revealed; use with onRevealedChange.
defaultRevealedbooleanfalseInitial revealed when uncontrolled.
onRevealedChange(revealed: boolean, reason: ScratchRevealReason) => voidA request to reveal (scratch, button) or cover again (reset). Controlled cards follow revealed.
onReveal(reason: 'scratch' | 'button') => voidOnce per cycle, when the threshold is reached or the button is pressed; not when revealed is set from outside.
onProgressChange(progress: number) => voidCleared share 0…1 while scratching, at most about ten times a second.
resetKeystring | number0A new key clears the scratches of a covered card. It does not cover a revealed one (revealed={false} does).
resettablebooleanfalseOffer a button that covers the card again once revealed. Default false.
disabledbooleanfalseNo scratching and no button.
labelsPartial<ScratchRevealLabels>Overrides for the built-in English text; keys left out keep their defaults.

Related components

Previous: Peel Sticker · Next: Tear-off Ticket · All Animated components