ScratchReveal
Scratch-off foil. Rub it away with a pointer or finger; once enough is gone the rest dissolves. Enter or Space reveals it without scratching, and what is underneath is in the page the whole time. Effects.
Open playgroundAbout
ScratchReveal is a React component in the Effects category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { ScratchReveal } from "@ashutoshswamy/smoui" and set children, label, colors among its 6 props.
Install
npm i @ashutoshswamy/smouiUsage
import { ScratchReveal } from "@ashutoshswamy/smoui";
<ScratchReveal className="h-40 w-72 rounded-3xl bg-neutral-100" onReveal={claim}>
<p>20% off your next order</p>
</ScratchReveal>Props 6
- children
What is underneath.
ReactNode- label
Text on the foil, and its accessible name.
stringdefault"Scratch to reveal"- colors
Two colours for the foil.
[string, string]- threshold
Share scratched away before the rest clears.
numberdefault0.55- brush
Brush width in px.
numberdefault36- onReveal
Called once it opens.
() => void
More effects components
- AuroraSlow drifting colour behind your content. Only transforms animate; it stands still with reduced motion.
- BorderBeamA light that runs around the edge of whatever it wraps, at an even pace along straight sides and rounded corners alike. Reduced motion parks it still.
- CompareSliderBefore/after reveal. Drag the divider; the top layer follows on a spring. It sweeps once to show it moves.
- ConfettiButton that throws flat confetti on press. Pieces fly out, tumble, then fall and fade.
- DotFieldA grid of dots that swells and shrinks away from the pointer, then springs home. One canvas, asleep when nothing moves.
- GlassLensA magnifier that drifts after the cursor like a drop of water. Press to zoom further.