Melding
Een inline-toelichting voor fouten in het formulier, waarschuwingen en bevestigingen van succes — panelen in de kleur van de status, met neobrutalistische randen en harde schaduwen.
import { CheckCircle2Icon, InfoIcon } from "lucide-react"
import {De alert is een inline-melding: een pictogram, een titel, een beschrijving en optioneel een actie, geordend op een CSS-grid. Het is een dependency-vrije div met role="alert" — geen primitive eronder, identiek in beide backends — vormgegeven volgens het neobrutalistische recept: dikke randen, harde schaduwen en vette typografie, met een status-as voor de kleuren van fouten, succes, waarschuwingen en info.
Gebruik deze component bij:
- Formulier- en verzoekfouten — toon een validatiefout of een mislukte API-call direct naast de plek waar het misging.
- Succes- en statusbevestigingen — "instellingen opgeslagen", "proefperiode loopt af", "betaling ontvangen", gekleurd via de prop
status. - Meldingen met een vervolgactie — een waarschuwing of upgrademelding met een
AlertAction-knop ("Inschakelen", "Ongedaan maken", "Upgraden").
Installatie#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/alert.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/alert.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/alert.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/alert.json
Kopieer en plak de volgende code in je project.
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
// CSS-grid layout (shadcn-style): drop an icon as a direct child and the alert
// auto-arranges into an icon column + a content column — no manual flex wrapper.
// `has-[>svg]` adds the icon column only when an icon is present. NeoBrutalist
// chrome: hard 2px border, square corners, hard offset shadow.
const alertVariants = cva(
cn(
"group/alert relative grid w-full grid-cols-[0_1fr] items-start gap-y-1 rounded border-2 px-4 py-3 text-left text-sm shadow-md",
"has-[>svg]:grid-cols-[1.25rem_1fr] has-[>svg]:gap-x-3",
"has-data-[slot=alert-action]:pr-14",
"[&>svg]:size-5 [&>svg]:translate-y-0.5 [&>svg]:shrink-0 [&>svg]:text-current"
),
{
variants: {
// shadcn's variant axis (kept for API compatibility). `solid` is a Neobrutalism
// addition.
variant: {
default:
"border-border bg-background text-foreground *:data-[slot=alert-description]:text-muted-foreground",
destructive:
"border-red-900 bg-red-300 text-red-900 *:data-[slot=alert-description]:text-red-900/80",
solid:
"border-border bg-foreground text-background *:data-[slot=alert-description]:text-background/80",
},
// Neobrutalism status axis — additive; overrides the variant's colors when set.
status: {
error:
"border-red-900 bg-red-300 text-red-900 *:data-[slot=alert-description]:text-red-900/80",
success:
"border-green-900 bg-green-300 text-green-900 *:data-[slot=alert-description]:text-green-900/80",
warning:
"border-yellow-900 bg-yellow-300 text-yellow-900 *:data-[slot=alert-description]:text-yellow-900/80",
info: "border-blue-900 bg-blue-300 text-blue-900 *:data-[slot=alert-description]:text-blue-900/80",
},
},
defaultVariants: {
variant: "default",
},
}
)
function Alert({
className,
variant,
status,
...props
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
return (
<div
data-slot="alert"
role="alert"
className={cn(alertVariants({ variant, status }), className)}
{...props}
/>
)
}
function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-title"
className={cn(
"col-start-2 min-h-5 font-head text-base leading-tight tracking-tight [&_a]:underline [&_a]:underline-offset-3",
className
)}
{...props}
/>
)
}
function AlertDescription({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-description"
className={cn(
"col-start-2 grid justify-items-start gap-1 text-sm [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p]:leading-relaxed [&_p:not(:last-child)]:mb-4",
className
)}
{...props}
/>
)
}
function AlertAction({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="alert-action"
className={cn("absolute top-2 right-2", className)}
{...props}
/>
)
}
export { Alert, AlertTitle, AlertDescription, AlertAction, alertVariants }
Werk de import-paden bij zodat ze overeenkomen met je projectstructuur.
Gebruik#
import {
Alert,
AlertAction,
AlertDescription,
AlertTitle,
} from "@/components/ui/alert"<Alert>
<InfoIcon />
<AlertTitle>Heads up!</AlertTitle>
<AlertDescription>
You can add components and dependencies to your app using the cli.
</AlertDescription>
<AlertAction>
<Button variant="outline">Enable</Button>
</AlertAction>
</Alert>Compositie#
Gebruik de volgende compositie om een Alert te bouwen:
Alert
├── Icon
├── AlertTitle
├── AlertDescription
└── AlertActionVoorbeelden#
Basis#
Een eenvoudige alert met een pictogram, titel en beschrijving.
import { CheckCircle2Icon } from "lucide-react"
import {Destructief#
Gebruik variant="destructive" om een destructieve alert te maken.
import { AlertCircleIcon } from "lucide-react"
import {Actie#
Gebruik AlertAction om een knop of ander actie-element aan de alert toe te voegen.
import {
Alert,
AlertAction,Aangepaste kleuren#
Je kunt de kleuren van de alert aanpassen door aangepaste klassen zoals bg-amber-50 dark:bg-amber-950 aan de component Alert toe te voegen.
import { AlertTriangleIcon } from "lucide-react"
import {RTL#
Om RTL-ondersteuning in Neobrutalism in te schakelen, zie de RTL-configuratiegids.
"use client"
import * as React from "react"Toegankelijkheid#
De root van de alert rendert role="alert", een impliciete assertieve live-regio: schermlezers lezen de inhoud voor zodra die in de DOM wordt ingevoegd. Die aankondiging klinkt alleen bij dynamisch invoegen — een alert die al bij het laden van de pagina aanwezig is, wordt als gewone tekst gelezen; render de alert dus conditioneel wanneer die gehoord moet worden. role="alert" verplaatst nooit de focus; moet de gebruiker eerst reageren voordat die verder kan, gebruik dan een alert dialog en behandel AlertAction als een handige afkorting, niet als de enige weg vooruit.
API-referentie#
Alert#
De component Alert toont een melding om de aandacht van de gebruiker te trekken.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "default" |
AlertTitle#
De component AlertTitle toont de titel van de alert.
| Prop | Type | Default |
|---|---|---|
className | string | - |
AlertDescription#
De component AlertDescription toont de beschrijving of inhoud van de alert.
| Prop | Type | Default |
|---|---|---|
className | string | - |
AlertAction#
De component AlertAction toont een actie-element (zoals een knop) dat absoluut in de rechterbovenhoek van de alert is geplaatst.
| Prop | Type | Default |
|---|---|---|
className | string | - |