डायलॉग
पुष्टिकरण, त्वरित फ़ॉर्म और विनाशकारी क्रिया संकेतों के लिए एक मोडल विंडो — मोटी सीमाओं और गहरे साये के साथ पृष्ठ पर परतबद्ध।
import { Button } from "@/components/ui/button"
import {
Dialog,डायलॉग पेज के ऊपर मोडल विंडो खोलता है — फ़ोकस अंदर जाता है, पीछे का कंटेंट inert हो जाता है, और बंद करने पर आप ठीक वहीं लौटते हैं जहाँ थे। यह Base UI Dialog प्रिमिटिव पर बना है और नियोब्रूटलिस्ट रेसिपी के अनुसार स्टाइल किया गया है: मोटे बॉर्डर, कठोर छायाएँ और बोल्ड टाइपोग्राफ़ी।
इसे इन स्थितियों में चुनें:
- पुष्टि — डिलीट, साइन-आउट, प्लान डाउनग्रेड; कोई भी डिस्ट्रक्टिव कदम जिसे सख्त रोक चाहिए।
- त्वरित फ़ॉर्म — प्रोफ़ाइल संपादन, प्रोजेक्ट नाम बदलना, टीम-मेट आमंत्रण — पेज छोड़े बिना।
- केंद्रित डिटेल व्यू — इमेज प्रीव्यू, लाइसेंस टेक्स्ट, रिलीज़ नोट्स जिन्हें अपना रूट न चाहिए।
इंस्टॉलेशन#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/dialog.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/dialog.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/dialog.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/dialog.json
निम्नलिखित डिपेंडेंसी इंस्टॉल करें:
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/react
निम्नलिखित कोड को अपने प्रोजेक्ट में कॉपी और पेस्ट करें.
"use client"
import * as React from "react"
import { XIcon } from "lucide-react"
import { Dialog as DialogPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
function Dialog({
...props
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
return <DialogPrimitive.Root data-slot="dialog" {...props} />
}
function DialogTrigger({
...props
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
}
function DialogPortal({
...props
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
}
function DialogClose({
...props
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
}
function DialogOverlay({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
return (
<DialogPrimitive.Overlay
data-slot="dialog-overlay"
className={cn(
"fixed inset-0 isolate z-50 bg-foreground/20 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
className
)}
{...props}
/>
)
}
function DialogContent({
className,
children,
showCloseButton = true,
...props
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
showCloseButton?: boolean
}) {
return (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
data-slot="dialog-content"
className={cn(
"fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded border-2 bg-popover p-4 text-sm text-popover-foreground shadow-md duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
className
)}
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close data-slot="dialog-close" asChild>
<Button
variant="ghost"
className="absolute top-2 right-2"
size="icon-sm"
>
<XIcon />
<span className="sr-only">Close</span>
</Button>
</DialogPrimitive.Close>
)}
</DialogPrimitive.Content>
</DialogPortal>
)
}
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-header"
className={cn("flex flex-col gap-2", className)}
{...props}
/>
)
}
function DialogFooter({
className,
showCloseButton = false,
children,
...props
}: React.ComponentProps<"div"> & {
showCloseButton?: boolean
}) {
return (
<div
data-slot="dialog-footer"
className={cn(
"-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t-2 bg-muted/50 p-4 sm:flex-row sm:justify-end",
className
)}
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close asChild>
<Button variant="outline">Close</Button>
</DialogPrimitive.Close>
)}
</div>
)
}
function DialogTitle({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
return (
<DialogPrimitive.Title
data-slot="dialog-title"
className={cn(
"font-head text-base leading-none font-medium",
className
)}
{...props}
/>
)
}
function DialogDescription({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
return (
<DialogPrimitive.Description
data-slot="dialog-description"
className={cn(
"text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
className
)}
{...props}
/>
)
}
export {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
}
अपने प्रोजेक्ट सेटअप के अनुसार इंपोर्ट पाथ अपडेट करें.
उपयोग#
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"<Dialog>
<DialogTrigger>Open</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Are you 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>कंपोज़िशन#
Dialog बनाने के लिए निम्नलिखित कंपोज़िशन का उपयोग करें:
Dialog
├── DialogTrigger
└── DialogContent
├── DialogHeader
│ ├── DialogTitle
│ └── DialogDescription
└── DialogFooterउदाहरण#
कस्टम क्लोज़ बटन#
डिफ़ॉल्ट क्लोज़ कंट्रोल को अपने बटन से बदलें.
import { Button } from "@/components/ui/button"
import {
Dialog,बिना क्लोज़ बटन#
क्लोज़ बटन को छिपाने के लिए showCloseButton={false} का उपयोग करें.
import { Button } from "@/components/ui/button"
import {
Dialog,स्टिकी फ़ुटर#
कंटेंट स्क्रॉल होने के दौरान एक्शन को दिखाई देते रखें.
import { Button } from "@/components/ui/button"
import {
Dialog,स्क्रॉल करने योग्य कंटेंट#
लंबा कंटेंट स्क्रॉल हो सकता है जबकि हेडर दिखाई देता रहता है.
import { Button } from "@/components/ui/button"
import {
Dialog,RTL#
Neobrutalism में RTL सपोर्ट सक्षम करने के लिए, RTL कॉन्फ़िगरेशन गाइड देखें.
"use client"
import {एक्सेसिबिलिटी#
डायलॉग WAI-ARIA Dialog (Modal) पैटर्न का पालन करता है: कंटेंट role="dialog" और aria-modal के साथ रेंडर होता है, DialogTitle से लेबल और DialogDescription से वर्णन, खुले रहने पर फ़ोकस ट्रैप रहता है, और बंद करने पर फ़ोकस ट्रिगर पर लौटता है।
कीबोर्ड इंटरैक्शन:
| कुंजी | क्रिया |
|---|---|
Space / Enter | फ़ोकस किए गए ट्रिगर से डायलॉग खोलें |
Tab / Shift + Tab | डायलॉग के अंदर अगले / पिछले एलिमेंट पर फ़ोकस (फ़ोकस ट्रैप) |
Esc | डायलॉग बंद करें और फ़ोकस ट्रिगर पर लौटाएँ |
API रेफ़रेंस#
अधिक जानकारी के लिए Base UI डॉक्युमेंटेशन देखें.