Slint · Slint components

This page shows the Slint implementation. Slint components written for native Rust applications and the browser. Browse the catalog, run each live example, and copy the .slint source into your own app.

AlertDialog

AlertDialog is a modal dialog component that interrupts the user with important content and expects a response. It is built on top of the Dialog component with opinionated defaults and a simplified API.

Install

#Differences from Dialog

AlertDialog provides these defaults on top of Dialog:

  • Not overlay closable by default (can be changed with overlay_closable(true))
  • No close button by default (can be changed with close_button(true))
  • Footer buttons are center-aligned (Dialog uses right-alignment)
  • Simplified API focused on alert and confirmation scenarios

#Import

use gpui_kit::component::dialog::{AlertDialog, DialogAction, DialogClose};
use gpui_kit::component::WindowExt;
// Installed in ui/components. That directory is on the Slint include path, so import by file name:
import { AlertDialog } from "alert-dialog.slint";
use iced::keyboard;
use iced::widget::{Stack, column, container, mouse_area, row, scrollable, svg, text};
use iced::{Alignment, Element, Length, Subscription, Task, Theme};
import { signal, Text, View } from "nsh";
import { AlertDialog } from "./alert_dialog";
import { Avatar } from "./avatar";
import { Button } from "./button";
import { Icon } from "./icon";
import { Input } from "./input";
import { Tag } from "./tag";
import { RADIUS_MD, SPACING_SM, tokens } from "./theme";

#Usage

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
const usageOpen = signal(false);
const usage = (
  <>
    <Button label="Apply settings" variant="primary" onPress={() => usageOpen.set(true)} />
    <AlertDialog
      open={usageOpen()}
      icon="info"
      tone="info"
      title="Apply new settings?"
      description="The app will restart to apply them."
      confirmLabel="Apply"
      cancelLabel="Not now"
      onConfirm={() => usageOpen.set(false)}
      onCancel={() => usageOpen.set(false)}
      onClose={() => usageOpen.set(false)}
    />
  </>
);

#Default

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// The default confirmation: a title, a description and a centered footer
// whose cancel action comes first and whose destructive one comes last.
let default = body_box(
    column![
        open_button("Discard Draft", slot::DEFAULT),
        muted_line("A centered footer: Cancel first, then the destructive action."),
    ]
    .spacing(8.0),
);
let default_dialog = Dialog::new()
    .open(app.open[slot::DEFAULT])
    .close_button(false)
    .title("Discard unsaved changes?")
    .description("Your edits since the last save will be permanently lost.")
    .footer(
        DialogFooter::new()
            .centered(true)
            .child(close_button("Cancel", slot::DEFAULT))
            .child(
                Button::new("Discard")
                    .variant(button::Variant::Danger)
                    .on_press(Message::Opened {
                        slot: slot::DEFAULT,
                        open: false,
                    }),
            ),
    )
    .on_open_change(|open| Message::Opened {
        slot: slot::DEFAULT,
        open,
    });
const defaultOpen = signal(false);
const defaultExample = (
  <>
    <Button label="Leave workspace" onPress={() => defaultOpen.set(true)} />
    <AlertDialog
      open={defaultOpen()}
      title="Leave workspace?"
      description="Your files stay in the workspace. You can rejoin with a new invite."
      confirmLabel="Leave"
      cancelLabel="Stay"
      showClose
      onConfirm={() => defaultOpen.set(false)}
      onCancel={() => defaultOpen.set(false)}
      onClose={() => defaultOpen.set(false)}
    />
  </>
);

Like Dialog, you need to set up your application’s root view to render the dialog layer. See Dialog documentation for details.

AlertDialog::new(cx)
    .trigger(Button::new("info-alert").outline().label("Discard Draft"))
    .on_ok(|_, window, cx| {
        window.push_notification("Draft discarded", cx);
        true
    })
    .content(|content, _, cx| {
        content
            .child(
                DialogHeader::new()
                    .child(DialogTitle::new().child("Discard unsaved changes?"))
                    .child(DialogDescription::new().child(
                        "Your edits since the last save will be permanently lost.",
                    )),
            )
            .child(
                DialogFooter::new()
                    .child(DialogClose::new().child(
                        Button::new("cancel").outline().label("Cancel"),
                    ))
                    .child(DialogAction::new().child(
                        Button::new("ok").label("Discard").danger(),
                    )),
            )
    })
row: root.row-of(0);
col: root.col-of(0);
Preview {
    label: "Discard Draft";
    clicked => {
        root.discard-open = true;
    }
    Dialog {
        width: 100%;
        height: 100%;
        open <=> root.discard-open;
        show-close: false;
        title: "Discard unsaved changes?";
        description: "Your edits since the last save will be permanently lost.";
        DialogFooter {
            centered: true;
            Button {
                text: "Cancel";
                outline: true;
                clicked => {
                    root.discard-open = false;
                }
            }
            Button {
                text: "Discard";
                variant: ButtonVariant.danger;
                clicked => {
                    root.discard-open = false;
                }
            }
        }
    }
}
NSHNo NSH version of this example yet.

#Delete file

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// The panel's body is the caller's, so a leading danger glyph and the two
// lines beside it are an ordinary row placed in `content`.
let delete = body_box(
    column![
        open_button("Delete File", slot::DELETE),
        muted_line("A danger glyph leads the title and the line beside it."),
    ]
    .spacing(8.0),
);
let delete_dialog = Dialog::new()
    .open(app.open[slot::DELETE])
    .close_button(false)
    .content(icon_row(
        INFO_XML,
        theme::Status::Danger,
        20.0,
        "Delete File",
        "Are you sure you want to delete this file? This action cannot be undone.",
    ))
    .footer(
        DialogFooter::new()
            .centered(true)
            .child(close_button("Cancel", slot::DELETE))
            .child(
                Button::new("Delete")
                    .variant(button::Variant::Danger)
                    .on_press(Message::Opened {
                        slot: slot::DELETE,
                        open: false,
                    }),
            ),
    )
    .on_open_change(|open| Message::Opened {
        slot: slot::DELETE,
        open,
    });
const deleteOpen = signal(false);
const deleteExample = (
  <>
    <Button label="Delete file" variant="danger" onPress={() => deleteOpen.set(true)} />
    <AlertDialog
      open={deleteOpen()}
      icon="trash"
      title="Delete this file?"
      description="It will be removed for everyone with access to this workspace."
      confirmLabel="Delete file"
      destructive
      onConfirm={() => deleteOpen.set(false)}
      onCancel={() => deleteOpen.set(false)}
      onClose={() => deleteOpen.set(false)}
    >
      <View
        style={{
          flexDirection: "row",
          alignItems: "center",
          gap: SPACING_SM,
          padding: SPACING_SM,
          borderRadius: RADIUS_MD,
          backgroundColor: tokens.muted,
        }}
      >
        <Icon name="file-text" size={18} color={tokens.mutedForeground} />
        <View style={{ flex: 1, gap: 1 }}>
          <Text style={{ fontSize: 13, fontWeight: "600", color: tokens.foreground }}>
            quarterly-report.pdf
          </Text>
          <Text style={{ fontSize: 12, color: tokens.mutedForeground }}>
            2.4 MB · Shared with 3 people
          </Text>
        </View>
        <Tag label="Shared" variant="secondary" size="xsmall" />
      </View>
    </AlertDialog>
  </>
);

Using imperative API:

Button::new("delete")
    .danger()
    .label("Delete")
    .on_click(|_, window, cx| {
        window.open_alert_dialog(cx, |alert, _, _| {
            alert
                .title("Delete File?")
                .description("This action cannot be undone.")
                .confirm()
                .ok_text("Delete")
                .ok_variant(ButtonVariant::Danger)
                .on_ok(|_, window, cx| {
                    // Perform delete operation
                    window.push_notification("File deleted", cx);
                    true
                })
        });
    })
row: root.row-of(1);
col: root.col-of(1);
Preview {
    label: "Delete File";
    clicked => {
        root.delete-file-open = true;
    }
    Dialog {
        width: 100%;
        height: 100%;
        open <=> root.delete-file-open;
        show-close: false;
        HorizontalLayout {
            spacing: 12px;
            Icon {
                name: "info";
                size: 20px;
                color: Theme.danger;
            }
            VerticalLayout {
                spacing: 4px;
                horizontal-stretch: 1;
                Text {
                    text: "Delete File";
                    color: Theme.foreground;
                    font-size: Theme.font-size-lg;
                    font-weight: 600;
                }
                Text {
                    text: "Are you sure you want to delete this file? This action cannot be undone.";
                    color: Theme.muted-foreground;
                    font-size: Theme.font-size-sm;
                    wrap: word-wrap;
                }
            }
        }
        DialogFooter {
            centered: true;
            Button {
                text: "Cancel";
                clicked => {
                    root.delete-file-open = false;
                }
            }
            Button {
                text: "Delete";
                variant: ButtonVariant.danger;
                clicked => {
                    root.delete-file-open = false;
                }
            }
        }
    }
}
NSHNo NSH version of this example yet.

Or using declarative API with DialogAction/DialogClose:

AlertDialog::new(cx)
    .trigger(Button::new("delete").danger().label("Delete"))
    .on_ok(|_, window, cx| {
        window.push_notification("File deleted", cx);
        true
    })
    .content(|content, _, cx| {
        content
            .child(
                DialogHeader::new()
                    .child(DialogTitle::new().child("Delete File?"))
                    .child(DialogDescription::new().child("This action cannot be undone."))
            )
            .child(
                DialogFooter::new()
                    .child(
                        DialogClose::new().child(
                            Button::new("cancel").outline().label("Cancel")
                        )
                    )
                    .child(
                        DialogAction::new().child(
                            Button::new("delete-confirm").danger().label("Delete")
                        )
                    )
            )
    })
SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.

#Icon

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// The centered prompt: the glyph, the title and the line stacked, and the
// two full-width actions stacked under them. A `footer` accepts any element,
// so it is a column here rather than the usual row.
let icon = body_box(
    column![
        open_button("Request Permission", slot::ICON),
        muted_line("Everything is centered, and the actions are stacked full width."),
    ]
    .spacing(8.0),
);
let icon_dialog =
    Dialog::new()
        .open(app.open[slot::ICON])
        .close_button(false)
        .content(
            column![
            container(
                svg(svg::Handle::from_memory(TRIANGLE_ALERT))
                    .width(40.0)
                    .height(40.0)
                    .style(|theme: &Theme, _status| svg::Style {
                        color: Some(Tokens::of(theme).warning),
                    })
            )
            .width(Length::Fill)
            .center_x(Length::Fill),
            container(
                text("Network Permission Required")
                    .size(theme::FONT_SIZE_LG)
                    .font(iced::Font {
                        weight: iced::font::Weight::Semibold,
                        ..iced::Font::DEFAULT
                    })
            )
            .width(Length::Fill)
            .center_x(Length::Fill),
            container(
                text("We need your permission to access the network. Allow access to continue.")
                    .size(theme::FONT_SIZE_SM)
                    .style(|theme: &Theme| text::Style {
                        color: Some(Tokens::of(theme).muted_foreground),
                    })
            )
            .width(Length::Fill)
            .center_x(Length::Fill),
        ]
            .spacing(8.0),
        )
        .footer(
            DialogFooter::new()
                .centered(true)
                .child(close_button("Cancel", slot::DELETE))
                .child(Button::new("Delete").on_press(Message::Opened {
                    slot: slot::DELETE,
                    open: false,
                })),
        )
        .on_open_change(|open| Message::Opened {
            slot: slot::ICON,
            open,
        });
const iconOpen = signal(false);
const iconExample = (
  <>
    <Button label="Discard draft" onPress={() => iconOpen.set(true)} />
    <AlertDialog
      open={iconOpen()}
      icon="triangle-alert"
      tone="warning"
      title="Unsaved changes"
      description="Leaving now discards the edits you made in this draft."
      confirmLabel="Discard"
      cancelLabel="Keep editing"
      destructive
      onConfirm={() => iconOpen.set(false)}
      onCancel={() => iconOpen.set(false)}
      onClose={() => iconOpen.set(false)}
    />
  </>
);

Using icon in declarative API:

use gpui_kit::component::{Icon, IconName, ActiveTheme};

AlertDialog::new(cx)
    .w(px(320.))
    .trigger(Button::new("permission").outline().label("Request Permission"))
    .on_ok(|_, window, cx| {
        window.push_notification("Permission granted", cx);
        true
    })
    .content(|content, _, cx| {
        content
            .child(
                DialogHeader::new()
                    .items_center()
                    .child(
                        Icon::new(IconName::TriangleAlert)
                            .size_10()
                            .text_color(cx.theme().warning)
                    )
                    .child(DialogTitle::new().child("Network Permission Required"))
                    .child(DialogDescription::new().child(
                        "We need your permission to access the network to provide better services."
                    ))
            )
            .child(
                DialogFooter::new()
                    .v_flex()
                    .child(
                        DialogAction::new().child(
                            Button::new("allow").w_full().primary().label("Allow")
                        )
                    )
                    .child(
                        DialogClose::new().child(
                            Button::new("deny").w_full().outline().label("Don't Allow")
                        )
                    )
            )
    })
row: root.row-of(2);
col: root.col-of(2);
Preview {
    label: "Request Permission";
    clicked => {
        root.permission-open = true;
    }
    Dialog {
        width: 100%;
        height: 100%;
        open <=> root.permission-open;
        show-close: false;
        VerticalLayout {
            alignment: center;
            spacing: 8px;
            Icon {
                name: "triangle-alert";
                size: 40px;
                color: Theme.warning;
            }
            Text {
                text: "Network Permission Required";
                color: Theme.foreground;
                font-size: Theme.font-size-lg;
                font-weight: 600;
                horizontal-alignment: center;
                wrap: word-wrap;
            }
            Text {
                text: "We need your permission to access the network. Allow access to continue.";
                color: Theme.muted-foreground;
                font-size: Theme.font-size-sm;
                horizontal-alignment: center;
                wrap: word-wrap;
            }
        }
        VerticalLayout {
            spacing: 8px;
            Button {
                text: "Allow";
                variant: ButtonVariant.primary;
                horizontal-stretch: 1;
                clicked => {
                    root.permission-open = false;
                }
            }
            Button {
                text: "Deny";
                outline: true;
                horizontal-stretch: 1;
                clicked => {
                    root.permission-open = false;
                }
            }
        }
    }
}
NSHNo NSH version of this example yet.

Using icon in imperative API:

window.open_alert_dialog(cx, |alert, _, cx| {
    alert
        .title("Warning")
        .description("This action requires confirmation.")
        .icon(
            Icon::new(IconName::AlertTriangle)
                .size_8()
                .text_color(cx.theme().warning)
        )
})
SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.

#Destructive

AlertDialog::new(cx)
    .trigger(
        Button::new("delete-account")
            .outline()
            .danger()
            .label("Delete Account")
    )
    .on_ok(|_, window, cx| {
        window.push_notification("Account deletion initiated", cx);
        true
    })
    .content(|content, _, _| {
        content
            .child(
                DialogHeader::new()
                    .child(DialogTitle::new().child("Delete Account"))
                    .child(DialogDescription::new().child(
                        "This will permanently delete your account \
                        and all associated data. This action cannot be undone."
                    ))
            )
            .child(
                DialogFooter::new()
                    .child(
                        DialogClose::new().child(
                            Button::new("cancel").flex_1().outline().label("Cancel")
                        )
                    )
                    .child(
                        DialogAction::new().child(
                            Button::new("delete")
                                .flex_1()
                                .outline()
                                .danger()
                                .label("Delete Forever")
                        )
                    )
            )
    })
row: root.row-of(3);
col: root.col-of(3);
Preview {
    label: "Delete Account";
    variant: ButtonVariant.danger;
    clicked => {
        root.account-open = true;
    }
    Dialog {
        width: 100%;
        height: 100%;
        open <=> root.account-open;
        show-close: false;
        title: "Delete Account";
        description: "This will permanently delete your account and all associated data. This action cannot be undone.";
        DialogFooter {
            centered: true;
            Button {
                text: "Cancel";
                outline: true;
                horizontal-stretch: 1;
                clicked => {
                    root.account-open = false;
                }
            }
            Button {
                text: "Delete";
                outline: true;
                variant: ButtonVariant.danger;
                horizontal-stretch: 1;
                clicked => {
                    root.account-open = false;
                }
            }
        }
    }
}
// Both actions are outlined and share the row, which is the Slint example's
// `horizontal-stretch` on each button.
let destructive = body_box(
    column![
        open_button("Delete Account", slot::DESTRUCTIVE),
        muted_line("Two outlined actions share the row."),
    ]
    .spacing(8.0),
);
let destructive_dialog = Dialog::new()
    .open(app.open[slot::DESTRUCTIVE])
    .close_button(false)
    .title("Delete Account")
    .description(
        "This will permanently delete your account and all associated data. \
         This action cannot be undone.",
    )
    .footer(
        DialogFooter::new()
            .centered(true)
            .child(
                Button::new("Cancel")
                    .outline()
                    .width(Length::Fill)
                    .on_press(Message::Opened {
                        slot: slot::DESTRUCTIVE,
                        open: false,
                    }),
            )
            .child(
                Button::new("Delete")
                    .outline()
                    .variant(button::Variant::Danger)
                    .width(Length::Fill)
                    .on_press(Message::Opened {
                        slot: slot::DESTRUCTIVE,
                        open: false,
                    }),
            ),
    )
    .on_open_change(|open| Message::Opened {
        slot: slot::DESTRUCTIVE,
        open,
    });
const destructiveOpen = signal(false);
const destructiveExample = (
  <>
    <Button label="Delete account" variant="danger" onPress={() => destructiveOpen.set(true)} />
    <AlertDialog
      open={destructiveOpen()}
      title="Delete account?"
      description="This permanently removes your account and every project you own. This cannot be undone."
      confirmLabel="Delete account"
      cancelLabel="Keep account"
      destructive
      onConfirm={() => destructiveOpen.set(false)}
      onCancel={() => destructiveOpen.set(false)}
      onClose={() => destructiveOpen.set(false)}
    />
  </>
);

#Without title

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// The component itself: `AlertDialog` builds the centered footer from its
// two labels, and an empty title simply draws no title.
let untitled = body_box(
    column![
        open_button("Continue without Title", slot::UNTITLED),
        muted_line("`AlertDialog` with a description and no title."),
    ]
    .spacing(8.0),
);
let untitled_dialog = AlertDialog::new()
    .open(app.open[slot::UNTITLED])
    .description("Continue with this action?")
    .confirm_text("Continue")
    .on_confirm(Message::Opened {
        slot: slot::UNTITLED,
        open: false,
    })
    .on_open_change(|open| Message::Opened {
        slot: slot::UNTITLED,
        open,
    });
const untitledOpen = signal(false);
const untitledExample = (
  <>
    <Button label="Sync changes" onPress={() => untitledOpen.set(true)} />
    <AlertDialog
      open={untitledOpen()}
      description="Your changes are saved on this device. Continue to sync them to the cloud?"
      confirmLabel="Sync now"
      cancelLabel="Later"
      onConfirm={() => untitledOpen.set(false)}
      onCancel={() => untitledOpen.set(false)}
      onClose={() => untitledOpen.set(false)}
    />
  </>
);

Create a fully declarative AlertDialog using trigger and content:

use gpui_kit::component::dialog::{AlertDialog, DialogHeader, DialogTitle, DialogDescription, DialogFooter};

AlertDialog::new(cx)
    .trigger(
        Button::new("show-alert")
            .outline()
            .label("Show Alert")
    )
    .content(|content, _, cx| {
        content
            .child(
                DialogHeader::new()
                    .child(DialogTitle::new().child("Are you absolutely sure?"))
                    .child(DialogDescription::new().child(
                        "This action cannot be undone. \
                        This will permanently delete your account from our servers."
                    ))
            )
            .child(
                DialogFooter::new()
                    .child(
                        Button::new("cancel")
                            .outline()
                            .label("Cancel")
                            .on_click(|_, window, cx| {
                                window.close_dialog(cx);
                            })
                    )
                    .child(
                        Button::new("ok")
                            .primary()
                            .label("Continue")
                            .on_click(|_, window, cx| {
                                window.push_notification("Confirmed", cx);
                                window.close_dialog(cx);
                            })
                    )
            )
    })
row: root.row-of(4);
col: root.col-of(4);
Preview {
    label: "Continue without Title";
    clicked => {
        root.untitled-open = true;
    }
    AlertDialog {
        width: 100%;
        height: 100%;
        open <=> root.untitled-open;
        description: "Continue with this action?";
        confirm-text: "Continue";
    }
}
NSHNo NSH version of this example yet.
GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// A single full-width action where the footer would be: the panel's body is
// the caller's, so the "footer" is just the last child.
let footer = body_box(
    column![
        open_button("Show Session Expiry", slot::FOOTER),
        muted_line("A single full-width action stands in for the footer."),
    ]
    .spacing(8.0),
);
let footer_dialog = Dialog::new()
    .open(app.open[slot::FOOTER])
    .close_button(false)
    .title("Session Expired")
    .description("Your session has expired due to inactivity. Please log in again to continue.")
    .content(
        Button::new("Sign in")
            .variant(button::Variant::Primary)
            .width(Length::Fill)
            .on_press(Message::Opened {
                slot: slot::FOOTER,
                open: false,
            }),
    )
    .on_open_change(|open| Message::Opened {
        slot: slot::FOOTER,
        open,
    });
const footerOpen = signal(false);
const footerExample = (
  <>
    <Button label="Restart required" onPress={() => footerOpen.set(true)} />
    <AlertDialog
      open={footerOpen()}
      icon="refresh-cw"
      tone="success"
      title="Restart to finish"
      description="The update is ready. Restarting keeps your open files."
      showClose
      footer={
        <>
          <Button
            label="Ask me later"
            variant="ghost"
            onPress={() => footerOpen.set(false)}
            style={{ flex: 1 }}
          />
          <Button
            label="Restart app"
            variant="primary"
            onPress={() => footerOpen.set(false)}
            style={{ flex: 1 }}
          />
        </>
      }
      onClose={() => footerOpen.set(false)}
    />
  </>
);

Set the button text and variant directly on the dialog:

use gpui_kit::component::button::ButtonVariant;

window.open_alert_dialog(cx, |alert, _, _| {
    alert
        .title("Delete Account")
        .description("This will permanently delete your account and all associated data.")
        .confirm()
        .ok_text("Delete")
        .ok_variant(ButtonVariant::Danger)
        .cancel_text("Keep")
        .on_ok(|_, window, cx| {
            window.push_notification("Account deleted", cx);
            true
        })
})
row: root.row-of(5);
col: root.col-of(5);
Preview {
    label: "Show Session Expiry";
    clicked => {
        root.session-open = true;
    }
    Dialog {
        width: 100%;
        height: 100%;
        open <=> root.session-open;
        show-close: false;
        title: "Session Expired";
        description: "Your session has expired due to inactivity. Please log in again to continue.";
        Button {
            text: "Sign in";
            variant: ButtonVariant.primary;
            horizontal-stretch: 1;
            clicked => {
                root.session-open = false;
            }
        }
    }
}
NSHNo NSH version of this example yet.

button_props takes the same properties as one value, for a configuration you want to build up or pass around. It overrides only the fields the value sets, so everything the dialog already carries — the Cancel button confirm asked for, a callback an earlier on_ok installed — survives, whatever the call order:

use gpui_kit::component::dialog::DialogButtonProps;

window.open_alert_dialog(cx, move |alert, _, _| {
    alert
        .title("Delete Account")
        .confirm()
        .button_props(
            DialogButtonProps::default()
                .ok_text("Delete")
                .ok_variant(ButtonVariant::Danger)
        )
})
SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.

#Custom content

AlertDialog::new(cx)
    .width(px(500.))
    .trigger(Button::new("custom-width").label("Custom Width"))
    .content(|content, _, _| {
        // ... dialog content
    })
row: root.row-of(6);
col: root.col-of(6);
Preview {
    label: "Install Update";
    clicked => {
        root.update-open = true;
    }
    Dialog {
        width: 100%;
        height: 100%;
        open <=> root.update-open;
        show-close: false;
        title: "Update Available";
        description: "A new version (v2.0.0) is available. This update includes new features and bug fixes.";
        Rectangle {
            background: Theme.muted;
            border-radius: Theme.radius-md;
            HorizontalLayout {
                padding: 12px;
                spacing: 8px;
                Button {
                    text: "Later";
                    outline: true;
                    horizontal-stretch: 1;
                    clicked => {
                        root.update-open = false;
                    }
                }
                Button {
                    text: "Update";
                    variant: ButtonVariant.primary;
                    horizontal-stretch: 1;
                    clicked => {
                        root.update-open = false;
                    }
                }
            }
        }
    }
}
// A muted trough holding the two actions, which is the Slint example's
// `Rectangle { background: Theme.muted }` around a row.
let content = body_box(
    column![
        open_button("Install Update", slot::CONTENT),
        muted_line("A muted trough holds the two actions."),
    ]
    .spacing(8.0),
);
let content_dialog = Dialog::new()
    .open(app.open[slot::CONTENT])
    .close_button(false)
    .title("Update Available")
    .description(
        "A new version (v2.0.0) is available. This update includes new features \
         and bug fixes.",
    )
    .content(
        container(
            row![
                Button::new("Later")
                    .outline()
                    .width(Length::Fill)
                    .on_press(Message::Opened {
                        slot: slot::CONTENT,
                        open: false,
                    }),
                Button::new("Update")
                    .variant(button::Variant::Primary)
                    .width(Length::Fill)
                    .on_press(Message::Opened {
                        slot: slot::CONTENT,
                        open: false,
                    }),
            ]
            .spacing(8.0),
        )
        .width(Length::Fill)
        .padding(12.0)
        .style(|theme: &Theme| container::Style {
            background: Some(Tokens::of(theme).muted.into()),
            border: iced::border::rounded(theme::RADIUS_MD),
            ..container::Style::default()
        }),
    )
    .on_open_change(|open| Message::Opened {
        slot: slot::CONTENT,
        open,
    });
const contentOpen = signal(false);
const contentExample = (
  <>
    <Button label="Transfer workspace" onPress={() => contentOpen.set(true)} />
    <AlertDialog
      open={contentOpen()}
      icon="users"
      tone="info"
      title="Transfer workspace"
      description="Choose the teammate who will own this workspace."
      confirmLabel="Send invite"
      cancelLabel="Cancel"
      onConfirm={() => contentOpen.set(false)}
      onCancel={() => contentOpen.set(false)}
      onClose={() => contentOpen.set(false)}
    >
      <View style={{ gap: SPACING_SM }}>
        <Input placeholder="Search teammates" prefixIcon="search" onChangeText={() => {}} />
        <View
          style={{
            flexDirection: "row",
            alignItems: "center",
            gap: SPACING_SM,
            padding: SPACING_SM,
            borderRadius: RADIUS_MD,
            borderWidth: 1,
            borderColor: tokens.border,
          }}
        >
          <Avatar name="Ada Lovelace" size="sm" />
          <View style={{ flex: 1, gap: 1 }}>
            <Text style={{ fontSize: 13, fontWeight: "600", color: tokens.foreground }}>
              Ada Lovelace
            </Text>
            <Text style={{ fontSize: 12, color: tokens.mutedForeground }}>ada@example.com</Text>
          </View>
          <Tag label="Admin" variant="info" size="xsmall" />
        </View>
      </View>
    </AlertDialog>
  </>
);

#Notice

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// An acknowledgement: one full-width action in the centered footer.
let notice = body_box(
    column![
        open_button("Review Notice", slot::NOTICE),
        muted_line("An acknowledgement with one action to dismiss it."),
    ]
    .spacing(8.0),
);
let notice_dialog = Dialog::new()
    .open(app.open[slot::NOTICE])
    .close_button(false)
    .title("Important Notice")
    .description("Please read this important notice carefully before proceeding.")
    .footer(
        DialogFooter::new().centered(true).child(
            Button::new("Got It")
                .variant(button::Variant::Primary)
                .on_press(Message::Opened {
                    slot: slot::NOTICE,
                    open: false,
                }),
        ),
    )
    .on_open_change(|open| Message::Opened {
        slot: slot::NOTICE,
        open,
    });
const noticeOpen = signal(false);
const noticeExample = (
  <>
    <Button label="View maintenance notice" onPress={() => noticeOpen.set(true)} />
    <AlertDialog
      open={noticeOpen()}
      icon="info"
      tone="info"
      title="Scheduled maintenance"
      description="The workspace will be read-only on Sunday from 02:00 to 03:00 UTC."
      confirmLabel="Got it"
      showCancel={false}
      onConfirm={() => noticeOpen.set(false)}
      onClose={() => noticeOpen.set(false)}
    />
  </>
);

DialogAction and DialogClose are wrapper components that simplify button click handling by automatically triggering the appropriate actions:

  • DialogClose: Wraps a button to trigger the Cancel action, invoking on_cancel callback
  • DialogAction: Wraps a button to trigger the Confirm action, invoking on_ok callback

These components eliminate the need to manually call window.close_dialog(cx):

AlertDialog::new(cx)
    .trigger(Button::new("show-alert").outline().label("Show Alert"))
    .on_ok(|_, window, cx| {
        window.push_notification("You confirmed!", cx);
        true  // Return true to close dialog
    })
    .on_cancel(|_, window, cx| {
        window.push_notification("You cancelled!", cx);
        true
    })
    .content(|content, _, cx| {
        content
            .child(
                DialogHeader::new()
                    .child(DialogTitle::new().child("Confirm Action"))
                    .child(DialogDescription::new().child("Do you want to proceed?"))
            )
            .child(
                DialogFooter::new()
                    .child(
                        DialogClose::new().child(
                            Button::new("cancel").outline().label("Cancel")
                        )
                    )
                    .child(
                        DialogAction::new().child(
                            Button::new("ok").primary().label("Confirm")
                        )
                    )
            )
    })
row: root.row-of(7);
col: root.col-of(7);
Preview {
    label: "Review Notice";
    clicked => {
        root.notice-open = true;
    }
    Dialog {
        width: 100%;
        height: 100%;
        open <=> root.notice-open;
        show-close: false;
        title: "Important Notice";
        description: "Please read this important notice carefully before proceeding.";
        DialogFooter {
            centered: true;
            Button {
                text: "Got It";
                variant: ButtonVariant.primary;
                clicked => {
                    root.notice-open = false;
                }
            }
        }
    }
}
NSHNo NSH version of this example yet.

Benefits:

  • No need to manually close the dialog
  • Automatically connects to on_ok and on_cancel callbacks
  • Cleaner, more declarative code
  • Supports returning false from callbacks to prevent closing

#Confirm

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// `AlertDialog` again, this time with the title and the primary confirm
// label the caller chose.
let confirm = body_box(
    column![
        open_button("Open Confirmation", slot::CONFIRM),
        muted_line("`AlertDialog` with a title and a confirm label."),
    ]
    .spacing(8.0),
);
let confirm_dialog = AlertDialog::new()
    .open(app.open[slot::CONFIRM])
    .title("Are you sure?")
    .description("Continue with this action?")
    .confirm_text("OK")
    .on_confirm(Message::Opened {
        slot: slot::CONFIRM,
        open: false,
    })
    .on_open_change(|open| Message::Opened {
        slot: slot::CONFIRM,
        open,
    });
NSHNo NSH version of this example yet.

Open a dialog imperatively using WindowExt::open_alert_dialog:

window.open_alert_dialog(cx, |alert, _, _| {
    alert
        .title("Delete File")
        .description("Are you sure you want to delete this file? This action cannot be undone.")
        .show_cancel(true)
        .on_ok(|_, window, cx| {
            window.push_notification("File deleted", cx);
            true // Return true to close dialog
        })
})
row: root.row-of(8);
col: root.col-of(8);
Preview {
    label: "Open Confirmation";
    clicked => {
        root.confirm-open = true;
    }
    AlertDialog {
        width: 100%;
        height: 100%;
        open <=> root.confirm-open;
        title: "Are you sure?";
        description: "Continue with this action?";
        confirm-text: "OK";
    }
}
NSHNo NSH version of this example yet.

#Prevent close

GPUINo GPUI version of this example yet.
SlintNo Slint version of this example yet.
// The footer buttons write the dialog's line instead of closing it; only the
// close button and the backdrop ask the caller to close, which is what
// `on_open_change` reports.
let sync = body_box(
    column![
        open_button("Close During Sync", slot::SYNC),
        muted_line("Nothing in the footer closes it; its buttons write the line."),
    ]
    .spacing(8.0),
);
let sync_note = if app.sync_note.is_empty() {
    "Your changes are still syncing. The dialog stays open until syncing finishes.".to_string()
} else {
    app.sync_note.clone()
};
let sync_dialog = Dialog::new()
    .open(app.open[slot::SYNC])
    .title("Sync in progress")
    .description(sync_note)
    .footer(
        DialogFooter::new()
            .centered(true)
            .child(
                Button::new("Wait")
                    .on_press(Message::Note("Waiting for sync to finish.".to_string())),
            )
            .child(
                Button::new("Close")
                    .variant(button::Variant::Primary)
                    .on_press(Message::Note("Cannot close while syncing.".to_string())),
            ),
    )
    .on_open_change(|open| Message::Opened {
        slot: slot::SYNC,
        open,
    });
NSHNo NSH version of this example yet.

#Allow Overlay Click to Close

window.open_alert_dialog(cx, |alert, _, _| {
    alert
        .title("Notice")
        .description("Click outside this dialog or press ESC to close it.")
        .overlay_closable(true)
})
SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.

#Disable Keyboard ESC to Close

window.open_alert_dialog(cx, |alert, _, _| {
    alert
        .title("Important Notice")
        .description("Please read this carefully before proceeding.")
        .keyboard(false)
})
SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.

#Show Close Button

window.open_alert_dialog(cx, |alert, _, _| {
    alert
        .title("Information")
        .description("Some information...")
        .close_button(true)
})
SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.

#Prevent Dialog from Closing

Return false from on_ok or on_cancel callbacks to prevent the dialog from closing:

window.open_alert_dialog(cx, |alert, _, _| {
    alert
        .title("Processing")
        .description("A process is running. Click Continue to stop it or Cancel to keep waiting.")
        .confirm()
        .ok_text("Continue")
        .on_ok(|_, window, cx| {
            // Return false to prevent closing
            window.push_notification("Cannot close: Process still running", cx);
            false
        })
        .on_cancel(|_, window, cx| {
            window.push_notification("Waiting...", cx);
            false
        })
})
row: root.row-of(9);
col: root.col-of(9);
Preview {
    label: "Close During Sync";
    clicked => {
        root.sync-open = true;
    }
    Dialog {
        width: 100%;
        height: 100%;
        open <=> root.sync-open;
        title: "Sync in progress";
        description: root.sync-note == "" ? "Your changes are still syncing. The dialog stays open until syncing finishes." : root.sync-note;
        DialogFooter {
            centered: true;
            Button {
                text: "Wait";
                clicked => {
                    root.sync-note = "Waiting for sync to finish.";
                }
            }
            Button {
                text: "Close";
                variant: ButtonVariant.primary;
                clicked => {
                    root.sync-note = "Cannot close while syncing.";
                }
            }
        }
    }
}
NSHNo NSH version of this example yet.

#Dialog Close Callback

Use on_close to execute actions after the dialog closes (called after on_ok or on_cancel):

window.open_alert_dialog(cx, |alert, _, _| {
    alert
        .title("Confirm")
        .description("Are you sure?")
        .on_close(|_, window, cx| {
            window.push_notification("Dialog closed", cx);
        })
})
SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.

#Session Timeout

window.open_alert_dialog(cx, |alert, _, _| {
    alert
        .content(|content, _, _| {
            content
                .child(
                    DialogHeader::new()
                        .items_center()
                        .child(DialogTitle::new().child("Session Expired"))
                        .child(DialogDescription::new().child(
                            "Your session has expired due to inactivity. \
                            Please log in again to continue."
                        ))
                )
                .child(
                    DialogFooter::new()
                        .child(
                            Button::new("sign-in")
                                .label("Sign in")
                                .primary()
                                .flex_1()
                                .on_click(|_, window, cx| {
                                    window.push_notification("Redirecting to login...", cx);
                                    window.close_dialog(cx);
                                })
                        )
                )
        })
})
SlintNo Slint version of this example yet.
const sessionOpen = signal(false);
const sessionExample = (
  <>
    <Button label="Simulate session timeout" onPress={() => sessionOpen.set(true)} />
    <AlertDialog
      open={sessionOpen()}
      icon="clock"
      tone="warning"
      title="Session expired"
      description="You were signed out after 30 minutes of inactivity. Sign in to continue where you left off."
      confirmLabel="Sign in"
      showCancel={false}
      onConfirm={() => sessionOpen.set(false)}
      onClose={() => sessionOpen.set(false)}
    />
  </>
);

#Update Available

AlertDialog::new(cx)
    .trigger(Button::new("update").outline().label("Update Available"))
    .on_cancel(|_, window, cx| {
        window.push_notification("Update postponed", cx);
        true
    })
    .on_ok(|_, window, cx| {
        window.push_notification("Starting update...", cx);
        true
    })
    .content(|content, _, _| {
        content
            .child(
                DialogHeader::new()
                    .child(DialogTitle::new().child("Update Available"))
                    .child(DialogDescription::new().child(
                        "A new version (v2.0.0) is available. \
                        This update includes new features and bug fixes."
                    ))
            )
            .child(
                DialogFooter::new()
                    .child(
                        DialogClose::new().child(
                            Button::new("later").flex_1().outline().label("Later")
                        )
                    )
                    .child(
                        DialogAction::new().child(
                            Button::new("update-now").flex_1().primary().label("Update Now")
                        )
                    )
            )
    })
SlintNo Slint version of this example yet.
const updateOpen = signal(false);
const updating = signal(false);
const updateExample = (
  <>
    <Button label="Check for updates" onPress={() => updateOpen.set(true)} />
    <AlertDialog
      open={updateOpen()}
      icon="download"
      tone="success"
      title="Update available"
      description="Version 2.0 adds faster sync and a new command bar."
      confirmLabel={updating() ? "Updating…" : "Update now"}
      cancelLabel="Later"
      loading={updating()}
      showClose
      onConfirm={() => {
        updating.set(true);
        setTimeout(() => {
          updating.set(false);
          updateOpen.set(false);
        }, 1200);
      }}
      onCancel={() => {
        if (!updating()) updateOpen.set(false);
      }}
      onClose={() => {
        if (!updating()) updateOpen.set(false);
      }}
    />
  </>
);

#Best Practices

  1. Choose the Right API: Use imperative API (open_alert_dialog) for simple confirmations; use declarative API (trigger + content) for complex layouts or integration with other components
  2. Use DialogAction and DialogClose: Prefer wrapping buttons with DialogAction and DialogClose over manual window.close_dialog() calls for cleaner, more declarative code
  3. Clarify Intent: Use appropriate button variants (e.g., ButtonVariant::Danger for delete operations) to communicate the importance of actions
  4. Provide Clear Descriptions: Ensure users understand the consequences of their actions, especially for destructive operations
  5. Use Icons Wisely: Icons can enhance attention for warnings and errors, but use them appropriately
  6. Prevent Closing Carefully: Only prevent dialog closing when user confirmation is truly necessary (e.g., a process is running)
  7. Maintain Consistency: Keep dialog button order and styles consistent throughout your application

#API Reference

#AlertDialog

MethodDescription
new(cx)Create a new AlertDialog
trigger(element)Set trigger element that opens the dialog when clicked
content(builder)Set dialog content using a builder function (declarative API)
title(title)Set dialog title (imperative API)
description(desc)Set dialog description (imperative API)
icon(icon)Set dialog icon (imperative API)
confirm()Show OK and Cancel buttons
ok_text(text)Set OK button text, default “OK”
ok_variant(variant)Set OK button variant, default Primary
cancel_text(text)Set cancel button text, default “Cancel”
cancel_variant(variant)Set cancel button variant
button_props(props)Override the button properties the value sets, keep the rest
show_cancel(bool)Show/hide cancel button, default false
width(px)Set dialog width, default 420px
overlay_closable(bool)Allow clicking overlay to close, default false
close_button(bool)Show/hide close button, default false
keyboard(bool)Support ESC key to close, default true
on_ok(callback)Set OK button callback, return true to close dialog
on_cancel(callback)Set cancel button callback, return true to close dialog
on_close(callback)Set callback after dialog closes

#DialogButtonProps

Every property is unset until a builder sets it, and an unset property keeps whatever the dialog already carries.

MethodDescription
ok_text(text)Set OK button text, default “OK”
cancel_text(text)Set cancel button text, default “Cancel”
ok_variant(variant)Set OK button variant
cancel_variant(variant)Set cancel button variant
show_cancel(bool)Show/hide cancel button
on_ok(callback)Set OK callback
on_cancel(callback)Set cancel callback

#DialogAction

A wrapper component that automatically triggers the Confirm action when its child element is clicked. This invokes the on_ok callback set on the AlertDialog.

Usage:

DialogAction::new().child(
    Button::new("ok").primary().label("Confirm")
)
SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.

Behavior:

  • Dispatches Confirm action on click
  • Invokes the on_ok callback
  • Dialog closes if callback returns true
  • Dialog stays open if callback returns false

#DialogClose

A wrapper component that automatically triggers the Cancel action when its child element is clicked. This invokes the on_cancel callback set on the AlertDialog.

Usage:

DialogClose::new().child(
    Button::new("cancel").outline().label("Cancel")
)
SlintNo Slint version of this example yet.
NSHNo NSH version of this example yet.

Behavior:

  • Dispatches Cancel action on click
  • Invokes the on_cancel callback
  • Dialog closes if callback returns true (or if no callback is set)
  • Dialog stays open if callback returns false

#AlertDialog

A confirmation dialog. Mirrors GPUI Component's `AlertDialog`.

NameKindTypeDefault
openin-outbool
titleinstring
descriptioninstring
cancel-textinstring"Cancel"
confirm-textinstring"Continue"
destructiveinbool
cancelledcallback()
confirmedcallback()