Alert
A white hairline box where colour lives only in the icon and title.
Your key was rotated
The old key keeps working for 24 hours.
Domain verified
You've used 90% of this month's screenshots
Couldn't reach northwind.io
The site took longer than 30 seconds. Try again or raise the timeout.
Install
$ npx shadcn@latest add @nudgekit/alertOr with no config: npx shadcn@latest add https://ui.nudgekit.app/r/alert.json
Brings in lucide-react, and the theme.
Usage
usage.tsx
import { Alert } from "@/components/ui/alert"
<Alert title="Your key was rotated">The old key keeps working for 24 hours.</Alert>
<Alert tone="bad" title="Couldn't reach northwind.io">Try again or raise the timeout.</Alert>Do
- Keep the title short and say what to do in the body.
Don't
- Fill the alert box with colour.
- Stack more than two alerts.
Code
What the CLI writes into your project. It is yours to change.
components/ui/alert.tsx
import * as React from "react";
import { CircleAlert, CircleCheck, Info, TriangleAlert } from "lucide-react";
import { cn } from "@/lib/utils";
const tones = {
info: { icon: Info, text: "text-brand-ink" },
ok: { icon: CircleCheck, text: "text-success" },
warn: { icon: TriangleAlert, text: "text-warning" },
bad: { icon: CircleAlert, text: "text-danger" },
} as const;
export interface AlertProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "title"> {
tone?: keyof typeof tones;
title: React.ReactNode;
}
/** A hairline box with a coloured icon and title. The box itself stays white: colour lives in the icon and title only. */
function Alert({ tone = "info", title, className, children, ...props }: AlertProps) {
const { icon: Icon, text } = tones[tone];
return (
<div
role={tone === "bad" ? "alert" : "status"}
data-slot="alert"
className={cn("flex gap-3 rounded-xl border border-border bg-background p-4", className)}
{...props}
>
<Icon aria-hidden className={cn("mt-0.5 size-4 shrink-0", text)} />
<div className="min-w-0 text-sm">
<p className={cn("font-medium", text)}>{title}</p>
{children && <div className="mt-1 leading-relaxed text-muted-foreground">{children}</div>}
</div>
</div>
);
}
export { Alert };