Karte
Ein umrandetes Feld für Dashboards, Preisstufen und Produkttabellen – Kopfzeile, Inhalt und Fußzeile mit dem neobrutalistischen „Hard-Shadow“-Effekt.
import { Button } from "@/components/ui/button"
import {
Card,Die Card gruppiert zusammengehörige Inhalte in einer eigenständigen Box mit optionalen Slots für Header, Inhalt und Footer. Darunter liegt kein Primitive – schlichtes Markup, gestaltet nach dem neobrutalistischen Rezept: ein dicker Rahmen, ein harter versetzter Schatten und ein Titel in der Überschriftenschrift.
Die richtige Wahl für:
- Dashboard-Panels – Statistik-Kacheln, Diagramme und Aktivitäts-Feeds im Raster angeordnet.
- Preisstufen – Tarifname und Preis im Header, Features im Rumpf, der Kauf-Button im Footer.
- Eigenständige Formulare – Login-, Registrierungs- und Einstellungsboxen, die eine sichtbare Begrenzung brauchen.
Installation#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/card.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/card.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/card.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/card.json
Kopiere den folgenden Code und füge ihn in dein Projekt ein.
import * as React from "react"
import { cn } from "@/lib/utils"
function Card({
className,
size = "default",
...props
}: React.ComponentProps<"div"> & { size?: "default" | "sm" }) {
return (
<div
data-slot="card"
data-size={size}
className={cn(
"group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded border-2 bg-card py-(--card-spacing) text-sm text-card-foreground shadow-md [--card-spacing:--spacing(4)] has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(3)] data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
className
)}
{...props}
/>
)
}
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-header"
className={cn(
"group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-(--card-spacing) has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-(--card-spacing)",
className
)}
{...props}
/>
)
}
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-title"
className={cn(
"cn-font-heading text-base leading-snug font-medium group-data-[size=sm]/card:text-sm",
className
)}
{...props}
/>
)
}
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-description"
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
)
}
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-action"
className={cn(
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
className
)}
{...props}
/>
)
}
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-content"
className={cn("px-(--card-spacing)", className)}
{...props}
/>
)
}
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-footer"
className={cn(
"flex items-center rounded-b-xl border-t-2 bg-muted/50 p-(--card-spacing)",
className
)}
{...props}
/>
)
}
export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardAction,
CardDescription,
CardContent,
}
Passe die Import-Pfade an die Struktur deines Projekts an.
Verwendung#
import {
Card,
CardAction,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"<Card>
<CardHeader>
<CardTitle>Card Title</CardTitle>
<CardDescription>Card Description</CardDescription>
<CardAction>Card Action</CardAction>
</CardHeader>
<CardContent>
<p>Card Content</p>
</CardContent>
<CardFooter>
<p>Card Footer</p>
</CardFooter>
</Card>Komposition#
Verwende die folgende Komposition, um eine Card aufzubauen:
Card
├── CardHeader
│ ├── CardTitle
│ ├── CardDescription
│ └── CardAction
├── CardContent
└── CardFooterBeispiele#
Größe#
Verwende die Prop size="sm", um die Größe der Card auf klein zu setzen. Die kleine Größenvariante verwendet geringere Abstände.
import { ChevronRightIcon } from "lucide-react"
import { Button } from "@/components/ui/button"Abstände#
Zusätzlich zur Prop size kannst du die CSS-Variable --card-spacing verwenden, um die Abstände zwischen den Abschnitten und den Innenabstand der Card-Teile zu steuern.
"use client"
import * as React from "react"Verwende negative Margins mit -mx-(--card-spacing), damit sich der Inhalt von Kante zu Kante erstreckt und dabei am Innenabstand der Card ausgerichtet bleibt. Wenn der Kante-zu-Kante-Inhalt über einem Footer sitzt, verwende -mb-(--card-spacing) an CardContent, um den Abschnittsabstand zu entfernen.
import { Button } from "@/components/ui/button"
import {
Card,Bild#
Füge ein Bild vor dem Card-Header hinzu, um eine Card mit Bild zu erstellen.
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {RTL#
Um die RTL-Unterstützung in Neobrutalism zu aktivieren, siehe die RTL-Konfigurationsanleitung.
"use client"
import * as React from "react"Barrierefreiheit#
Die Card ist rein präsentational – jeder Teil rendert ein schlichtes <div> ohne implizite Rolle und trägt damit nichts zum Accessibility-Baum bei. CardTitle ist kein Überschriftenelement: Verschachtele ein echtes <h2>–<h4> darin, wenn der Titel in der Dokumentstruktur auftauchen soll. Bei klickbaren Cards gehört der Link oder Button in die Card, mit einer über die Fläche gestreckten Trefferfläche – häng onClick niemals an das Card-<div> selbst.
API-Referenz#
Card#
Die Card-Komponente ist der Wurzel-Container für den Card-Inhalt.
| Prop | Type | Default |
|---|---|---|
size | "default" | "sm" | "default" |
className | string | - |
CardHeader#
Die CardHeader-Komponente wird für einen Titel, eine Beschreibung und eine optionale Aktion verwendet.
| Prop | Type | Default |
|---|---|---|
className | string | - |
CardTitle#
Die CardTitle-Komponente wird für den Titel der Card verwendet.
| Prop | Type | Default |
|---|---|---|
className | string | - |
CardDescription#
Die CardDescription-Komponente wird für den Hilfetext unter dem Titel verwendet.
| Prop | Type | Default |
|---|---|---|
className | string | - |
CardAction#
Die CardAction-Komponente platziert Inhalt oben rechts im Header (zum Beispiel einen Button oder ein Badge).
| Prop | Type | Default |
|---|---|---|
className | string | - |
CardContent#
Die CardContent-Komponente wird für den Hauptteil der Card verwendet.
| Prop | Type | Default |
|---|---|---|
className | string | - |
CardFooter#
Die CardFooter-Komponente wird für Aktionen und sekundäre Inhalte im unteren Bereich der Card verwendet.
| Prop | Type | Default |
|---|---|---|
className | string | - |
Changelog#
Abstands-Variable#
Wenn du von einer früheren Version der Card-Komponente aktualisierst, musst du die folgenden Änderungen anwenden, um die Variable --card-spacing zu verwenden:
Aktualisiere die Abstands-Klassen der Card-Wurzel.
Ersetze das fest kodierte Gap und das vertikale Padding durch --card-spacing und setze die Werte für die Standard- und kleine Größe an der Wurzel:
className={cn(
- "group/card flex flex-col gap-4 overflow-hidden rounded-xl bg-card py-4 text-sm text-card-foreground ring-1 ring-foreground/10 has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:gap-3 data-[size=sm]:py-3 data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
+ "group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-xl bg-card py-(--card-spacing) text-sm text-card-foreground ring-1 ring-foreground/10 [--card-spacing:--spacing(4)] has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(3)] data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
className
)}Aktualisiere die Abstands-Klassen von CardHeader.
Ersetze das horizontale Padding und den Rahmenabstand durch die gemeinsame Variable:
className={cn(
- "group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-4 group-data-[size=sm]/card:px-3 has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-4 group-data-[size=sm]/card:[.border-b]:pb-3",
+ "group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-(--card-spacing) has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-(--card-spacing)",
className
)}Aktualisiere die Abstands-Klassen von CardContent und CardFooter.
Verwende --card-spacing für den Innenabstand des Inhalts und das Padding des Footers:
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-content"
- className={cn("px-4 group-data-[size=sm]/card:px-3", className)}
+ className={cn("px-(--card-spacing)", className)}
{...props}
/>
)
} className={cn(
- "flex items-center rounded-b-xl border-t bg-muted/50 p-4 group-data-[size=sm]/card:p-3",
+ "flex items-center rounded-b-xl border-t bg-muted/50 p-(--card-spacing)",
className
)}Nachdem du diese Änderungen angewendet hast, kannst du die Abstände der Card anpassen, indem du --card-spacing an der Card mit einer arbiträren Property-Klasse setzt:
function Example() {
return <Card className="[--card-spacing:--spacing(6)]">...</Card>
}