unstable_Dialog API
- Component status:
unstable
import { unstable_Dialog as Dialog } from "@stratakit/structures";// ORimport * as Dialog from "@stratakit/structures/unstable_Dialog";Dialog.Root
Section titled âDialog.RootâA modal dialog component used to display content in a window overlay. Must include Dialog.Header and Dialog.Content as direct
descendants. Additionally, Dialog.Footer can be optionally used as a direct descendant.
Example:
const [open, setOpen] = useState(false);
<Dialog.Root modal={true} open={open} onClose={() => setOpen(false)}> <Dialog.Heading>Heading</Dialog.Heading> <Dialog.Content>Content</Dialog.Content> <Dialog.Footer> <Dialog.ActionList actions={[ <Button key="ok" onClick={() => setOpen(false)}>Ok</Button>, ]} />
</Dialog.Footer></Dialog.Root>true(required)Determines whether the dialog is modal. Currently, only modal dialogs are supported.
backdrop
Section titled âbackdropâboolean | ReactElement<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, string | JSXElementConstructor<any>> | ElementType<...> | undefined(optional)Determines whether there will be a backdrop behind the dialog. On modal
dialogs, this is true by default. Besides a boolean, this prop can also
be a React component or JSX element that will be rendered as the backdrop.
Note: If a custom component is used, it must accept ref and spread all props to its underlying DOM element, the same way a native element would.
hideOnInteractOutside
Section titled âhideOnInteractOutsideâBooleanOrCallback<Event | SyntheticEvent<Element, Event>> | undefined(optional)trueDetermines if the dialog should hide when the user clicks or focuses on an element outside the dialog.
This prop can be either a boolean or a function that takes an event as an argument and returns a boolean. The event object represents the event that triggered the action, which could be a native event or a React synthetic event of various types.
onClose
Section titled âonCloseâ((event: Event) => void) | undefined(optional)This is an event handler prop triggered when the dialogâs close event is
dispatched. The close event is similar to the native dialog
close
event. The only difference is that this event can be canceled with
event.preventDefault(), which will prevent the dialog from hiding.
Itâs important to note that this event only fires when the dialog storeâs
open state is set
to false. If the controlled
open prop value changes, or
if the dialogâs visibility is altered in any other way (such as unmounting
the dialog without adjusting the open state), this event wonât be
triggered.
boolean | undefined(optional)Controls the open state of the dialog. This is similar to the
open
attribute on native dialog elements.
unmountOnHide
Section titled âunmountOnHideâboolean | undefined(optional)trueWhen set to true, the content element will be unmounted and removed from
the DOM when itâs hidden.
Additional props
Section titled âAdditional propsâDialog.Header
Section titled âDialog.HeaderâThe header of a dialog. Should be used as a child of Dialog.Root. Must include Dialog.Heading as a direct
descendant. Additionally, Dialog.CloseButton can be optionally used as a direct descendant.
Example:
<Dialog.Header> <Dialog.Heading>Heading</Dialog.Heading> <Dialog.CloseButton /></Dialog.Header>Use render prop when only a heading is displayed in a header.
<Dialog.Header render={<Dialog.Heading />}>Heading</Dialog.Header>Additional props
Section titled âAdditional propsâDialog.Heading
Section titled âDialog.HeadingâThe heading of a dialog. Should be used as a child of Dialog.DialogHeader.
Example:
<Dialog.Heading>Heading</Dialog.Heading>Additional props
Section titled âAdditional propsâDialog.CloseButton
Section titled âDialog.CloseButtonâA button that closes the dialog. Displayed as an icon button in the top-right corner of the dialog.
Should be used as a child of Dialog.DialogHeader.
Example:
<Dialog.CloseButton />string | undefined(optional)"Dismiss"Label for the close button.
Additional props
Section titled âAdditional propsâDialog.Content
Section titled âDialog.ContentâThe content of a dialog. Should be used as a child of Dialog.Root.
Example:
<Dialog.Content>Content</Dialog.Content>Additional props
Section titled âAdditional propsâDialog.Footer
Section titled âDialog.FooterâThe footer section of a dialog, typically used to display action buttons at the bottom of the dialog.
Should be used as a child of Dialog.Root. Use Dialog.ActionList as a direct descendant to display a list of actions.
Example:
<Dialog.Footer> <Dialog.ActionList actions={[ <Button key="cancel" onClick={() => setOpen(false)}>Cancel</Button>, <Button key="ok" tone="accent" onClick={() => setOpen(false)}>Ok</Button>, ]} /></Dialog.Footer>Additional props
Section titled âAdditional propsâDialog.ActionList
Section titled âDialog.ActionListâA container for action buttons in a dialog. Should be used as a child of Dialog.Footer.
Example:
<Dialog.ActionList actions={[ <Button key="cancel" onClick={() => setOpen(false)}>Cancel</Button>, <Button key="ok" tone="accent" onClick={() => setOpen(false)}>Ok</Button>, ]}/>actions
Section titled âactionsâReactNode[] | undefined(optional)The actions available for the dialog. Must be a list of Button components.
Additional props
Section titled âAdditional propsâDialog.Backdrop
Section titled âDialog.BackdropâThe backdrop of a dialog. Should be passed into the backdrop prop of Dialog.Root.
Example:
<Dialog.Root modal={true} backdrop={<Dialog.Backdrop />} />