SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

Confirm

A confirmation prompt built from parts over AlertDialog.

Cancel the Team plan?

Billing stops at the end of the period on 30 September. The workspace keeps read access, and the nine seats over the free limit lose theirs that day.

No decision yet.

View code
tsx
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.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Or copy it into your project to edit it:

Terminal
sdxc ui add confirm

Usage

typescript
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.

  • Confirm
  • Confirm.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

Delete team?

Acme Ops, its 14 monitors, 3 status pages and 90 days of check history are deleted for everyone.

View code
tsx
<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

Publish “Shipping the Acme 2.0 editor”?

View code
tsx
<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

Sign out of MacBook Pro?

View code
tsx
<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.

PropTypeDefaultRequiredDescription
idstring—Yes
colorButton.Color—No

Also accepts everything in Omit<AlertDialog.Props, "id">.

Confirm.Form

PropTypeDefaultRequiredDescription
method"get" | "post"—No

Also accepts everything in Omit<TagProps<"form">, "method">.

Confirm.Header

Confirm.Title

Confirm.Description

Confirm.Phrase

PropTypeDefaultRequiredDescription
valuestring—YesThe exact text that unlocks the confirming control, compared case-sensitively.
namestring—NoName the typed text submits under inside a Confirm.Form, so the server can check it again.
childrenTagProps<"label">["children"]—YesThe field's label, such as Type "acme" to confirm.

Also accepts everything in Omit<TagProps<"div">, "children">.

Confirm.Cancel

Confirm.Action

@sdxc/ui

Can’t find it? Contact us