अलर्ट
फ़ॉर्म त्रुटियों, चेतावनियों और सफलता पुष्टि के लिए इनलाइन कॉलआउट — नियोब्रुटलिस्ट बॉर्डर और कठोर छायाओं वाले स्थिति-रंगित पैनल।
import { CheckCircle2Icon, InfoIcon } from "lucide-react"
import {अलर्ट एक इनलाइन कॉलआउट है: आइकन, टाइटल, विवरण और वैकल्पिक एक्शन, CSS ग्रिड पर व्यवस्थित। यह डिपेंडेंसी-मुक्त role="alert" div है — कोई प्रिमिटिव नीचे नहीं, दोनों बैकएंड पर एक जैसा — और नियोब्रूटलिस्ट रेसिपी के अनुसार स्टाइल किया गया है: मोटे बॉर्डर, कठोर छायाएँ और बोल्ड टाइपोग्राफ़ी। साथ में status अक्ष error, success, warning और info रंगों के लिए।
इसे इन स्थितियों में चुनें:
- फ़ॉर्म और रिक्वेस्ट एरर — वैलिडेशन फ़ेल या API कॉल फ़ेल को ठीक उसी जगह दिखाएँ जहाँ समस्या हुई।
- सफलता और स्टेटस पुष्टि — "settings saved", "trial expiring", "payment received",
statusprop के रंग में। - फ़ॉलो-अप वाला कॉलआउट — चेतावनी या अपग्रेड नोटिस जिसमें
AlertActionबटन हो ("Enable", "Undo", "Upgrade")।
इंस्टॉलेशन#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/alert.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/alert.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/alert.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/alert.json
निम्नलिखित कोड को कॉपी करके अपने प्रोजेक्ट में पेस्ट करें।
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
// CSS-grid layout (shadcn-style): drop an icon as a direct child and the alert
// auto-arranges into an icon column + a content column — no manual flex wrapper.
// `has-[>svg]` adds the icon column only when an icon is present. NeoBrutalist
// chrome: hard 2px border, square corners, hard offset shadow.
const alertVariants = cva(
cn(
"group/alert relative grid w-full grid-cols-[0_1fr] items-start gap-y-1 rounded border-2 px-4 py-3 text-left text-sm shadow-md",
"has-[>svg]:grid-cols-[1.25rem_1fr] has-[>svg]:gap-x-3",
"has-data-[slot=alert-action]:pr-14",
"[&>svg]:size-5 [&>svg]:translate-y-0.5 [&>svg]:shrink-0 [&>svg]:text-current"
),
{
variants: {
// shadcn's variant axis (kept for API compatibility). `solid` is a Neobrutalism
// addition.
variant: {
default:
"border-border bg-background text-foreground *:data-[slot=alert-description]:text-muted-foreground",
destructive:
"border-red-900 bg-red-300 text-red-900 *:data-[slot=alert-description]:text-red-900/80",
solid:
"border-border bg-foreground text-background *:data-[slot=alert-description]:text-background/80",
},
// Neobrutalism status axis — additive; overrides the variant's colors when set.
status: {
error:
"border-red-900 bg-red-300 text-red-900 *:data-[slot=alert-description]:text-red-900/80",
success:
"border-green-900 bg-green-300 text-green-900 *:data-[slot=alert-description]:text-green-900/80",
warning:
"border-yellow-900 bg-yellow-300 text-yellow-900 *:data-[slot=alert-description]:text-yellow-900/80",
info: "border-blue-900 bg-blue-300 text-blue-900 *:data-[slot=alert-description]:text-blue-900/80",
},
},
defaultVariants: {
variant: "default",
},
}
)
function Alert({
className,
variant,
status,
...props
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
return (
<div
data-slot="alert"
role="alert"
className={cn(alertVariants({ variant, status }), className)}
{...props}
/>
)
}
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-title"
className={cn(
"col-start-2 min-h-5 font-head text-base leading-tight tracking-tight [&_a]:underline [&_a]:underline-offset-3",
className
)}
{...props}
/>
)
}
function AlertDescription({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-description"
className={cn(
"col-start-2 grid justify-items-start gap-1 text-sm [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p]:leading-relaxed [&_p:not(:last-child)]:mb-4",
className
)}
{...props}
/>
)
}
function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-action"
className={cn("absolute top-2 right-2", className)}
{...props}
/>
)
}
export { Alert, AlertTitle, AlertDescription, AlertAction, alertVariants }
अपने प्रोजेक्ट सेटअप से मेल खाने के लिए import पाथ अपडेट करें।
उपयोग#
import {
Alert,
AlertAction,
AlertDescription,
AlertTitle,
} from "@/components/ui/alert"<Alert>
<InfoIcon />
<AlertTitle>Heads up!</AlertTitle>
<AlertDescription>
You can add components and dependencies to your app using the cli.
</AlertDescription>
<AlertAction>
<Button variant="outline">Enable</Button>
</AlertAction>
</Alert>कंपोज़िशन#
Alert बनाने के लिए निम्नलिखित कंपोज़िशन का उपयोग करें:
Alert
├── Icon
├── AlertTitle
├── AlertDescription
└── AlertActionउदाहरण#
बेसिक#
एक आइकन, शीर्षक और विवरण के साथ एक बेसिक alert।
import { CheckCircle2Icon } from "lucide-react"
import {डिस्ट्रक्टिव#
डिस्ट्रक्टिव alert बनाने के लिए variant="destructive" का उपयोग करें।
import { AlertCircleIcon } from "lucide-react"
import {एक्शन#
alert में बटन या अन्य एक्शन एलिमेंट जोड़ने के लिए AlertAction का उपयोग करें।
import {
Alert,
AlertAction,कस्टम रंग#
आप Alert कंपोनेंट में bg-amber-50 dark:bg-amber-950 जैसी कस्टम क्लास जोड़कर alert के रंग कस्टमाइज़ कर सकते हैं।
import { AlertTriangleIcon } from "lucide-react"
import {RTL#
Neobrutalism में RTL सपोर्ट सक्षम करने के लिए, RTL कॉन्फ़िगरेशन गाइड देखें।
"use client"
import * as React from "react"एक्सेसिबिलिटी#
अलर्ट रूट role="alert" रेंडर करता है — एक अंतर्निहित assertive live region: DOM में डालते ही स्क्रीन रीडर उसकी सामग्री घोषित करते हैं। घोषणा केवल डायनामिक इंसर्शन पर होती है — पेज लोड पर पहले से मौजूद अलर्ट साधारण टेक्स्ट की तरह पढ़ा जाता है, इसलिए जब सुनाई देना हो तब कंडीशनली रेंडर करें। role="alert" कभी फ़ोकस नहीं हटाता; अगर उपयोगकर्ता को आगे बढ़ने से पहले जवाब देना हो तो अलर्ट डायलॉग इस्तेमाल करें, और AlertAction को शॉर्टकट समझें, एकमात्र रास्ता नहीं।
API रेफ़रेंस#
Alert#
Alert कंपोनेंट यूज़र का ध्यान खींचने के लिए सूचना दिखाता है।
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "default" |
AlertTitle#
AlertTitle कंपोनेंट alert का शीर्षक दिखाता है।
| Prop | Type | Default |
|---|---|---|
className | string | - |
AlertDescription#
AlertDescription कंपोनेंट alert का विवरण या कंटेंट दिखाता है।
| Prop | Type | Default |
|---|---|---|
className | string | - |
AlertAction#
AlertAction कंपोनेंट एक एक्शन एलिमेंट (जैसे बटन) दिखाता है, जो alert के ऊपरी-दाएँ कोने में absolutely पोज़िशन किया जाता है।
| Prop | Type | Default |
|---|---|---|
className | string | - |