kai-confirm
Collects an explicit yes or no before something consequential runs, then closes itself.
- Shadow DOM
- Single kai-card event
- Resolves on action (no double-fire)
- 3 action styles
- Optional dismiss affordance
Preview
Section titled “Preview”Set data in JavaScript (it’s an object) and listen for the kai-card CustomEvent:
<kai-confirm heading="Run database migration?"></kai-confirm>
<script type="module"> import '@kitn.ai/ui/web-components';
await customElements.whenDefined('kai-confirm');
const el = document.querySelector('kai-confirm');
el.data = { body: 'This will apply 3 pending migrations to production. This cannot be undone.', tone: 'warning', actions: [ { id: 'approve', label: 'Run migration', style: 'primary', default: true }, { id: 'reject', label: 'Cancel' }, ], };
el.addEventListener('kai-card', (e) => { const ev = e.detail; // { kind: 'action', cardId, action, payload? } if (ev.kind === 'action') console.log('chose', ev.action); });</script>data— shape:ConfirmCardDatafrom@kitn.ai/ui. Malformed payloads render an inline error.- Action styles —
'primary' | 'default' | 'destructive'. Mark onedefault: trueto make it the keyboard default; combine withautofocusto focus it on mount. - Restore resolved state via
el.resolution = { kind: 'action', action: 'approve' }— useful when replaying past conversations.
Examples
Section titled “Examples”Approve or Reject
Section titled “Approve or Reject”Destructive Action
Section titled “Destructive Action”tone: 'danger' with style: 'destructive': colour and icon both signal severity.
Choice Set
Section titled “Choice Set”Dismissible
Section titled “Dismissible”dismissible: true adds a close (×) affordance that fires { kind: 'dismiss', cardId }; the card stays in the DOM.
Resolved (Read-only)
Section titled “Resolved (Read-only)”Error State
Section titled “Error State”An empty actions array renders the inline error view and fires { kind: 'error', cardId, message }.
| Property | Type | Default | Notes |
|---|---|---|---|
| theme | "light" | "dark" | "auto" | 'auto' | Color mode (`auto` follows prefers-color-scheme). |
| data | — | The confirm definition (the card's `data`). JS property: `el.data = { body, tone, actions: [...] }`. | |
| cardId | string | — | Stable card id correlating every emitted CardEvent. Attribute: `card-id`. |
| heading | string | — | Heading rendered in the card chrome (= CardEnvelope.title). Attribute: `heading`. |
| autofocus | boolean | false | Focus the default action on mount (off by default, so nothing steals focus). Attribute: `autofocus`. |
| resolution | Record<string, unknown> | — | Set when the user resolved this card; renders the read-only view. Property: `el.resolution = { kind:'action', action:'…' }`. |
Methods
Section titled “Methods”| Method | Signature | Notes |
|---|---|---|
| focus | (options?: FocusOptions): void | Focus the default action button (or the first action if none is default). The same target `autofocus` focuses on mount, but on demand. |
| confirm | (actionId?: string): void | Activate an action by id: emits the `action` verb on kai-card and resolves the card (single-shot). With no id, invokes the default action. |
| dismiss | (): void | Trigger the dismiss path: emits `dismiss` on kai-card and optimistically collapses the card to its re-openable stub. |
| reopen | (): void | Re-open a dismissed card from its stub: emits `reopen` on kai-card. |
Composed from
Section titled “Composed from”This element wraps these SolidJS components — reach for them directly when you need finer control than the props expose.
ConfirmCard