Motion-Primitives Pro is live - Advanced components and templates to help you build delightful websites, faster.

Dialog

A window overlaid on either the primary window or another dialog window, rendering the content underneath inert. Customize the dialog with variants and transition.

Examples

Basic Dialog

Controlled Dialog

You can control the open state of the dialog using the open and onOpenChange props.

Dialog with custom variants and transition

Dialog with custom exit animation

You can customize the exit animation by providing a custom exit variant.

Dialog with custom backdrop

You can customize the backdrop using the backdrop: prefix on DialogContent, e.g., backdrop:bg-white/20.

Installation

npx shadcn add "https://motion-primitives.com/c/dialog.json" "https://motion-primitives.com/h/usePreventScroll.json"

Component API

Dialog

PropTypeDefaultDescription
childrenReactNoderequiredChildren to be rendered within the dialog.
variantsVariantsVariants for controlling the animation states with specific properties for initial, animate, and exit states.
transitionTransitionTransition settings from framer-motion for animation effects.
classNamestringOptional CSS class for styling the dialog container.
defaultOpenbooleanfalseIf true, the dialog will be open by default.
onOpenChange(open: boolean) => voidCallback function that is called when the dialog's open state changes.
openbooleanControlled open state of the dialog.

DialogTrigger

PropTypeDefaultDescription
childrenReactNoderequiredThe content to be rendered inside the trigger button.
classNamestringOptional CSS class for styling the trigger button.

DialogContent

PropTypeDefaultDescription
childrenReactNoderequiredThe content to be rendered inside the dialog.
classNamestringOptional CSS class for styling the dialog content.
containerHTMLElementdocument.bodySpecify a container element to portal the content into.

DialogHeader

PropTypeDefaultDescription
childrenReactNoderequiredThe content to be rendered inside the dialog header.
classNamestringOptional CSS class for styling the dialog header.

DialogTitle

PropTypeDefaultDescription
childrenReactNoderequiredThe title content to be rendered inside the dialog.
classNamestringOptional CSS class for styling the dialog title.

DialogDescription

PropTypeDefaultDescription
childrenReactNoderequiredThe description content to be rendered inside the dialog.
classNamestringOptional CSS class for styling the dialog description.

DialogClose

PropTypeDefaultDescription
classNamestringOptional CSS class for styling the close button.
childrenReactNodeOptional content to be rendered inside the close button. If not provided, a default close icon will be used.
disabledbooleanIf true, the close button will be disabled.