mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-30 08:04:18 +00:00
108 lines
2.6 KiB
Plaintext
108 lines
2.6 KiB
Plaintext
---
|
|
title: Dialog
|
|
description: A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.
|
|
featured: true
|
|
component: true
|
|
radix:
|
|
link: https://www.radix-ui.com/docs/primitives/components/dialog
|
|
api: https://www.radix-ui.com/docs/primitives/components/dialog#api-reference
|
|
---
|
|
|
|
<ComponentExample src="/components/examples/dialog/demo.tsx">
|
|
<DialogDemo />
|
|
</ComponentExample>
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
npx shadcn-ui add dialog
|
|
```
|
|
|
|
<Accordion type="single" collapsible>
|
|
<AccordionItem value="manual-installation">
|
|
<AccordionTrigger>Manual Installation</AccordionTrigger>
|
|
<AccordionContent>
|
|
|
|
1. Install the `@radix-ui/react-dialog` component from radix-ui:
|
|
|
|
```bash
|
|
npm install @radix-ui/react-dialog
|
|
```
|
|
|
|
2. Copy and paste the following code into your project.
|
|
|
|
<ComponentSource src="/components/ui/dialog.tsx" />
|
|
|
|
<Callout>
|
|
|
|
This is the `<Dialog />` primitive. You can place it in a file at `components/ui/dialog.tsx`.
|
|
|
|
</Callout>
|
|
|
|
</AccordionContent>
|
|
|
|
</AccordionItem>
|
|
</Accordion>
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from "@/components/ui/dialog"
|
|
```
|
|
|
|
```tsx
|
|
<Dialog>
|
|
<DialogTrigger>Open</DialogTrigger>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Are you sure absolutely sure?</DialogTitle>
|
|
<DialogDescription>
|
|
This action cannot be undone. This will permanently delete your account
|
|
and remove your data from our servers.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
</DialogContent>
|
|
</Dialog>
|
|
```
|
|
|
|
## Notes
|
|
|
|
To activate the `Dialog` component from within a `Context Menu` or `Dropdown Menu`, you must encase the `Context Menu` or
|
|
`Dropdown Menu` component in the `Dialog` component. For more information, refer to the linked issue [here](https://github.com/radix-ui/primitives/issues/1836).
|
|
|
|
```tsx {14-25}
|
|
<Dialog>
|
|
<ContextMenu>
|
|
<ContextMenuTrigger>Right click</ContextMenuTrigger>
|
|
<ContextMenuContent>
|
|
<ContextMenuItem>Open</ContextMenuItem>
|
|
<ContextMenuItem>Download</ContextMenuItem>
|
|
<DialogTrigger asChild>
|
|
<ContextMenuItem>
|
|
<span>Delete</span>
|
|
</ContextMenuItem>
|
|
</DialogTrigger>
|
|
</ContextMenuContent>
|
|
</ContextMenu>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Are you sure absolutely sure?</DialogTitle>
|
|
<DialogDescription>
|
|
This action cannot be undone. Are you sure you want to permanently
|
|
delete this file from our servers?
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<DialogFooter>
|
|
<Button type="submit">Confirm</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
```
|