1import { AlertCircleIcon, CheckCircle2Icon, PopcornIcon } from "lucide-solid";2
3import { Alert, AlertDescription, AlertTitle } from "~/components/ui/alert";4
5export default function AlertDemo() {6 return (7 <div class="grid w-full max-w-xl items-start gap-4">8 <Alert>9 <CheckCircle2Icon />10 <AlertTitle>Success! Your changes have been saved</AlertTitle>11 <AlertDescription>12 This is an alert with icon, title and description13 </AlertDescription>14 </Alert>15 <Alert>16 <PopcornIcon />17 <AlertTitle>18 This Alert has a title and an icon. No description.19 </AlertTitle>20 </Alert>21 <Alert variant="destructive">22 <AlertCircleIcon />23 <AlertTitle>Unable to process your payment.</AlertTitle>24 <AlertDescription>25 <p>Please verify your billing information and try again.</p>26 <ul class="list-inside list-disc text-sm">27 <li>Check your card details</li>28 <li>Ensure sufficient funds</li>29 <li>Verify billing address</li>30 </ul>31 </AlertDescription>32 </Alert>33 </div>34 );35}
npx shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/alert.json
yarn shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/alert.json
pnpm dlx shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/alert.json
bunx --bun shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/alert.json
Install the following dependencies
npm install @kobalte/core
yarn add @kobalte/core
pnpm add @kobalte/core
bun add @kobalte/core
Copy and paste the following code into your project
1import type { PolymorphicProps } from "@kobalte/core/polymorphic";2import type { VariantProps } from "class-variance-authority";3import type { Component, ComponentProps, ValidComponent } from "solid-js";4
5import { splitProps } from "solid-js";6import * as AlertPrimitive from "@kobalte/core/alert";7import { cva } from "class-variance-authority";8
9import { cn } from "~/lib/utils";10
11const alertVariants = cva(12 "relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-base border-2 border-border px-4 py-3 text-sm shadow-shadow 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",13 {14 variants: {15 variant: {16 default: "bg-primary text-primary-foreground",17 destructive: "border-black bg-black text-white shadow-destructive",18 neutral: "bg-secondary text-foreground",19 },20 },21 defaultVariants: {22 variant: "default",23 },24 },25);26
27type AlertRootProps<T extends ValidComponent = "div"> =28 AlertPrimitive.AlertRootProps<T> &29 VariantProps<typeof alertVariants> & { class?: string | undefined };30
31const Alert = <T extends ValidComponent = "div">(32 props: PolymorphicProps<T, AlertRootProps<T>>,33) => {34 const [local, others] = splitProps(props as AlertRootProps, [35 "class",36 "variant",37 ]);38 return (39 <AlertPrimitive.Root40 data-slot="alert"41 class={cn(alertVariants({ variant: props.variant }), local.class)}42 {...others}43 />44 );45};46
47const AlertTitle: Component<ComponentProps<"h5">> = (props) => {48 const [local, others] = splitProps(props, ["class"]);49 return (50 <h551 data-slot="alert-title"52 class={cn(53 "col-start-2 line-clamp-1 min-h-4 font-heading tracking-tight",54 local.class,55 )}56 {...others}57 />58 );59};60
61const AlertDescription: Component<ComponentProps<"div">> = (props) => {62 const [local, others] = splitProps(props, ["class"]);63 return (64 <div65 data-slot="alert-description"66 class={cn(67 "col-start-2 grid justify-items-start gap-1 text-sm font-base [&_p]:leading-relaxed",68 local.class,69 )}70 {...others}71 />72 );73};74
75export { Alert, AlertTitle, AlertDescription };
Update the import paths to match your project setup.
1import { Alert, AlertDescription, AlertTitle } from "~/components/ui/alert";
1<Alert variant="default | destructive | neutral">2 <AlertIcon />3 <AlertTitle>Alert Title</AlertTitle>4 <AlertDescription>5 This is an important message for the user.6 </AlertDescription>7</Alert>