अलर्ट डायलॉग
विनाशकारी क्रियाओं — हटाना, साइन आउट, त्यागना — के लिए प्रवाह को रोकने वाला एक मोडल, जिसमें नियोब्रूटलिस्ट बॉर्डर्स-एंड-शैडोज़ ट्रीटमेंट है।
import {
AlertDialog,
AlertDialogAction,अलर्ट डायलॉग उपयोगकर्ता को ऐसे मोडल से रोकता है जिसमें स्पष्ट चुनाव ज़रूरी है — बाहर क्लिक करने से यह बंद नहीं होता। यह Base UI Alert Dialog कंपोनेंट पर बना है और नियोब्रूटलिस्ट रेसिपी के अनुसार स्टाइल किया गया है: मोटे बॉर्डर, कठोर छायाएँ और बोल्ड टाइपोग्राफ़ी।
इसे इन स्थितियों में चुनें:
- डिस्ट्रक्टिव पुष्टि — अकाउंट डिलीट, टीम मेंबर हटाना, प्रोजेक्ट साफ़ करना।
- अपरिवर्तनीय कार्रवाई — पब्लिश, सेंड, सबमिट; जहाँ undo न हो।
- अनसेव्ड-चेंज गार्ड — गंदे फ़ॉर्म से निकलने से पहले चेतावनी दें।
इंस्टॉलेशन#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/alert-dialog.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/alert-dialog.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/alert-dialog.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/alert-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 { AlertDialog as AlertDialogPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
function AlertDialog({
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />
}
function AlertDialogTrigger({
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
return (
<AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
)
}
function AlertDialogPortal({
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
return (
<AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
)
}
function AlertDialogOverlay({
className,
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
return (
<AlertDialogPrimitive.Overlay
data-slot="alert-dialog-overlay"
className={cn(
"fixed inset-0 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 AlertDialogContent({
className,
size = "default",
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Content> & {
size?: "default" | "sm"
}) {
return (
<AlertDialogPortal>
<AlertDialogOverlay />
<AlertDialogPrimitive.Content
data-slot="alert-dialog-content"
data-size={size}
className={cn(
"group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 rounded border-2 bg-popover p-4 text-popover-foreground shadow-md duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]: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}
/>
</AlertDialogPortal>
)
}
function AlertDialogHeader({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-dialog-header"
className={cn(
"grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
className
)}
{...props}
/>
)
}
function AlertDialogFooter({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-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 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
className
)}
{...props}
/>
)
}
function AlertDialogMedia({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-dialog-media"
className={cn(
"mb-2 inline-flex size-10 items-center justify-center rounded-md bg-muted sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-6",
className
)}
{...props}
/>
)
}
function AlertDialogTitle({
className,
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
return (
<AlertDialogPrimitive.Title
data-slot="alert-dialog-title"
className={cn(
"font-head text-base font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
className
)}
{...props}
/>
)
}
function AlertDialogDescription({
className,
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
return (
<AlertDialogPrimitive.Description
data-slot="alert-dialog-description"
className={cn(
"text-sm text-balance text-muted-foreground md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
className
)}
{...props}
/>
)
}
function AlertDialogAction({
className,
variant = "default",
size = "default",
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Action> &
Pick<React.ComponentProps<typeof Button>, "variant" | "size">) {
return (
<Button variant={variant} size={size} asChild>
<AlertDialogPrimitive.Action
data-slot="alert-dialog-action"
className={cn(className)}
{...props}
/>
</Button>
)
}
function AlertDialogCancel({
className,
variant = "outline",
size = "default",
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel> &
Pick<React.ComponentProps<typeof Button>, "variant" | "size">) {
return (
<Button variant={variant} size={size} asChild>
<AlertDialogPrimitive.Cancel
data-slot="alert-dialog-cancel"
className={cn(className)}
{...props}
/>
</Button>
)
}
export {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogMedia,
AlertDialogOverlay,
AlertDialogPortal,
AlertDialogTitle,
AlertDialogTrigger,
}
अपने प्रोजेक्ट सेटअप से मेल खाने के लिए import पाथ अपडेट करें।
उपयोग#
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"<AlertDialog>
<AlertDialogTrigger render={<Button variant="outline" />}>
Show Dialog
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. This will permanently delete your account
from our servers.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction>Continue</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>कंपोज़िशन#
AlertDialog बनाने के लिए निम्नलिखित कंपोज़िशन का उपयोग करें:
AlertDialog
├── AlertDialogTrigger
└── AlertDialogContent
├── AlertDialogHeader
│ ├── AlertDialogMedia
│ ├── AlertDialogTitle
│ └── AlertDialogDescription
└── AlertDialogFooter
├── AlertDialogCancel
└── AlertDialogActionउदाहरण#
बेसिक#
एक शीर्षक, विवरण, और रद्द करने व जारी रखने के बटन के साथ एक बेसिक alert dialog।
import {
AlertDialog,
AlertDialogAction,छोटा#
alert dialog को छोटा करने के लिए size="sm" prop का उपयोग करें।
import {
AlertDialog,
AlertDialogAction,मीडिया#
alert dialog में icon या image जैसा कोई मीडिया एलिमेंट जोड़ने के लिए AlertDialogMedia कंपोनेंट का उपयोग करें।
import { CircleFadingPlusIcon } from "lucide-react"
import {मीडिया के साथ छोटा#
alert dialog को छोटा करने के लिए size="sm" prop और उसमें icon या image जैसा मीडिया एलिमेंट जोड़ने के लिए AlertDialogMedia कंपोनेंट का उपयोग करें।
import { BluetoothIcon } from "lucide-react"
import {डिस्ट्रक्टिव#
alert dialog में डिस्ट्रक्टिव एक्शन बटन जोड़ने के लिए AlertDialogAction कंपोनेंट का उपयोग करें।
import { Trash2Icon } from "lucide-react"
import {RTL#
Neobrutalism में RTL सपोर्ट सक्षम करने के लिए, RTL कॉन्फ़िगरेशन गाइड देखें।
"use client"
import { BluetoothIcon } from "lucide-react"एक्सेसिबिलिटी#
अलर्ट डायलॉग WAI-ARIA Alert Dialog पैटर्न का पालन करता है: पॉपअप role="alertdialog" रेंडर करता है, टाइटल और विवरण aria-labelledby और aria-describedby से जुड़े रहते हैं, और खुले रहने पर फ़ोकस अंदर ट्रैप रहता है।
कीबोर्ड इंटरैक्शन:
| कुंजी | क्रिया |
|---|---|
Space / Enter | फ़ोकस किए गए ट्रिगर से डायलॉग खोलें |
Tab / Shift + Tab | डायलॉग के फ़ोकस-योग्य एलिमेंटों के बीच घूमें |
Esc | डायलॉग बंद करें और फ़ोकस ट्रिगर पर लौटाएँ |
API रेफ़रेंस#
size#
alert dialog का साइज़ नियंत्रित करने के लिए AlertDialogContent कंपोनेंट पर size prop का उपयोग करें। यह निम्नलिखित वैल्यू स्वीकार करता है:
| Prop | Type | Default |
|---|---|---|
size | "default" | "sm" | "default" |
अन्य कंपोनेंट और उनके props के बारे में अधिक जानकारी के लिए, Base UI डॉक्यूमेंटेशन देखें।