Success! Your changes have been saved
This is an alert with icon, title and description.
This Alert has a title and an icon. No description.
Unable to process your payment.
Please verify your billing information and try again.
- Check your card details
- Ensure sufficient funds
- Verify billing address
import { Alert, AlertDescription, AlertTitle } from "@/registry/components/alert/react/alert";import { AlertCircleIcon, CheckCircle2Icon, PopcornIcon } from "lucide-react";
export function AlertDemo() { return ( <div className="flow w-full"> <Alert> <CheckCircle2Icon /> <div className="flow"> <AlertTitle>Success! Your changes have been saved</AlertTitle> <AlertDescription className="flow-space-3xs"> This is an alert with icon, title and description. </AlertDescription> </div> </Alert> <Alert> <PopcornIcon /> <AlertTitle>This Alert has a title and an icon. No description.</AlertTitle> </Alert> <Alert data-intent="danger"> <AlertCircleIcon /> <div className="flow"> <AlertTitle>Unable to process your payment.</AlertTitle> <AlertDescription className="flow-space-3xs"> <p>Please verify your billing information and try again.</p> <ul className="list-inside"> <li>Check your card details</li> <li>Ensure sufficient funds</li> <li>Verify billing address</li> </ul> </AlertDescription> </div> </Alert> </div> );}
You can add the alert component in two ways:
- During project initialization:
pnpm dlx make-sugarcube@latest init
npx make-sugarcube@latest init
yarn make-sugarcube@latest init
bunx --bun make-sugarcube@latest init
Then select the alert component when prompted.
- After initialization:
pnpm dlx make-sugarcube@latest components alert --framework react
npx make-sugarcube@latest components alert --framework react
yarn make-sugarcube@latest components alert --framework react
bunx --bun make-sugarcube@latest components alert --framework react
When you add the button component, you get:
alert.tsx
- The React component implementationalert.css
- The base styles for the alert@clsx
- Theclsx
utility for conditional classes
import cn from "clsx";
function Alert({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="alert" role="alert" className={cn("alert", className)} {...props} />;}
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="alert-title" className={cn("alert-title", className)} {...props} />;}
function AlertDescription({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="alert-description" className={cn("alert-description", className)} {...props} /> );}
export { Alert, AlertTitle, AlertDescription };
.alert { position: relative; background-color: var(--alert-bg); color: var(--alert-fg); border-style: var(--alert-border-style); border-width: var(--alert-border-width); border-color: var(--alert-border-color); padding-inline: var(--alert-padding-inline); padding-block: var(--alert-padding-block); border-radius: var(--alert-radius); font-size: var(--alert-font-size);}
.alert:has(svg) { --title-col-start: 2; --description-col-start: 2; --action-col-start: 3; display: grid; grid-template-columns: var(--alert-icon-size) 1fr; row-gap: var(--space-3xs); column-gap: var(--space-xs);}
.button:where(.alert button) { --button-shadow: none; --button-height: 24px; grid-column: var(--action-col-start);}
.alert svg { width: var(--alert-icon-size); height: var(--alert-icon-size); transform: translateY(var(--alert-icon-offset, 2px)); justify-self: var(--alert-icon-justify, start); align-self: var(--alert-icon-align, start);}
.alert-title { grid-column-start: var(--title-col-start); font-weight: var(--font-weight-medium); letter-spacing: var(--tracking-tight); display: -webkit-box; -webkit-line-clamp: 1; line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;}
.alert-description { grid-column-start: var(--description-col-start); color: var(--alert-description-color);}
:::note The following examples show how to use data attributes for variants. This is just one possible approach. See the principles section for more information on how to approach component variants. :::