Components
Alert
Displays a callout for user attention.
Loading...
Installation
CLI
npx shadcn@latest add @exabase/alertManual
Copy and paste the following code into your project.
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const alertVariants = cva(
"relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-3 py-2.5 text-sm text-foreground has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-2 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4",
{
variants: {
variant: {
default: "bg-muted/50",
info: "border-info-text/50 bg-info-muted *:[svg]:text-info",
success: "border-success-text/50 bg-success-muted *:[svg]:text-success",
warning: "border-warning-text/50 bg-warning-muted *:[svg]:text-warning",
error:
"border-destructive-text/50 bg-destructive-muted *:[svg]:text-destructive",
},
},
defaultVariants: {
variant: "default",
},
}
)
function Alert({
className,
variant,
...props
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
return (
<div
data-slot="alert"
role="alert"
className={cn(alertVariants({ variant }), className)}
{...props}
/>
)
}
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-title"
className={cn(
"col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",
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",
className
)}
{...props}
/>
)
}
export { Alert, AlertTitle, AlertDescription }
Usage
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";<Alert>
<Terminal className="h-4 w-4" />
<AlertTitle>Heads up!</AlertTitle>
<AlertDescription>
You can add components and dependencies to your app using the cli.
</AlertDescription>
</Alert>Examples
Variant
Loading...
Elements
Loading...
Action
shadcn/ui provides an AlertAction component, but we do not provide it due to its lack of layout flexibility.
Instead, place actions at any position you like.
Loading...
API
Alert
<Alert> renders as a <div> element.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "success" | "info" | "warning" | "error" | default | The variant of the alert. |