Scratch Reveal
ComponentsScratch Reveal
ExperimentsNew

Scratch Reveal

A little curiosity pays off. Scratch a foil surface and uncover a print worth finding.

React + CSS
Live component. Go ahead, interact.
01

Installation

Run this in your shadcn-configured React project. The component and stylesheet are added together.

TERMINAL
npx shadcn@latest add http://localhost:5173/r/scratch-reveal.json

This command uses the current site address. For localhost, keep this preview running on the same computer. Files follow your configured components alias.

02

Usage

Import the component and make the details your own.

TypeScript
import { ScratchReveal } from '@/components/anticraft/ScratchReveal';

export function Example() {
  return (
    <ScratchReveal coverText="A little curiosity pays off" coverColor="#a7bcb0">
      <div style={{ display: 'grid', placeItems: 'center', width: '100%', height: '100%', background: '#f2a06d', color: '#41332c', textAlign: 'center' }}>
        <div><span style={{ fontSize: 72 }} aria-hidden="true">✳</span><h2>Good things are underneath.</h2></div>
      </div>
    </ScratchReveal>
  );
}
03

Props

PropTypeDefaultDescription
childrenReactNodeRequiredThe revealed artwork. It is hidden from assistive technology and made inert until fully revealed. Prefer decorative artwork; the reveal button remains available below it.
labelstring'Scratch to reveal'The visible instruction in the footer before the artwork is revealed.
coverTextstring'A little curiosity pays off'The phrase drawn onto the generated foil. Keep it short; up to three lines are displayed.
coverColorstring'#bdc4bd'A CSS color used beneath the locally generated foil texture. Choose a light or muted color for readable dark lettering.
brushSizenumber36The scratch diameter in CSS pixels, clamped between 8 and 140.
thresholdnumber0.45The erased fraction that reveals the complete artwork, clamped between 0.05 and 1. Coverage is estimated on an evenly spaced alpha grid.
onReveal() => voidundefinedCalled once per completed reveal, whether scratched or opened with the button. Reset allows another reveal.
classNamestring''Additional classes. Set --ac-scratch-height, --ac-scratch-paper, --ac-scratch-ink, --ac-scratch-border, and --ac-scratch-radius to customize the card.
04

Motion & accessibility

Considered by default.

Scratch with a mouse, pen, or touch, or activate Reveal artwork with the keyboard. Reset artwork restores the foil. Touch drawing reserves the canvas area, while the footer and surrounding page preserve normal scrolling. Scratch paths scale with a resized card. Reduced motion removes the final fade. All foil artwork is generated locally without images or network requests.

Use semantic content and meaningful labels in your composition. Check contrast and keyboard behavior with your own styles and content.