התראה
הערות מוטמעות המציגות שגיאות בטופס, אזהרות ואישורי הצלחה — לוחות בצבעי סטטוס עם מסגרות בסגנון ניאו-ברוטליסטי וצללים חדים.
import { CheckCircle2Icon, InfoIcon } from "lucide-react"
import {ה-alert הוא קריאה פנימית בשורה: אייקון, כותרת, תיאור ופעולה אופציונלית, מסודרים על CSS grid. זה div עם role="alert" בלי תלויות — אין פרימיטיב מתחת, זהה בשני ה-backends — ומעוצב לפי המתכון הנאו-ברוטליסטי: מסגרות עבות, צללים חדים וטיפוגרפיה מודגשת, עם ציר status לצביעה של error, success, warning ו-info.
השתמשו בו כש:
- שגיאות טופס ובקשות — מציגים כשל ולידציה או קריאת API שנכשלה ליד מה שנשבר.
- אישורי הצלחה וסטטוס — "ההגדרות נשמרו", "הניסיון עומד לפוג", "התשלום התקבל", צבועים לפי prop ה-
status. - קריאות עם המשך — אזהרה או הודעת שדרוג שנושאת כפתור
AlertAction("הפעלה", "ביטול", "שדרוג").
התקנה#
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 {
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דוגמאות#
בסיסי#
התראה בסיסית עם סמל, כותרת ותיאור.
import { CheckCircle2Icon } from "lucide-react"
import {הרסני#
השתמשו ב-variant="destructive" כדי ליצור התראה הרסנית.
import { AlertCircleIcon } from "lucide-react"
import {Action#
השתמשו ב-AlertAction כדי להוסיף כפתור או אלמנט פעולה אחר להתראה.
import {
Alert,
AlertAction,צבעים מותאמים אישית#
תוכלו להתאים אישית את צבעי ההתראה על ידי הוספת מחלקות מותאמות אישית כגון bg-amber-50 dark:bg-amber-950 לרכיב Alert.
import { AlertTriangleIcon } from "lucide-react"
import {RTL#
כדי להפעיל RTL ב-Neobrutalism, עיינו במדריך ההגדרה של RTL.
"use client"
import * as React from "react"נגישות#
שורש ה-alert מרנדר role="alert", אזור live אסרטיבי מרומז: קוראי מסך מכריזים על התוכן ברגע שהוא מוכנס ל-DOM. ההכרזה נורות רק בהכנסה דינמית — alert שכבר נוכח בטעינת העמוד נקרא כטקסט רגיל, לכן רנדרו אותו מותנה כשצריך שיישמע. role="alert" אף פעם לא מעביר מוקד; אם המשתמשים חייבים להגיב לפני המשך, השתמשו ב-alert dialog, והתייחסו ל-AlertAction כקיצור דרך ולא כדרך היחידה קדימה.
תיעוד ה-API#
Alert#
רכיב Alert מציג הבלטה למשיכת תשומת לב המשתמש.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "default" |
AlertTitle#
רכיב AlertTitle מציג את כותרת ההתראה.
| Prop | Type | Default |
|---|---|---|
className | string | - |
AlertDescription#
רכיב AlertDescription מציג את התיאור או התוכן של ההתראה.
| Prop | Type | Default |
|---|---|---|
className | string | - |
AlertAction#
רכיב AlertAction מציג אלמנט פעולה (כמו כפתור) הממוקם באופן מוחלט בפינה הימנית העליונה של ההתראה.
| Prop | Type | Default |
|---|---|---|
className | string | - |