Redaction

Redaction overlays black boxes on an image to hide sensitive regions, and offers a Reveal for review toggle that shows the hidden areas as dashed red outlines with a warning that the redaction is only visual. Users can draw new regions with the pointer when onCreate is provided, and delete them when onDelete is provided.

uidocumentredactionprivacyregistry-item.json
Redaction
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @mischief/redaction

Requires @mischief in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { Redaction } from '@/components/ui/redaction'export function Example() {  return (    <Redaction      src='/docs/invoice.png'      alt='Invoice scan'      regions={[{ id: 'account', x: 0.1, y: 0.2, width: 0.3, height: 0.05, reason: 'Account number' }]}      readOnly    />  )}
  • Hiding personal data, account numbers, or other sensitive text in screenshots, scans, or documents before sharing them
  • Letting reviewers inspect what was covered without permanently exposing it, using the explicit reveal state
  • Annotating an image by drawing redaction regions in a review or moderation workflow
  • Displaying a read-only redacted preview where the covered regions are listed with reasons

Examples

Read-only preview with reasons

Shows a fixed set of redactions over an image. Regions use normalized coordinates from 0 to 1 relative to the image surface. readOnly hides the delete list and disables drawing.

read-only-preview-with-reasons.tsx
import { Redaction, type RedactionRegion } from '@/components/ui/redaction'const regions: RedactionRegion[] = [  { id: 'email', x: 0.08, y: 0.12, width: 0.4, height: 0.06, reason: 'Email address' },  { id: 'phone', x: 0.08, y: 0.22, width: 0.25, height: 0.06, reason: 'Phone number' },]export function ReadOnlyPreview() {  return (    <Redaction      src='/docs/contact-form.png'      alt='Contact form screenshot'      regions={regions}      readOnly    />  )}

Editable redaction editor

Lets the user draw new regions with the pointer and delete existing ones. Drawing is enabled because onCreate is provided and readOnly is not set.

editable-redaction-editor.tsx
'use client'import * as React from 'react'import { Redaction, type RedactionRegion, type RedactionRect } from '@/components/ui/redaction'export function RedactionEditor() {  const [regions, setRegions] = React.useState<RedactionRegion[]>([])  const handleCreate = (rect: RedactionRect) => {    setRegions((current) => [      ...current,      { id: String(Date.now()), reason: 'Manual redaction', ...rect },    ])  }  const handleDelete = (id: string) => {    setRegions((current) => current.filter((region) => region.id !== id))  }  return (    <Redaction      src='/scans/form.png'      alt='Scanned form'      regions={regions}      onCreate={handleCreate}      onDelete={handleDelete}    />  )}

Controlled reveal state

Owns the revealed state in the parent so it can be logged, persisted, or reset alongside other review controls.

controlled-reveal-state.tsx
'use client'import * as React from 'react'import { Redaction, type RedactionRegion } from '@/components/ui/redaction'const regions: RedactionRegion[] = [  { id: 'ssn', x: 0.3, y: 0.4, width: 0.3, height: 0.05, reason: 'SSN' },]export function ControlledReview() {  const [revealed, setRevealed] = React.useState(false)  return (    <Redaction      src='/scans/id-card.png'      alt='ID card scan'      regions={regions}      revealed={revealed}      onRevealedChange={setRevealed}      readOnly    />  )}

Custom image renderer

Replaces the default img element with a custom renderer. The renderer receives src, alt, and the className that keeps the image sized to the surface.

custom-image-renderer.tsx
import { Redaction } from '@/components/ui/redaction'export function CustomImage() {  return (    <Redaction      src='/docs/receipt.jpg'      alt='Store receipt'      regions={[{ id: 'card', x: 0.6, y: 0.8, width: 0.3, height: 0.04, reason: 'Card last digits' }]}      renderImage={({ src, alt, className }) => (        <img src={src} alt={alt} className={className} loading='lazy' />      )}      readOnly    />  )}

API reference

PropTypeDefaultDescription
srcstring—URL of the image to display.
altstring—Alternative text passed to the image element (or to renderImage).
regionsRedactionRegion[]—Redaction rectangles with id, x, y, width, height (normalized 0 to 1 relative to the surface), and optional reason.
onCreate(rect: RedactionRect) => void—Called when the user finishes drawing a region larger than minSize. Drawing is enabled only when this is provided and readOnly is false.
onDelete(id: string) => void—Called with a region id when its remove button is clicked. The removal list appears only when regions is non-empty, onDelete is provided, and readOnly is false.
revealedboolean—Controlled reveal state. When provided, the component does not manage its own reveal state.
defaultRevealedbooleanfalseInitial reveal state when uncontrolled.
onRevealedChange(revealed: boolean) => void—Called with the next reveal state when the reveal button is clicked.
readOnlybooleanfalseDisables drawing and hides the delete list.
minSizenumber0.01Minimum width and height of a drawn region, in normalized units. Smaller drags are discarded.
labelstring"Redactions"Accessible label applied to the root section via aria-label.
renderImage(props: { src: string; alt: string; className: string }) => React.ReactNode—Custom renderer for the base image. Receives a className that keeps the image full width and block-level.
...restOmit<React.HTMLAttributes<HTMLElement>, 'children'>—Remaining HTML attributes are spread onto the root section element. className is merged with the root classes.

Accessibility

  • The root element is a section labelled by the label prop (default 'Redactions') via aria-label.
  • The reveal button uses aria-pressed to communicate its on or off state and changes its visible text between 'Reveal for review' and 'Hide again'.
  • The revealed warning is a role='status' paragraph, so screen readers announce it when the state changes.
  • Each redaction region has screen-reader-only text giving its index, reason, and whether it is currently revealed.
  • Icons are marked aria-hidden. Delete buttons have sr-only labels such as 'Remove redaction 1'.
  • The base image has draggable disabled. Pass alt text that describes the image content, because redaction is only visual.
  • Drawing relies on pointer events and has no keyboard alternative in the source, so provide another way to add regions if keyboard users need it.
  • Visual covering is not a security measure. The component's own warning states that the source file must be redacted before sharing.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Redaction" component (mischief/redaction) from its shadcn registry.1. Install it with: npx shadcn@latest add @mischief/redaction2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: src, alt, regions, onCreate, onDelete, revealed, defaultRevealed, onRevealedChange, readOnly, minSize, label, renderImage, ...rest.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { Redaction } from '@/components/ui/redaction'export function Example() {  return (    <Redaction      src='/docs/invoice.png'      alt='Invoice scan'      regions={[{ id: 'account', x: 0.1, y: 0.2, width: 0.3, height: 0.05, reason: 'Account number' }]}      readOnly    />  )}```

Files & dependencies

  • registry/default/redaction/redaction.tsx
dependencieslucide-react@^1.31.0
registryDependenciesutils

Looks similar, elsewhere