Confirm
kai-confirm
A structured approval card that pairs a body message with labelled action buttons — use it when the model needs an explicit go-ahead before a consequential operation runs.
- 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/elements'; 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”The canonical two-action pattern: warning tone, primary confirm, plain cancel.
Destructive Action
Section titled “Destructive Action”tone: 'danger' with style: 'destructive' — colour and icon both signal severity.
Choice Set
Section titled “Choice Set”More than two actions work naturally — each becomes a button.
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)”Set the resolution property to render the chromed read-only view for a replayed conversation.
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 |
|---|---|---|---|
| data | Record<string, unknown> | — | The confirm definition (the CardEnvelope.data). Set as a JS PROPERTY: `el.data = { body, tone, actions:[…] }`. Import `ConfirmCardData` from `@kitn.ai/ui` for the full shape. |
| 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 — no focus-stealing). Attribute: `autofocus`. |
| resolution | Record<string, unknown> | — | Set when the user resolved this card; renders the read-only view. Property: `el.resolution = { kind:'action', action:'…' }`. |
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.