Dialog
A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.
use leptos::prelude::*; use singlestage::*; #[component] pub fn DialogExample() -> impl IntoView { view! { <Dialog class="sm:max-w-sm"> <DialogTrigger> <Button variant="outline">"Open Dialog"</Button> </DialogTrigger> <DialogContent> <form> <DialogHeader> <DialogTitle>"Edit profile"</DialogTitle> <DialogDescription> "Make changes to your profile here. Click save when you're done." </DialogDescription> </DialogHeader> <FieldGroup> <Field> <Input name="name" value="Pedro Duarte"> "Name" </Input> </Field> <Field> <Input name="username" value="@peduarte"> "Username" </Input> </Field> </FieldGroup> <DialogFooter> <DialogClose> <Button>"Cancel"</Button> </DialogClose> <Button button_type="submit">"Save changes"</Button> </DialogFooter> </form> </DialogContent> </Dialog> } }
Custom Close Button
Replace the default close control with your own button.
use leptos::prelude::*; use singlestage::*; #[component] pub fn DialogCustomCloseButtonExample() -> impl IntoView { view! { <Dialog class="sm:max-w-md"> <DialogTrigger> <Button variant="outline">"Share"</Button> </DialogTrigger> <DialogContent> <DialogHeader> <DialogTitle>"Share link"</DialogTitle> <DialogDescription> "Anyone who has this link will be able to view this." </DialogDescription> </DialogHeader> <div class="flex items-center gap-2"> <div class="grid flex-1 gap-2"> <Label label_for="link" class="sr-only"> "Link" </Label> <Input id="link" value="https://singlestage.doordesk.net/install" readonly=true /> </div> </div> <DialogFooter class="sm:justify-start"> <DialogClose> <Button button_type="button">"Close"</Button> </DialogClose> </DialogFooter> </DialogContent> </Dialog> } }
No Close Button
Use close_button=false to hide the close button.
use leptos::prelude::*; use singlestage::*; #[component] pub fn DialogNoCloseButtonExample() -> impl IntoView { view! { <Dialog> <DialogTrigger> <Button variant="outline">"No Close Button"</Button> </DialogTrigger> <DialogContent close_button=false> <DialogHeader> <DialogTitle>"No Close Button"</DialogTitle> <DialogDescription> "This dialog doesn't have a close button in the top-right corner." </DialogDescription> </DialogHeader> </DialogContent> </Dialog> } }
Sticky Footer
Keep actions visible while the content scrolls.
use leptos::prelude::*; use singlestage::*; #[component] pub fn DialogStickyFooterExample() -> impl IntoView { view! { <Dialog> <DialogTrigger> <Button variant="outline">"Sticky Footer"</Button> </DialogTrigger> <DialogContent> <DialogHeader> <DialogTitle>"Sticky Footer"</DialogTitle> <DialogDescription> "This dialog has a sticky footer that stays visible while the content scrolls." </DialogDescription> </DialogHeader> <div class="no-scrollbar -mx-4 max-h-[50vh] overflow-y-auto px-4"> <For each=move || 0..10 key=|i| i.to_string() let(_)> <p class="mb-4 leading-normal"></p> "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." </For> </div> <DialogFooter> <DialogClose> <Button variant="outline">"Close"</Button> </DialogClose> </DialogFooter> </DialogContent> </Dialog> } }
Scrollable Content
Long content can scroll while the header stays in view.
use leptos::prelude::*; use singlestage::*; #[component] pub fn DialogScrollableContentExample() -> impl IntoView { view! { <Dialog> <DialogTrigger> <Button variant="outline">"Scrollable Content"</Button> </DialogTrigger> <DialogContent> <DialogHeader> <DialogTitle>"Scrollable Content"</DialogTitle> <DialogDescription> "This is a dialog with scrollable content." </DialogDescription> </DialogHeader> <div class="no-scrollbar -mx-4 max-h-[50vh] overflow-y-auto px-4"> <For each=move || 0..10 key=|i| i.to_string() let(_)> <p class="mb-4 leading-normal"> "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." </p> </For> </div> </DialogContent> </Dialog> } }
Anatomy
Import all parts and piece them together.
use leptos::prelude::*; use singlestage::*; #[component] pub fn DialogAnatomy -> impl IntoView { view!{ <Dialog> <DialogTrigger> <Button /> </DialogTrigger> <DialogContent> <DialogHeader> <DialogTitle /> <DialogDescription /> </DialogHeader> <DialogFooter> <DialogCancel /> <DialogAction /> </DialogFooter> </DialogContent> </Dialog> } }
API Reference
Dialog
Contains all the parts of a Dialog component.
| Name | Type | Default | Description |
|---|---|---|---|
| open | bool | false | Reactive signal that can remotely control the open state of the popover **but is not coupled to the actual open state of the popover** |
DialogAction
Wraps a button that the user presses to acknowledge the dialog.
DialogCancel
Wraps a button that the user presses to dismiss the dialog.
DialogContent
Contains content to be rendered in the main body of the dialog.
| Name | Type | Default | Description |
|---|---|---|---|
| close_button | bool | true | Toggles whether or not a close button should appear in the top right corner of the dialog. |
DialogDescription
A short description/subheading describing dialog content.
DialogFooter
Displays at the bottom of the dialog, contains calls to action.
DialogHeader
Contains the dialog title and a description to be rendered in the open dialog.
DialogTrigger
Used to wrap other elements and trigger the dialog on click.