Search for a command to run...
Displays a callout for user attention.
npx shadcn@latest add @zaidan/alertpnpx shadcn add @zaidan/alertyarn dlx shadcn@latest add @zaidan/alertbunx shadcn@latest add @zaidan/alertCopy and paste the following code into your project.
1import type { PolymorphicProps } from "@kobalte/core";2import { type AlertRootProps, Root } from "@kobalte/core/alert";3import { cva, type VariantProps } from "class-variance-authority";4import type { ComponentProps, ValidComponent } from "solid-js";5import { splitProps } from "solid-js";6import { cn } from "~/lib/utils";7
8const alertVariants = cva("group/alert relative z-alert w-full", {9 variants: {10 variant: {11 default: "z-alert-variant-default",12 destructive: "z-alert-variant-destructive",13 },14 },15 defaultVariants: {16 variant: "default",17 },18});19
20type AlertProps<T extends ValidComponent = "div"> = PolymorphicProps<T, AlertRootProps<T>> &21 VariantProps<typeof alertVariants>;22
23const Alert = <T extends ValidComponent = "div">(props: AlertProps<T>) => {24 const [local, others] = splitProps(props as AlertProps, ["class", "variant"]);25
26 return (27 <Root28 class={cn(alertVariants({ variant: local.variant }), local.class)}29 data-slot="alert"30 role="alert"31 {...others}32 />33 );34};35
36type AlertTitleProps = ComponentProps<"div">;37
38const AlertTitle = (props: AlertTitleProps) => {39 const [local, others] = splitProps(props, ["class"]);40
41 return (42 <div43 class={cn(44 "z-alert-title [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground",45 local.class,46 )}47 data-slot="alert-title"48 {...others}49 />50 );51};52
53type AlertDescriptionProps = ComponentProps<"div">;54
55const AlertDescription = (props: AlertDescriptionProps) => {56 const [local, others] = splitProps(props, ["class"]);57
58 return (59 <div60 class={cn(61 "z-alert-description [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground",62 local.class,63 )}64 data-slot="alert-description"65 {...others}66 />67 );68};69
70type AlertActionProps = ComponentProps<"div">;71
72const AlertAction = (props: AlertActionProps) => {73 const [local, others] = splitProps(props, ["class"]);74
75 return <div class={cn("z-alert-action", local.class)} data-slot="alert-action" {...others} />;76};77
78export { Alert, AlertTitle, AlertDescription, AlertAction, alertVariants };Here are the source code of all the examples from the preview page:
import { Alert, AlertDescription, AlertTitle,} from "~/components/ui/alert";function Basic() { return ( <Example title="Basic"> <div class="mx-auto flex w-full max-w-lg flex-col gap-4"> <Alert> <AlertTitle>Success! Your changes have been saved.</AlertTitle> </Alert> <Alert> <AlertTitle>Success! Your changes have been saved.</AlertTitle> <AlertDescription>This is an alert with title and description.</AlertDescription> </Alert> <Alert> <AlertDescription>This one has a description only. No title. No icon.</AlertDescription> </Alert> </div> </Example> );}import { CircleAlert } from "lucide-solid";import { Alert, AlertDescription, AlertTitle,} from "~/components/ui/alert";function WithIcons() { return ( <Example title="With Icons"> <div class="mx-auto flex w-full max-w-lg flex-col gap-4"> <Alert> <CircleAlert /> <AlertTitle> Let's try one with icon, title and a <a href="#">link</a>. </AlertTitle> </Alert> <Alert> <CircleAlert /> <AlertDescription> This one has an icon and a description only. No title. <a href="#">But it has a link</a>{" "} and a <a href="#">second link</a>. </AlertDescription> </Alert>
<Alert> <CircleAlert /> <AlertTitle>Success! Your changes have been saved</AlertTitle> <AlertDescription>This is an alert with icon, title and description.</AlertDescription> </Alert> <Alert> <CircleAlert /> <AlertTitle> This is a very long alert title that demonstrates how the component handles extended text content and potentially wraps across multiple lines </AlertTitle> </Alert> <Alert> <CircleAlert /> <AlertDescription> This is a very long alert description that demonstrates how the component handles extended text content and potentially wraps across multiple lines </AlertDescription> </Alert> <Alert> <CircleAlert /> <AlertTitle> This is an extremely long alert title that spans multiple lines to demonstrate how the component handles very lengthy headings while maintaining readability and proper text wrapping behavior </AlertTitle> <AlertDescription> This is an equally long description that contains detailed information about the alert. It shows how the component can accommodate extensive content while preserving proper spacing, alignment, and readability across different screen sizes and viewport widths. This helps ensure the user experience remains consistent regardless of the content length. </AlertDescription> </Alert> </div> </Example> );}import { CircleAlert } from "lucide-solid";import { Alert, AlertDescription, AlertTitle,} from "~/components/ui/alert";function Destructive() { return ( <Example title="Destructive"> <div class="mx-auto flex w-full max-w-lg flex-col gap-4"> <Alert variant="destructive"> <CircleAlert /> <AlertTitle>Something went wrong!</AlertTitle> <AlertDescription>Your session has expired. Please log in again.</AlertDescription> </Alert> <Alert variant="destructive"> <CircleAlert /> <AlertTitle>Unable to process your payment.</AlertTitle> <AlertDescription> <p> Please verify your <a href="#">billing information</a> and try again. </p> <ul class="list-inside list-disc"> <li>Check your card details</li> <li>Ensure sufficient funds</li> <li>Verify billing address</li> </ul> </AlertDescription> </Alert> </div> </Example> );}import { CircleAlert } from "lucide-solid";import { Alert, AlertAction, AlertDescription, AlertTitle,} from "~/components/ui/alert";import { Badge } from "~/components/ui/badge";import { Button } from "~/components/ui/button";function WithActions() { return ( <Example title="With Actions"> <div class="mx-auto flex w-full max-w-lg flex-col gap-4"> <Alert> <CircleAlert /> <AlertTitle>The selected emails have been marked as spam.</AlertTitle> <AlertAction> <Button size="xs">Undo</Button> </AlertAction> </Alert> <Alert> <CircleAlert /> <AlertTitle>The selected emails have been marked as spam.</AlertTitle> <AlertDescription> This is a very long alert title that demonstrates how the component handles extended text content. </AlertDescription> <AlertAction> <Badge variant="secondary">Badge</Badge> </AlertAction> </Alert> </div> </Example> );}