Confirm
A confirmation prompt built from parts over AlertDialog.
No decision yet.
View code
let outcome: string | null = null;
function settle(next: string) {
outcome = next;
void handle.update();
}
<div mix={[vstack({ gap: 3, align: "center" }), maxIs("26rem")]}>
<Button commandfor="preview-confirm" command="show-modal" color="danger" variant="outline">
Cancel subscription
</Button>
<Confirm id="preview-confirm" color="danger">
<Confirm.Header>
<Confirm.Title>Cancel the Team plan?</Confirm.Title>
<Confirm.Description>{CONSEQUENCES}</Confirm.Description>
</Confirm.Header>
<Confirm.Footer>
<Confirm.Cancel mix={on("click", () => settle("Still on the Team plan."))}>
Keep the plan
</Confirm.Cancel>
<Confirm.Action mix={on("click", () => settle("Cancellation scheduled for 30 September."))}>
Cancel the plan
</Confirm.Action>
</Confirm.Footer>
</Confirm>
<p mix={[text("sm"), fg("neutral"), textAlign("center")]}>{outcome ?? "No decision yet."}</p>
</div>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Or copy it into your project to edit it:
sdxc ui add confirmUsage
import { Confirm } from "@sdxc/ui";Renders the AlertDialog panel, named by its Confirm.Title and described by its Confirm.Description through generated ids. Focus opens on Confirm.Cancel, or on a Confirm.Phrase field, which comes first in the panel.
Composition
The parts the component publishes, each a static property of the host.
ConfirmConfirm.FormTurns confirming into a real submission: the panel's parts go inside, the confirming control becomes its submit button, and hidden inputs (a CSRF token, the record's id) go in as children.Confirm.HeaderThe column stacking the title and description.Confirm.TitleThe panel's heading, which names it.Confirm.DescriptionThe supporting copy under the title, which describes the panel.Confirm.PhraseThe type-to-confirm field: its label, then an input that keeps the confirming control disabled until the phrase matches.Confirm.FooterThe end-aligned row holding Cancel, then the confirming control.Confirm.CancelBacks out without confirming, closing the panel.Confirm.ActionThe confirming control in the root's colour: inside a Confirm.Form it submits the form, otherwise it closes the panel for the page to react to.
Examples
Type to confirm
View code
<Button commandfor="delete-team" command="show-modal" color="danger" variant="outline">
Delete team
</Button>
<Confirm id="delete-team">
<Confirm.Form action="/examples/teams/acme-ops/delete">
<Confirm.Header>
<Confirm.Title>Delete team?</Confirm.Title>
<Confirm.Description>
Acme Ops, its 14 monitors, 3 status pages and 90 days of check history are deleted for everyone.
</Confirm.Description>
</Confirm.Header>
<Confirm.Phrase value="acme-ops" name="confirmation">
Type "acme-ops" to confirm
</Confirm.Phrase>
<Confirm.Footer>
<Confirm.Cancel>Cancel</Confirm.Cancel>
<Confirm.Action>Delete team</Confirm.Action>
</Confirm.Footer>
</Confirm.Form>
</Confirm>Brand color
View code
<Button commandfor="publish-post" command="show-modal" color="brand">Publish</Button>
<Confirm id="publish-post" color="brand">
<Confirm.Header>
<Confirm.Title>Publish “Shipping the Acme 2.0 editor”?</Confirm.Title>
</Confirm.Header>
<Confirm.Footer>
<Confirm.Cancel>Keep editing</Confirm.Cancel>
<Confirm.Action>Publish</Confirm.Action>
</Confirm.Footer>
</Confirm>Submitting a form
View code
<Button commandfor="revoke-session" command="show-modal" variant="outline" color="neutral">
Sign out of MacBook Pro
</Button>
<Confirm id="revoke-session">
<Confirm.Form action="/examples/settings/sessions/macbook-pro/revoke">
<input type="hidden" name="csrf" value="b1f4c9e2" />
<Confirm.Header>
<Confirm.Title>Sign out of MacBook Pro?</Confirm.Title>
</Confirm.Header>
<Confirm.Footer>
<Confirm.Cancel>Stay signed in</Confirm.Cancel>
<Confirm.Action>Sign out</Confirm.Action>
</Confirm.Footer>
</Confirm.Form>
</Confirm>Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
id | string | — | Yes | |
color | Button.Color | — | No |
Also accepts everything in Omit<AlertDialog.Props, "id">.
Confirm.Form
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
method | "get" | "post" | — | No |
Also accepts everything in Omit<TagProps<"form">, "method">.
Confirm.Header
Confirm.Title
Confirm.Description
Confirm.Phrase
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
value | string | — | Yes | The exact text that unlocks the confirming control, compared case-sensitively. |
name | string | — | No | Name the typed text submits under inside a Confirm.Form, so the server can check it again. |
children | TagProps<"label">["children"] | — | Yes | The field's label, such as Type "acme" to confirm. |
Also accepts everything in Omit<TagProps<"div">, "children">.