suiss/ui ยท Pattern
Confirm
A confirmation prompt that opens as an alert dialog on desktop and an action sheet on mobile.
Confirm is an open-source pattern from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Confirm asks the user to confirm or cancel an action. On desktop it renders an AlertDialog with a header and a footer of buttons. Below the 48rem breakpoint it renders an AlertSheet, with the title, description and actions in one grouped card and Cancel in its own button below it.
Use it before destructive or irreversible actions, such as deleting a record, where the user must make an explicit choice.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
-
Add the pieces it builds on: Alert Dialog, Alert Sheet,
use-mobile. -
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a Confirm:
Examples
Dismissible
Set dismissible so the mobile sheet also closes when the user presses outside it. The desktop dialog ignores it.
Accessibility
- The popup has the
alertdialogrole, named byConfirmTitleand described byConfirmDescription. On mobile withdismissibleset, it has thedialogrole instead. - Opening moves focus into the dialog, and closing returns it to the trigger.
- On desktop, pressing outside does not close the dialog;
Escape, Cancel or an action does.
API Reference
Confirm
The root that renders an AlertDialog on desktop and an AlertSheet on mobile.
| Prop | Type | Default |
|---|---|---|
dismissible | boolean | false |
Also accepts the props of React.ComponentProps<typeof AlertSheet>.
The mobile sheet is not dismissible by default; set dismissible to let an outside press close it.
Confirm accepts open, defaultOpen and onOpenChange for controlled or uncontrolled use.
Confirm accepts isOpen, defaultOpen and onOpenChange for controlled or uncontrolled use. A Button placed inside Confirm opens it.
ConfirmTrigger
The button that opens the confirmation.
Also accepts the props of React.ComponentProps<typeof AlertDialogTrigger>.
ConfirmContent
The popup; on mobile it regroups the footer buttons into the sheet layout.
Also accepts the props of React.ComponentProps<typeof AlertDialogContent>.
Write the content once with the desktop structure: ConfirmHeader holding ConfirmTitle and ConfirmDescription, then ConfirmFooter holding ConfirmCancel and ConfirmAction. On mobile, ConfirmContent lifts the buttons out of ConfirmFooter. The size prop applies to the desktop AlertDialogContent only.
ConfirmHeader
Groups the title and description.
Also accepts the props of React.ComponentProps<"div">.
ConfirmFooter
Holds the cancel and action buttons on desktop; on mobile its buttons are moved into the sheet.
Also accepts the props of React.ComponentProps<"div">.
Keep ConfirmCancel and ConfirmAction as direct children of ConfirmFooter so the mobile layout can find them.
ConfirmTitle
The prompt's title, used as the dialog's accessible name.
Also accepts the props of React.ComponentProps<typeof AlertDialogTitle>.
ConfirmDescription
Supporting text, used as the dialog's accessible description.
Also accepts the props of React.ComponentProps<typeof AlertDialogDescription>.
ConfirmAction
A button that performs the action and closes the prompt.
Also accepts the props of React.ComponentProps<typeof AlertSheetAction>.
Pass variant="destructive" for destructive actions.
ConfirmCancel
A button that closes the prompt without acting; shown separately below the actions on mobile.
Also accepts the props of React.ComponentProps<typeof AlertSheetCancel>.
Each part sets a data-slot, such as confirm-content or confirm-cancel, for styling.
Web preview
Confirm wraps AlertSheet with dismissible set to false by default, so the sheet closes only through one of its buttons.
ConfirmContent places the header and every non-cancel button in one rounded group, and ConfirmCancel below it as a separate button. Use it before destructive or irreversible actions.
Installation
The CLI also adds what it builds on: Alert Sheet.
- Install the following dependencies:
-
Add the pieces it builds on: Alert Sheet.
-
Copy and paste the following code into
components/patterns/confirm.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Add the pieces it builds on: Alert Sheet.
-
Copy and paste the following code into
components/patterns/confirm.tsx:
- Update the import paths to match your project setup.
-
Add the pieces it builds on: Alert Sheet.
-
Copy and paste the following code into
components/patterns/confirm.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Default
Web preview
Accessibility
- With the default
dismissible={false}, the sheet uses the alert dialog primitive, so it closes only through its buttons.
API Reference
Confirm
The root that owns the open state.
| Prop | Type | Default |
|---|---|---|
dismissible | boolean | false |
Also accepts the props of React.ComponentProps<typeof AlertSheet>.
The root accepts open, defaultOpen and onOpenChange. Set dismissible to let a press on the scrim close the sheet.
ConfirmTrigger
The element that opens the sheet.
Also accepts the props of React.ComponentProps<typeof AlertSheetTrigger>.
ConfirmContent
The sheet that groups the header and actions and places Cancel below.
Also accepts the props of React.ComponentProps<typeof AlertSheetContent>.
Put ConfirmTitle and ConfirmDescription in a ConfirmHeader, and the buttons in a ConfirmFooter inside ConfirmContent. Any ConfirmAction goes into the group; ConfirmCancel is moved out of it. On iOS the sheet renders in a full-window overlay so it appears above native screens.
ConfirmHeader
Holds the title and description.
Also accepts the props of React.ComponentProps<typeof AlertSheetHeader>.
ConfirmFooter
Holds the action and cancel buttons.
Also accepts the props of ViewProps.
ConfirmTitle
The question being asked.
Also accepts the props of React.ComponentProps<typeof AlertSheetTitle>.
ConfirmDescription
Supporting text about the consequences.
Also accepts the props of React.ComponentProps<typeof AlertSheetDescription>.
ConfirmAction
A confirming action, rendered as an AlertSheetAction.
Also accepts the props of React.ComponentProps<typeof AlertSheetAction>.
Set variant="destructive" for delete-style actions.
ConfirmCancel
The cancel button, shown separately below the group.
Also accepts the props of React.ComponentProps<typeof AlertSheetCancel>.
.confirm
| Parameter | Type | Default |
|---|---|---|
isPresented | Binding<Bool> | - |
dismissible | Bool | false |
content | () -> Content | - |
ConfirmContent
The sheet that groups the header and actions and places Cancel below.
| Parameter | Type | Default |
|---|---|---|
size | AlertDialogContent<Content>.Size | .default |
content | () -> Content | - |
ConfirmHeader
Holds the title and description.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
ConfirmTitle
The question being asked.
| Parameter | Type | Default |
|---|---|---|
_ย title | LocalizedStringKey | - |
ConfirmDescription
Supporting text about the consequences.
| Parameter | Type | Default |
|---|---|---|
_ย description | LocalizedStringKey | - |
ConfirmFooter
Holds the action and cancel buttons.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
ConfirmAction
A confirming action, rendered as an AlertSheetAction.
| Parameter | Type | Default |
|---|---|---|
_ย title | LocalizedStringKey | - |
variant | AlertSheetActionVariant | .default |
action | (() -> Void)? | nil |
ConfirmCancel
The cancel button, shown separately below the group.
| Parameter | Type | Default |
|---|---|---|
_ย title | LocalizedStringKey | "Cancel" |
action | (() -> Void)? | nil |
Confirm
The root that owns the open state.
| Parameter | Type | Default |
|---|---|---|
open | Boolean | - |
onOpenChange | (Boolean) -> Unit | - |
modifier | Modifier | Modifier |
dismissible | Boolean | false |
content | @Composable () -> Unit | - |
ConfirmHeader
Holds the title and description.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable ColumnScope.() -> Unit | - |
ConfirmTitle
The question being asked.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
ConfirmDescription
Supporting text about the consequences.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
ConfirmFooter
Holds the action and cancel buttons.
| Parameter | Type | Default |
|---|---|---|
content | @Composable () -> Unit | - |
ConfirmAction
A confirming action, rendered as an AlertSheetAction.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
onClick | () -> Unit | - |
modifier | Modifier | Modifier |
variant | AlertSheetActionVariant | AlertSheetActionVariant.Default |
enabled | Boolean | true |
ConfirmCancel
The cancel button, shown separately below the group.
| Parameter | Type | Default |
|---|---|---|
text | String | "Cancel" |
onClick | () -> Unit | {} |