Presets

Blocks

Get PRO

Need premium blocks and templates? Upgrade to PRO and get access.

Upgrade
JoinLogin
Presets
Monochrome
Overview
  • Introduction
  • Components
  • Installation
Components
  • Accordion
  • Alert
  • Alert Dialog
  • Aspect Ratio
  • Avatar
  • Badge
  • Breadcrumb
  • Button
  • Button Group
  • CalendarNEW
  • Card
  • CarouselNEW
  • Checkbox
  • Collapsible
  • Dialog
  • Dropdown Menu
  • Empty
  • Field
  • Input
  • Input Group
  • Item
  • Kbd
  • Label
  • Native Select
  • Scroll Area
  • SelectNEW
  • Separator
  • SwitchNEW
  • Table
  • Tabs
  • Textarea
  • TooltipNEW

Alert

PreviousNext

Displays a callout for user attention.

1import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";2import { CheckCircle2Icon, InfoIcon } from "lucide-solid";34export default function Preview() {

Installation

pnpm dlx sprawlify@latest add alert
npx sprawlify@latest add alert
yarn sprawlify@latest add alert
bunx --bun sprawlify@latest add alert

Install the following dependencies:

pnpm add @sprawlify/primitives @sprawlify/solid
npm install @sprawlify/primitives @sprawlify/solid
yarn add @sprawlify/primitives @sprawlify/solid
bun add @sprawlify/primitives @sprawlify/solid

Add the following files to your project:

alert.tsx
1import { type ComponentProps, splitProps } from "solid-js";2import { cva, type VariantProps } from "class-variance-authority";3import { cn } from "@/lib/utils";4import { sprawlify } from "@sprawlify/solid";56const alertVariants = cva(7  "grid gap-0.5 rounded-lg border px-2.5 py-2 text-left text-sm has-data-[slot=alert-action]:relative has-data-[slot=alert-action]:pr-18 has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-2 *:[svg]:row-span-2 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4 w-full relative group/alert",8  {9    variants: {10      variant: {11        default: "bg-card text-card-foreground",12        destructive:13          "text-destructive bg-card *:data-[slot=alert-description]:text-destructive/90 *:[svg]:text-current",14      },15    },16    defaultVariants: {17      variant: "default",18    },19  },20);2122const Alert = (23  props: ComponentProps<typeof sprawlify.div> & VariantProps<typeof alertVariants>,24) => {25  const [local, others] = splitProps(props, ["variant", "class"]);2627  return (28    <sprawlify.div29      data-scope="alert"30      data-part="root"31      data-slot="alert"32      role="alert"33      class={cn(alertVariants({ variant: local.variant }), local.class)}34      {...others}35    />36  );37};3839const AlertTitle = (props: ComponentProps<typeof sprawlify.div>) => {40  const [local, others] = splitProps(props, ["class"]);4142  return (43    <sprawlify.div44      data-scope="alert"45      data-part="title"46      data-slot="alert-title"47      class={cn(48        "font-medium group-has-[>svg]/alert:col-start-2 [&_a]:hover:text-foreground [&_a]:underline [&_a]:underline-offset-3",49        local.class,50      )}51      {...others}52    />53  );54};5556const AlertDescription = (props: ComponentProps<typeof sprawlify.div>) => {57  const [local, others] = splitProps(props, ["class"]);5859  return (60    <sprawlify.div61      data-scope="alert"62      data-part="description"63      data-slot="alert-description"64      class={cn(65        "text-muted-foreground text-sm text-balance md:text-pretty [&_p:not(:last-child)]:mb-4 [&_a]:hover:text-foreground [&_a]:underline [&_a]:underline-offset-3",66        local.class,67      )}68      {...others}69    />70  );71};7273const AlertAction = (props: ComponentProps<typeof sprawlify.div>) => {74  const [local, others] = splitProps(props, ["class"]);7576  return (77    <sprawlify.div78      data-scope="alert"79      data-part="action"80      data-slot="alert-action"81      class={cn("absolute top-2 right-2", local.class)}82      {...others}83    />84  );85};8687export { Alert, AlertTitle, AlertDescription, AlertAction };88

Update the import paths to match your project setup.

Usage

1import {
2  Alert,
3  AlertAction,
4  AlertDescription,
5  AlertTitle,
6} from "@/components/ui/alert"
1<Alert>
2  <InfoIcon />
3  <AlertTitle>Heads up!</AlertTitle>
4  <AlertDescription>
5    You can add components and dependencies to your app using the cli.
6  </AlertDescription>
7  <AlertAction>
8    <Button variant="outline">Enable</Button>
9  </AlertAction>
10</Alert>

Examples

Action

Use AlertAction to add a button or other action element to the alert.

1import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert";2import { Button } from "@/components/ui/button";34export default function Preview() {

Basic

A basic alert with an icon, title and description.

1import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";2import { CheckCircle2Icon } from "lucide-solid";34export default function Preview() {

Custom Colors

You can customize the alert colors by adding custom classes such as bg-amber-50 dark:bg-amber-950 to the Alert component.

1import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";2import { AlertTriangleIcon } from "lucide-solid";34export default function Preview() {

Destructive

Use variant="destructive" to create a destructive alert.

1import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";2import { AlertCircleIcon } from "lucide-solid";34export default function Preview() {

On This Page

InstallationUsageExamplesActionBasicCustom ColorsDestructive

Get PRO

Need premium blocks and templates? Upgrade to PRO and get access.