Alert
hextaui/alertFreeComponent
Displays a status or message banner.
Live preview
live · rendered by the registry
Rendered by HextaUI on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://hextaui.com/r/alert.jsonSource
1import { cva, type VariantProps } from "class-variance-authority";2import type * as React from "react";34import { cn } from "@/lib/utils";56const alertVariants = cva(7 "relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",8 {9 variants: {10 variant: {11 default: "bg-card text-card-foreground",12 destructive:13 "bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current",14 },15 },16 defaultVariants: {17 variant: "default",18 },19 }20);2122type LivePoliteness = "polite" | "assertive" | false;2324function Alert({25 className,26 variant,27 live = "polite",28 ...props29}: React.ComponentProps<"div"> &30 VariantProps<typeof alertVariants> & { live?: LivePoliteness }) {31 const liveAttributes =32 live === "assertive"33 ? ({34 role: "alert",35 "aria-live": "assertive",36 "aria-atomic": true,37 } as const)38 : live === "polite"39 ? ({40 role: "status",41 "aria-live": "polite",42 "aria-atomic": true,43 } as const)44 : ({} as const);45 return (46 <div47 data-slot="alert"48 {...liveAttributes}49 className={cn(alertVariants({ variant }), className)}50 {...props}51 />52 );53}5455function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {56 return (57 <div58 className={cn(59 "col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",60 className61 )}62 data-slot="alert-title"63 {...props}64 />65 );66}6768function AlertDescription({69 className,70 ...props71}: React.ComponentProps<"div">) {72 return (73 <div74 className={cn(75 "col-start-2 grid justify-items-start gap-1 text-muted-foreground text-sm [&_p]:leading-relaxed",76 className77 )}78 data-slot="alert-description"79 {...props}80 />81 );82}8384export { Alert, AlertTitle, AlertDescription };
Files it writes
More from HextaUI
All 139 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | HextaUI | Components | Free | 1 dep | |
| AI Chat Historyai-chat-history | HextaUI | Components | Free | no deps | |
| AI Citationsai-citations | HextaUI | Components | Free | no deps | |
| AI Conversationai-conversation | HextaUI | Components | Free | no deps | |
| AI Error Handlerai-error-handler | HextaUI | Components | Free | no deps | |
| AI File Uploadai-file-upload | HextaUI | Components | Free | no deps | |
| AI Messageai-message | HextaUI | Components | Free | 4 deps | |
| AI Model Selectorai-model-selector | HextaUI | Components | Free | no deps |
