# Secret reveal

> A freshly generated secret shown exactly once: monospace value, copy, one-time hint, optional regenerate.

- Group: Feedback
- Status: stable
- Aliases: token-reveal, api-key
- HTML page: https://design.ipmnx.com/components/secret-reveal/
- Spec: https://design.ipmnx.com/design/#nx-secret-reveal

## Preview

**Device token**

```html
<section class="nx-secret" aria-labelledby="nxsecret-_R_0_">
  <p id="nxsecret-_R_0_" class="nx-secret__label">Device token</p>
  <div class="nx-secret__row">
    <code class="nx-secret__value" translate="no"
        spellCheck="false">nxd_9f3c2a7e5b1d4c6a8e0f2b7d</code>
    <button type="button"
        class="nx-btn nx-btn--outline nx-btn--sm nx-secret__copy">
      <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14"
          viewBox="0 0 24 24" fill="none" stroke="currentColor"
          stroke-width="2" stroke-linecap="round"
          stroke-linejoin="round" class="lucide lucide-copy"
          aria-hidden="true" focusable="false">
        <rect width="14" height="14" x="8" y="8" rx="2"
            ry="2"></rect>
        <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9
            2 2"></path>
      </svg>
      <span>Copy</span>
    </button>
  </div>
  <p class="nx-secret__feedback" role="status"
      aria-live="polite"></p>
  <p class="nx-secret__hint">Only visible now. Only its hash is
      stored.</p>
  <div class="nx-secret__actions">
    <button type="button" class="nx-btn nx-btn--ghost nx-btn--sm">
      <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14"
          viewBox="0 0 24 24" fill="none" stroke="currentColor"
          stroke-width="2" stroke-linecap="round"
          stroke-linejoin="round" class="lucide lucide-refresh-cw"
          aria-hidden="true" focusable="false">
        <path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21
            8"></path>
        <path d="M21 3v5h-5"></path>
        <path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3
            16"></path>
        <path d="M8 16H3v5"></path>
      </svg>
      <span>Regenerate</span>
    </button>
    <button type="button"
        class="nx-btn nx-btn--primary nx-btn--sm">Done</button>
  </div>
</section>
```

```tsx
<NxSecretReveal
  value={token}
  label="Device token"
  hint="Only visible now. Only its hash is stored."
  copyLabel="Copy"
  copiedLabel="Copied"
  copyFallbackLabel="Selected - press Ctrl+C"
  regenerateLabel="Regenerate"
  onRegenerate={regenerate}
  closeLabel="Done"
  onClose={close}
/>
```

## API

### React props (NxKit)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `value` | `string` |   | yes | The secret. Rendered once as text, never in an attribute. |
| `label` | `string` |   | yes | Visible label, e.g. "Device token". |
| `hint` | `ReactNode` |   | yes | "Only visible now, only the hash is stored" in the app's language. |
| `copyLabel` | `string` |   | yes | Copy button text. |
| `copiedLabel` | `string` |   | yes | Announced after a successful copy. |
| `copyFallbackLabel` | `string` |   | yes | Announced when the clipboard is unavailable and the value was selected instead. |
| `onCopy` | `() => void` | `undefined` |   | Called after a successful clipboard write. |
| `regenerateLabel` | `string` | `undefined` |   | With onRegenerate: shows the regenerate action. |
| `onRegenerate` | `() => void` | `undefined` |   | Regenerate handler. |
| `closeLabel` | `string` | `undefined` |   | With onClose: shows the close action; afterwards the value is gone from the DOM. |
| `onClose` | `() => void` | `undefined` |   | Close handler. |
| `className` | `string` | `undefined` |   | Layout class. |

### Classes

| Class | Description |
| --- | --- |
| `.nx-secret` | Stack |
| `.nx-secret__value` | Monospace value on surface-2, hairline, wraps anywhere, user-select: all |
| `.nx-secret__feedback` | role=status live region for copy feedback |
| `.nx-secret__hint` | One-time hint |
| `.nx-secret__actions` | Regenerate / close |

## Accessibility

- The copy result is announced through a status region that is mounted empty. Without a clipboard the value is selected, so Ctrl+C or the context menu works.
- The value is plain text (translate=no) and leaves the DOM when the reveal is closed or unmounted; it is never placed in a title, value or data attribute.

## Do / Don't

- Do: Show it once right after generating, then store only the hash.
- Don't render the secret again on a later visit, or keep it in an input's value.

## Related

- [Field](https://design.ipmnx.com/components/field.md)
- [Alert](https://design.ipmnx.com/components/alert.md)

---

Source: registry.js (NX Design System)
