What is @radix-ui/react-dialog?
The @radix-ui/react-dialog package is a React component library that provides accessible and customizable dialog components. It allows developers to create modal dialogs, which are UI overlays that can contain text, forms, or other interactive elements. These dialogs are often used to capture user input or present information without navigating away from the current page.
What are @radix-ui/react-dialog's main functionalities?
Basic Dialog
This feature allows you to create a basic modal dialog with a trigger button. When the button is clicked, the dialog opens, displaying the content within a portal overlay. The dialog can be closed with the close button.
{"import * as Dialog from '@radix-ui/react-dialog';\n\nfunction App() {\n return (\n <Dialog.Root>\n <Dialog.Trigger>Open Dialog</Dialog.Trigger>\n <Dialog.Portal>\n <Dialog.Overlay />\n <Dialog.Content>\n <Dialog.Title>Dialog Title</Dialog.Title>\n <Dialog.Description>This is a basic dialog example.</Dialog.Description>\n <Dialog.Close>Close</Dialog.Close>\n </Dialog.Content>\n </Dialog.Portal>\n </Dialog.Root>\n );\n}"}
Non-modal Dialog
This feature allows you to create a non-modal dialog, which does not lock the user's interaction with the rest of the application. The dialog can be opened and closed similar to a modal, but the background content remains interactive.
{"import * as Dialog from '@radix-ui/react-dialog';\n\nfunction App() {\n return (\n <Dialog.Root modal={false}>\n <Dialog.Trigger>Open Non-modal Dialog</Dialog.Trigger>\n <Dialog.Content>\n <Dialog.Title>Non-modal Dialog Title</Dialog.Title>\n <Dialog.Description>This is a non-modal dialog example.</Dialog.Description>\n <Dialog.Close>Close</Dialog.Close>\n </Dialog.Content>\n </Dialog.Root>\n );\n}"}
Animated Dialog
This feature demonstrates how to add animations to the dialog's overlay and content when they are being shown. Custom animations are defined using keyframes and applied to the styled components.
{"import * as Dialog from '@radix-ui/react-dialog';\nimport { keyframes, styled } from '@stitches/react';\n\nconst overlayShow = keyframes({\n '0%': { opacity: 0 },\n '100%': { opacity: 1 },\n});\n\nconst contentShow = keyframes({\n '0%': { opacity: 0, transform: 'translate(-50%, -48%) scale(.96)' },\n '100%': { opacity: 1, transform: 'translate(-50%, -50%) scale(1)' },\n});\n\nconst StyledOverlay = styled(Dialog.Overlay, {\n animation: `${overlayShow} 150ms cubic-bezier(0.16, 1, 0.3, 1) forwards`,\n});\n\nconst StyledContent = styled(Dialog.Content, {\n animation: `${contentShow} 150ms cubic-bezier(0.16, 1, 0.3, 1) forwards`,\n});\n\nfunction App() {\n return (\n <Dialog.Root>\n <Dialog.Trigger>Open Animated Dialog</Dialog.Trigger>\n <Dialog.Portal>\n <StyledOverlay />\n <StyledContent>\n <Dialog.Title>Animated Dialog Title</Dialog.Title>\n <Dialog.Description>This is an animated dialog example.</Dialog.Description>\n <Dialog.Close>Close</Dialog.Close>\n </StyledContent>\n </Dialog.Portal>\n </Dialog.Root>\n );\n}"}
Other packages similar to @radix-ui/react-dialog
react-modal
react-modal is a popular package for creating accessible modal dialogs in React applications. It provides similar functionality to @radix-ui/react-dialog but has a different API and may offer different customization options.
material-ui
material-ui, also known as @mui/material, offers a Dialog component as part of its comprehensive UI kit for React. It follows Material Design guidelines and provides a rich set of features for creating dialogs, with a focus on Material Design aesthetics.
reactstrap
reactstrap provides Bootstrap-styled components for React, including a Modal component. It is similar to @radix-ui/react-dialog in that it allows for the creation of dialogs, but it is styled according to Bootstrap's design system.