# Safe Action (Lumen Halo): prompt.md (v1.0.0)

- id: `lumen-safe-action` · version 1.0.0 · component · pro (Pro)
- category: Actions
- build: Base UI (one set of files; its dependencies follow the build)
- install (this build): `npx shadcn@latest add @beautiful-ui-pro/lumen-safe-action`
- npm dependencies: none
- registry dependencies: utils, @beautiful-ui/lumen-button, https://beautiful-ui.dev/r/lumen-foundation.json
- docs: https://beautiful-ui.dev/components/lumen-safe-action
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

A risky action that asks in place: the button widens into Cancel and a confirm you hold until its cells fill, shows its pending state in the same spot, then offers Undo while a hairline drains. No dialog and no layout jump, and focus always lands on the step you're on.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: none beyond React.
- Files: `components/ui/lumen/controls/safe-action.tsx`; shared code: `lib/beautiful-ui/core/safe-action-steps.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `lumen-button`, `lumen-foundation`.
- Builds: one set of files for both, but its dependencies come in Base UI and Radix builds. Install the one that matches the project (see Install): a free item's bare URL installs the Base UI build of it and its dependencies.
- Exports to keep: `SafeAction`, and every exported type.
- CSS: the install merges this item's rules (the registry `css` field) into your global stylesheet, in `@layer components`, and adds the lumen foundation (tokens, keyframes, motion levels) once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Tokens: retheme with the `--lumen-*` custom properties (`--lumen-accent`, `--lumen-accent-foreground`, `--lumen-accent-text`, `--lumen-bad`, `--lumen-bad-text`, `--lumen-chart-accent`, `--lumen-chart-accent-foreground`, `--lumen-chart-accent-text`, `--lumen-focus`, `--lumen-good`, `--lumen-good-text`, `--lumen-hairline`, `--lumen-ink`, `--lumen-muted-ink`, `--lumen-series-1`, `--lumen-series-2`, `--lumen-series-3`, `--lumen-series-4`, `--lumen-series-5`, `--lumen-series-6`, `--lumen-warn`, `--lumen-warn-text`); this item's CSS also reads `--lumen-font-sans`, `--lumen-radius-k`. Never add Tailwind colour classes inside the component.

```tsx
import { SafeAction } from "@/components/ui/lumen/controls/safe-action";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `SafeAction` | — | The action, its confirm step, pending, done and undo. |

## Sound
- Keep every `data-slot` and `data-sound` attribute: the sound layer reads them.
- Installing this item adds no audio. Nothing plays until the app mounts `GlassSoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/glass-sound.json`, import from `@/components/beautiful-ui/glass-sound`); `GlassSoundToggle` is its mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/lumen/controls/safe-action.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- confirm button, delete confirmation, inline confirm, hold to confirm, undo, archive, destructive action, are you sure, Lumen
- Deleting, archiving, revoking or resetting one thing, where a dialog would be heavier than the decision
- Actions you can reverse: pass onUndo and people act without fear

### Not when
- Irreversible actions with wide impact (deleting a workspace): use Alert Dialog and make people type the name
- Bulk actions on a selection: use Bulk Action Bar

## Mistakes
- Do the work in onConfirm and return its promise, so the pending and error steps are real
- Keep onUndo honest: only pass it when the action can really be reversed

## Usage

```tsx
"use client";

import * as React from "react";
import { SafeAction } from "@/components/ui/lumen/controls/safe-action";

async function deleteProject(id: string) {
  await fetch(`/api/projects/${id}`, { method: "DELETE" });
}

async function restoreProject(id: string) {
  await fetch(`/api/projects/${id}/restore`, { method: "POST" });
}

// Hold to confirm, then Undo while the meter drains.
export function DeleteProject({ id }: { id: string }) {
  return (
    <SafeAction icon="trash" onConfirm={() => deleteProject(id)} onUndo={() => restoreProject(id)} labels={{ done: "Project deleted" }}>
      Delete project
    </SafeAction>
  );
}

// A milder action: one press confirms, with a question in the strip.
export function ArchiveProject({ id }: { id: string }) {
  return (
    <SafeAction mode="press" tone="accent" variant="outline" prompt="Archive this project?" onConfirm={() => console.log("archive", id)}>
      Archive
    </SafeAction>
  );
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `children` | `ReactNode` |  | The action's name on the first button, such as "Delete project". |
| `onConfirm` | `() => unknown` |  | Runs once confirmed. Return a promise to show the pending state until it settles; a rejection shows the error step with Try again. |
| `onUndo` | `() => unknown` |  | Reverses the action (a promise works too). Without it there's no Undo step. |
| `mode` | `"hold" \| "press"` | `"hold"` | hold: hold the confirm until its cells fill (Space or Enter held works too). press: one press confirms. |
| `holdMs / undoMs / armedMs` | `number` | `1000 / 5000 / 6000` | How long the hold takes, how long Undo stays, and how long an untouched confirm step waits before stepping back. |
| `tone` | `"danger" \| "accent"` | `"danger"` | The confirm drawn as destructive, or as the primary. |
| `variant / size / icon` | `Button props` | `"secondary" / "default"` | The first button's look, size and icon (a Lumen icon name such as "trash", or your own). |
| `prompt` | `string` |  | A short question in the confirm step, such as "Archive this project?". |
| `labels` | `Partial<SafeActionLabels>` |  | Every word it shows: confirm, holdHint, holding, cancel, pending, done, undo, undoing, undone, error, undoError, retry, dismiss. |
| `motion` | `"full" \| "subtle" \| "off"` | `"full"` | full: the width springs and each step fades in from a soft blur. subtle: shorter, on a calm curve. off (and reduced motion): no width travel or blur. |

Full docs: https://beautiful-ui.dev/components/lumen-safe-action

## Customising
- Motion: `motion="full"` (default) | `"subtle"` | `"off"`. prefers-reduced-motion is always respected.
- Colours: set the `--lumen-*` tokens on `:root`, or on a container with the `lumen-scope` class to retheme one area. Add the `lumen-inherit` class to follow your shadcn palette instead (`--chart-N`, `--destructive`).
- Dark mode follows the `.dark` class on an ancestor (the shadcn and next-themes convention).
- Update later by re-running the install with `--overwrite` (review the diff if you edited it). Changelog: https://beautiful-ui.dev/r/changelog.json

## Keyboard

| Keys | Action |
|---|---|
| Enter or Space | Open the confirm step |
| Hold Space or Enter | Confirm (hold mode) |
| Escape | Step back |

## Motion inventory

| Interaction | What moves |
|---|---|
| Open and close | The frame springs to the new width; the step fades in from a 4px blur |
| Hold | The confirm's cells fill over holdMs and drain when released early |
| Done | A check draws itself; a hairline drains while Undo is offered |

## Accessibility contract (preserve when editing)
- Every step is a real button; the hold has a spoken hint (Press and hold to confirm)
- Focus moves to the step you're on (the confirm, then Undo) only when it was already inside, so it never steals focus from the page
- Done and Undone are announced (role=status), a failure as an alert

## Install

```bash
npx shadcn@latest add @beautiful-ui-pro/lumen-safe-action
```

Pro item: needs the `@beautiful-ui-pro` registry in `components.json` and `BEAUTIFUL_UI_TOKEN` in `.env.local` (https://beautiful-ui.dev/account). Setup: https://beautiful-ui.dev/docs/pro. Your components.json `style` picks the build: radix-*, new-york and default get Radix, base-* gets Base UI.

## Credits
- Built on shadcn/ui (https://ui.shadcn.com)

The lumen foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://beautiful-ui.dev/r/lumen-foundation.json.
