implement
Alert

Alert

A standing message about the page.

import { Div } from "@implementjs/core";
import { CircleAlertIcon, TerminalIcon } from "@implementjs/lucide";
import { Alert, AlertDescription, AlertTitle } from "@/lib/components/ui/alert";

export default function AlertDemo() {
	return Div(
		{ class: "flex w-full max-w-lg flex-col gap-4" },
		Alert(
			TerminalIcon({ "aria-hidden": true }),
			AlertTitle("Heads up"),
			AlertDescription("You can add components with the jsrepo CLI."),
		),
		Alert(
			{ variant: "destructive" },
			CircleAlertIcon({ "aria-hidden": true }),
			AlertTitle("Payment failed"),
			AlertDescription("Your card was declined. Try another payment method."),
		),
		Alert(AlertTitle("No icon, no description — just the line.")),
	);
}

Installation

npx jsrepo add @implementjs/ui/alert

It installs tailwind-variants at the same time.

Usage

An alert stays until the situation changes. For something that passes, use a toast; for something that must be answered, an alert dialog.

import { Alert, AlertDescription, AlertTitle } from "@/lib/components/ui/alert";

Alert(
	TerminalIcon({ "aria-hidden": true }),
	AlertTitle("Heads up"),
	AlertDescription("You can add components with the jsrepo CLI."),
);

The icon column

The root is a grid whose first column only appears when an icon is actually there (has-[>svg]), so a text-only alert has no empty gutter to explain. Put the icon first, before the title.

Destructive

Alert({ variant: "destructive" }, CircleAlertIcon(), AlertTitle("Payment failed"));

The variant recolors the title and the description together — the description is reached through *:data-[slot=alert-description], so it follows without being told.

API Reference

Alert

Sets role="alert". A grid that grows an icon column only when an icon is present, so a text-only alert has no empty gutter. Renders a Div; extra props are forwarded onto it.

PropTypeDefaultDescription
variant"default" | "destructive""default"destructive turns the title and description red for a failure.

AlertTitle

The headline. Clamped to one line. Renders a Div; extra props are forwarded onto it.

AlertDescription

The body, in muted text under the title. Renders a Div; extra props are forwarded onto it.