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 playground
20% offYour next order

About

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

Terminal
npm i @ashutoshswamy/smoui

Usage

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

numberdefault 0.55
brush

Brush width in px.

numberdefault 36
onReveal

Called once it opens.

() => void