# Privacy mask

> A frosted optical unmasker for sensitive keys, salaries and tokens, with auto-hide timeout and one-tap copy.

Showing raw API keys, account balances, or employee salaries in screenshares, live demos, or co-working spaces creates immediate privacy risks. Privacy mask keeps confidential strings behind an optical 5px blur or bullet dots. A click, hover, or hold dissolves the blur in 200ms while the eye icon cross-fades to eye-off. One tap copies the secret with a self-drawing checkmark, and an auto-hide timer or Escape key re-masks the value immediately.

## Install

```bash
npx shadcn@latest add @hairline/privacy-mask
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): none
- Docs and live preview: https://hairlineui.com/ui/privacy-mask
- Registry item (source): https://hairlineui.com/r/privacy-mask.json

## Usage

```tsx
import { PrivacyMask } from "@/components/privacy-mask";

<PrivacyMask
  label="Stripe secret key"
  value="sk_live_51M0x7K2eZvKYlo2CL8"
  autoHideMs={6000}
/>
```

## Developer settings page with API secret keys

Display sensitive live production API credentials safely. Keys remain masked by default, and developers can copy or inspect them with automatic re-masking.

```tsx
// app/settings/api-keys/key-row.tsx
"use client";

import { PrivacyMask } from "@/components/privacy-mask";

export function KeyRow({ apiKey }: { apiKey: { name: string; secret: string; created: string } }) {
  return (
    <div className="flex items-center justify-between border-b border-border py-3">
      <div>
        <p className="text-sm font-medium text-foreground">{apiKey.name}</p>
        <p className="text-xs text-muted-foreground">Created {apiKey.created}</p>
      </div>
      <PrivacyMask
        label={apiKey.name}
        value={apiKey.secret}
        maskStyle="blur"
        autoHideMs={8000}
      />
    </div>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | – | The sensitive string to be masked and copied. |
| `label` | `string` | `"Confidential value"` | Accessible label for assistive technologies. |
| `trigger` | `"click" \| "hover" \| "hold"` | `"click"` | How the unmasking interaction is initiated. |
| `maskStyle` | `"blur" \| "dots" \| "truncate"` | `"blur"` | Visual mask format: optical blur, bullet dots, or truncated token. |
| `autoHideMs` | `number` | `6000` | Milliseconds before automatically re-masking (0 disables). |
| `copyable` | `boolean` | `true` | Shows an integrated copy button with self-drawing checkmark. |

## States

- **masked**: Frosted 5px optical blur with 60% opacity keeps text confidential while maintaining exact character width.
- **revealed**: Blur dissolves to 0px over 200ms with cubic-bezier(0.16,1,0.3,1); eye icon cross-fades into eye-off.
- **copied**: Copy button swaps to an emerald checkmark that draws its path in 320ms and restores after 1.8s.
- **auto re-mask**: Timer automatically returns to masked state after 6000ms of inactivity.
- **escape dismiss**: Escape key immediately cancels the unmasked state without waiting for the timer.

## What it handles

Developers often hack together a simple show/hide toggle that replaces the text completely or causes layout jumps when changing string lengths. Privacy mask preserves the exact physical dimensions of the text with optical blur, handles clipboard feedback, and includes auto re-mask safety timers.

- **Optical blur preserves width**: The 5px blur applies directly over the real string, so the component never shifts width or changes height between masked and unmasked states.
- **Multiple reveal triggers**: Supports click-to-toggle, hover-to-peek, and hold-to-reveal for varying levels of security sensitivity.
- **Self-drawing copy checkmark**: Copying the secret draws a crisp SVG checkmark and resets to the clipboard icon after 1.8 seconds.
- **Auto re-mask safety net**: Automatically re-masks the value after 6 seconds of inactivity to prevent leaving sensitive keys exposed on open tabs.
- **Instant Escape dismiss**: Pressing Escape immediately re-applies the mask and returns keyboard focus cleanly.
- **Screen reader privacy**: Announces "Hidden" when masked, preventing screen readers from speaking private keys aloud in public spaces.

## Replaces

custom show/hide state logic, clipboard copy handlers with timeout cleanup, auto-hide timer effects, layout-jumping masked strings, Escape key dismiss listeners

## Where it fits

- **API keys & developer settings**: Protect live Stripe, OpenAI, and database secret keys from accidental exposure.
- **Fintech & banking dashboards**: Conceal total net worth, bank account numbers, and portfolio balances during screen sharing.
- **HR & payroll records**: Mask employee base compensation and equity allocations in team directories.
- **Auth & recovery tokens**: Show two-factor backup recovery codes with one-tap copy and instant re-masking.

## Notes

- Preserves exact horizontal character metrics to prevent layout shifts across sibling components.
- Screen reader status region politely reports "Hidden" until explicitly revealed by user action.
- Clipboard copy cleans up asynchronous timeouts on component unmount.
- Reduced motion eliminates blur transitions and updates text states instantaneously.

License: MIT (https://hairlineui.com/license#components)
