# Scratch To Reveal

> React scratch card with a gradient foil you rub away by pointer or touch to show the content beneath, clearing itself once past a set threshold.

- Kind: Motion component (Motion)
- Docs: https://ui.minidev.pro/docs/scratch-to-reveal
- Source (registry JSON with the full file): https://ui.minidev.pro/r/scratch-to-reveal.json
- License: MIT. One file, yours to edit after install.

## When to use

Use it for a playful reward, promo code or launch teaser. Reach for SecretReveal to show a sensitive value behind a click, and BeforeAfterWipe to compare two images.

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/scratch-to-reveal
```

Writes `components/ui/scratch-to-reveal.tsx` and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/scratch-to-reveal.json`.

### npm package

```bash
npm i minidev-ui-kit lucide-react motion
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { ScratchToReveal } from "@/components/ui/scratch-to-reveal"
```

From the npm package:

```tsx
import { ScratchToReveal } from "minidev-ui-kit/premium/scratch-to-reveal"
```

## Usage

```tsx
import { ScratchToReveal } from "@/components/ui/scratch-to-reveal"

export function Example() {
  return (
    <ScratchToReveal />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `threshold` | `number` | `50` | no | Percent of the foil that must be scratched before the rest clears itself. |
| `brush` | `number` | `24` | no | Brush radius in pixels. |
| `gradient` | `string[]` | `DEFAULT_GRADIENT` | no | Colours of the foil gradient. CSS colours and var(--token) both work. |
| `label` | `string` | `"Scratch to reveal"` | no | Hint printed on the foil. |
| `onComplete` | `() => void` | - | no | Called once the card is fully revealed. |
| `onProgress` | `(percent: number) => void` | - | no | Called with the scratched percentage as it changes. |
| `children` | `React.ReactNode` | - | no |  |
| `className` | `string` | - | no |  |

## Examples

### Your own prize

Children are what the foil hides; gradient takes any CSS colours or tokens and label is the hint printed on top.

```tsx
<ScratchToReveal gradient={["var(--info)", "var(--chart-2)"]} label="Rub to see your seat">
  <div className="flex flex-col items-center gap-2 px-4 py-6 text-center">
    <span className="text-[11px] font-medium tracking-[0.08em] text-fg-subtle uppercase">Lumen Conf 2026</span>
    <p className="text-2xl font-medium tracking-[-0.018em] text-fg">Row C, seat 14</p>
    <p className="text-xs text-fg-muted">Doors open at 9:00, main stage.</p>
  </div>
</ScratchToReveal>
```

### Progress and completion

onProgress reports the scratched percent as it changes and onComplete fires once, when the rest of the foil clears itself.

```tsx
function ProgressDemo() {
  const [percent, setPercent] = React.useState(0)
  const [done, setDone] = React.useState(false)
  return (
    <div className="flex w-full max-w-sm flex-col items-center gap-3">
      <ScratchToReveal threshold={40} onProgress={setPercent} onComplete={() => setDone(true)}>
        <div className="flex flex-col items-center gap-1 px-4 py-8 text-center">
          <p className="text-2xl font-medium tracking-[-0.018em] text-fg">A free month of Lumen Pro</p>
          <p className="text-xs text-fg-muted">Applied to your next invoice.</p>
        </div>
      </ScratchToReveal>
      <p className="text-xs text-fg-muted tabular-nums">{done ? "Revealed. The month is on your account." : `${percent}% scratched, clears at 40%`}</p>
    </div>
  )
}
```

### Big brush, low threshold

A wide brush and a 30 percent threshold make one or two swipes enough, for a card that should not feel like work.

```tsx
<ScratchToReveal brush={40} threshold={30} label="One swipe does it" className="max-w-xs" />
```

## Keyboard interactions

| Key | Action |
| --- | --- |
| `Tab` | Focuses the Reveal button in the bottom-right corner of the foil. |
| `Enter` or `Space` | On Reveal, clears the foil and moves focus to the revealed content. |

## Accessibility

- Until revealed, the content is `aria-hidden` and `inert`, so neither screen readers nor Tab reach it.
- A Reveal button gives keyboard and switch users the same result as scratching. Focus moves to the content after it.
- An `sr-only` `role="status"` region announces "Revealed."
- Under reduced motion the foil disappears at once instead of fading out.

## FAQ

### Is the hidden content secret?

No. The children are in the DOM and the server HTML from the start, only `aria-hidden` and `inert` until revealed. Do not put a single-use code there that people must not see; fetch it in `onComplete` instead.

### How do I know when the card is revealed?

`onComplete` fires exactly once, when the scratched share reaches `threshold` (default 50%) or the Reveal button is pressed. `onProgress` receives the scratched percentage as it changes.

### Does scratching work on phones?

Yes. The foil canvas uses pointer events with pointer capture and `touch-action: none`, so a finger scratches instead of scrolling the page while it is on the card.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `lucide-react`, `motion`

## Related

- [Progress](https://ui.minidev.pro/docs/progress/md): A linear progress bar built on Base UI with track, indicator, label and value parts, a default aria label and smooth width transitions. Matches shadcn progress.
- [Secret Reveal](https://ui.minidev.pro/docs/secret-reveal/md): Masked secret field for API keys with an eye toggle to reveal or hide the value and a copy button for the full key. Monospace, compact, built with Tailwind.
- [Before After Wipe](https://ui.minidev.pro/docs/before-after-wipe/md): A before and after comparison slider in React: drag the handle or use the labelled range input to wipe between two layouts across the full width.
- [Animated Feature Row](https://ui.minidev.pro/docs/animated-feature-row/md): A row of feature cards that slide up with a staggered delay when scrolled into view. Pass title and description pairs; reduced motion keeps them still.
- [Card Tilt](https://ui.minidev.pro/docs/card-tilt/md): A card that tilts in 3D toward the pointer on springs, with an accent glare that follows the cursor. It stays flat when reduced motion is preferred.
- [Cursor Spotlight Panel](https://ui.minidev.pro/docs/cursor-spotlight-panel/md): A panel whose accent radial spotlight follows the cursor, driven by Framer Motion values without re-renders. It shows a still surface for reduced motion.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
