# Permission prompt

An agent's act that waits on a person's yes or no: who asks, what it names, what will happen and whether it can be undone, with Allow once, Don't allow and the other ways the act may be allowed.

Live variants: https://design.arcadia.is/components/permission-prompt

```tsx
import { PermissionPrompt } from "@arcadia/ui";
```

A destructive act draws only Allow once, in the danger tone, and asks every time. Escape denies; the Dismiss button closes it without a decision.

```tsx
import { useState } from "react";
import { Button, Ask, fmtTime, PermissionPrompt } from "@arcadia/ui";

function Deletion() {
  const [state, setState] = useState<PermissionState>("asking");
  const [at, setAt] = useState<string>();
  const [open, setOpen] = useState(true);
  const settle = (next: PermissionState) => () => new Promise<void>((done) => {
    setTimeout(() => {
      setAt(fmtTime(Date.now()));
      setState(next);
      done();
    }, 600);
  });
  return (
    <>
      <PermissionPrompt
        {...DELETION}
        open={open}
        state={state}
        at={at}
        onAllow={settle("allowed")}
        onDeny={settle("denied")}
        onDismiss={() => setOpen(false)}
        onRevoke={() => { setState("asking"); setAt(undefined); }}
      />
      {!open && <Button size="sm" variant="secondary" onClick={() => { setOpen(true); setState("asking"); }}>Ask again</Button>}
    </>
  );
}
```

## Accessibility

While it asks, the prompt is a `dialog` named by its title and described by the reason and, with a timed request, by a sentence that says when it expires. The ways to allow are a radio group of the platform's own radios, so the arrow keys pick one, and the Allow button says the choice it will take. Enter inside the prompt allows the chosen way, Escape denies. Every state is written: `risky` and `destructive` carry their word, and the decided line is a polite `status` that says what was decided, in words.

A press keeps its own button busy and disables the others while its promise is pending; when the decision settles the buttons go and the line takes focus. While `disabled`, every control is off and no key answers, and nothing moves focus to Allow. The tray's enter and exit drop their travel under reduced motion.

- Tab: Through the facts, the choices and the buttons
- ← →: Picks a way to allow
- Enter: Allows the chosen way
- Esc: Denies

## API reference

### PermissionPrompt

- `title` (`ReactNode`, required): The act and the thing it names: "Delete agent Rosalind".
- `agent` (`ReactNode`, required): Who asks: its avatar, its name and its model, composed with the kit.
- `target` (`ReactNode`): Where the act lands: "Release notes", "acme/web".
- `toolIcon` (`IconName`): The tool's mark beside the target.
- `section` (`ReactNode`): The place inside the target, when both are worth naming.
- `removes` (`ReactNode`): What goes with it when it cannot be undone: "Rosalind's chat and memory".
- `facts` (`readonly Fact[]`): Structured facts after the built-in ones (Asked by, Target, Section, Removes), one row each: "Run", "ci-4821".
- `risk` (`"safe" | "risky" | "destructive"`, default `"safe"`): `risky` and `destructive` say so in the header; a destructive act turns Allow red and offers only the first choice.
- `reason` (`ReactNode`): The agent's own words on why it asks.
- `consequences` (`readonly PermissionConsequence[]`, default `[]`): What will happen, a line each, under "What will happen".
- `reversibility` (`"reversible" | "irreversible" | "unknown"`, default `"reversible"`): And `irreversible` for a destructive act.
- `choices` (`readonly PermissionChoice[]`, default `DEFAULT_CHOICES`): How the person may allow, shortest first. Default one: Allow once.
- `disabled` (`boolean`, default `false`): True while the product cannot take an answer yet: every button and choice is disabled and no key acts.
- `denyLabel` (`ReactNode`, default `"Don't allow"`): The deny button's words.
- `allowButtonProps` (`PermissionButtonAttrs`): The caller's own marks on the Allow button: its `data-*` and an accessible name, never a class, a style or a handler. The chosen choice's own `buttonProps` come after these.
- `denyButtonProps` (`PermissionButtonAttrs`): The caller's own marks on the Don't allow button.
- `dismissButtonProps` (`PermissionButtonAttrs`): The caller's own marks on the header's Dismiss button.
- `state` (`"asking" | "allowed" | "denied" | "expired"`, default `"asking"`)
- `decision` (`string`): The choice id taken, once allowed.
- `until` (`number`): When a timed grant ends, in epoch milliseconds: counted down while it asks, and the time left once decided.
- `now` (`number`): The clock, when the product keeps its own; the part ticks when this is left out.
- `onAllow` (`(choice: PermissionChoice) => void | Promise<unknown>`): The person allowed it, with the choice they took. A promise locks the buttons and shows a spinner; a rejection keeps the prompt asking.
- `onDeny` (`() => void | Promise<unknown>`): The person did not allow it.
- `onExpire` (`() => void`): The request ran out of time.
- `onRevoke` (`() => void`): On the decided line: the grant can be taken back.
- `onChange` (`() => void`): On the decided line: ask again, with the choice in hand.
- `onDismiss` (`() => void`): The person closed it without deciding.
- `at` (`ReactNode`): When the decision was recorded, in the kit's clock (`fmtTime`).
- `error` (`ReactNode`): The decision did not land: what happened and what to do.
- `nesting` (`"contained-object"`): Mark an independent tray contained in another surface. A tray docked beside the composer needs no mark.
- `placement` (`"above" | "below" | "drop"`, default `"above"`): Which side of the composer it docks to. `above` rises from below; `below` drops from above. `drop` hangs under the box it stands in with the composer (a positioned dock), over what follows, a popup's shadow under it, so the page under the composer does not move (a home page's pickers).
- `motion` (`"enter" | "static"`, default `"enter"`): `enter`: 120ms rise + fade on mount, 90ms fade on close. Only event-driven trays animate (a question or approval arriving, a message queued). `static`: appears and leaves instantly: hydrated trays and the `+`, `/` and `@` pickers, which open at once.
- `open` (`boolean`): Omit to mount and unmount the tray yourself (no exit motion). Pass it to let the tray keep itself mounted for its exit fade (`data-exiting`, `inert`) and unmount afterwards.
- `rootStyle` (`RootStyle<TrayKnobs>`): Typed StyleX override: where the tray sits (layout) and its `--tray-*` knobs.

Rest props go to `<div>` props and `render`.
