Card05
A box for related content: a title, a body, actions and a footer. Sticker can tape it to the page, Retro turns it into a window, Comic into a panel with a caption box, Arcade into a score screen.
Weekly report
<Card title="Weekly report">
Signups are up 12% since the new onboarding shipped.
</Card>Usage
import { Card } from "plonk-ui";
export function Report() {
return (
<Card title="Weekly report">
Signups are up 12% since the new onboarding shipped.
</Card>
);
}Card is a <section>. Every part is optional, and only the parts you pass
are rendered, so a card can be just a body or just a title.
Anatomy
title and description head the card, actions sit to the right of the
title, children is the body and footer holds the buttons at the bottom.
Spring launch
Landing page, emails and the press kit.
import { Badge, Button, Card } from "plonk-ui";
export default function Anatomy() {
return (
<Card
className="w-full max-w-sm"
title="Spring launch"
description="Landing page, emails and the press kit."
actions={<Badge variant="success">On track</Badge>}
footer={
<>
<Button size="sm">Open board</Button>
<Button size="sm" variant="ghost">
Share
</Button>
</>
}
>
Copy is final. Illustrations land on Friday, then we hand everything to
the dev team.
</Card>
);
}Closable
Pass onClose to show a close box. The card doesn't hide itself; you decide
what closing means. Give the box a specific name with closeLabel.
Tip
import { useState } from "react";
import { Button, Card } from "plonk-ui";
export default function Closable() {
const [open, setOpen] = useState(true);
if (!open) {
return (
<Button variant="neutral" onPress={() => setOpen(true)}>
Bring the tip back
</Button>
);
}
return (
<Card
className="w-full max-w-xs"
title="Tip"
onClose={() => setOpen(false)}
closeLabel="Dismiss tip"
>
Press ⌘K anywhere to jump to a page.
</Card>
);
}Tilt
tilt sticks the card on at a slight angle, to the left or the right. The
angle is the personality's --plonk-tilt: 1.5° in Sticker, 0.8° in Comic, and
none in Retro and Arcade, which stay straight.
To do
Done
import { Card } from "plonk-ui";
export default function Tilt() {
return (
<div className="flex flex-wrap justify-center gap-6">
<Card tilt="left" title="To do" className="w-44">
Pick fonts
</Card>
<Card tilt="right" title="Done" className="w-44">
Choose a name
</Card>
</div>
);
}Tape
Cards have no tape by default. Add it with tape, and each personality draws
its own: paper tape in Sticker, a dithered pixel strip at the top right in
Retro, a blue halftone strip in Comic, and a blinking neon "1UP" plate in
Arcade.
<Card tape title="Pinned note">
Same prop, four kinds of tape.
</Card>;"sticker"Squash, stretch, spring backPinned note
"retro"Stepped, instant, framedPinned note
"comic"Fast, overshooting, loudPinned note
"arcade"Pixel steps, neon, pointsPinned note
The provider's tape setting turns tape off for toasts and the data table, but
never adds it to cards: a card only has tape when you ask for it. See
Personalities for the global switch.
Personalities
Sticker is a sheet of paper with a hard shadow. Retro wraps the card in a window with a striped title bar, and the close box moves to the left like on an old Mac. Comic prints a halftone corner and puts the title in a yellow caption box. Arcade lights the title up like a high score.
Accessibility
- A card with a
titleis a region named by its title, so screen reader users can find it in the landmarks list. Without a title it's a plain section. - The title is an
<h3>by default. SetheadingLevelso it follows the page's outline: a card under an<h2>section keeps3, a card that starts its own section can use2. - The close box is a real button with an accessible name, "Close" by default.
- Tape, halftone and title bar stripes are decoration and stay silent.
API
All other <section> props are passed through.
| Prop | Type | Default | Description |
|---|---|---|---|
title | ReactNode | — | Heading, used to name the card's region. In Retro it sits in the window's title bar. |
description | ReactNode | — | Muted line under the title. |
actions | ReactNode | — | Content on the right of the header, like a badge, a button or a menu. |
footer | ReactNode | — | Bottom row, usually buttons. Wraps on narrow screens. |
onClose | () => void | — | Shows a close box and calls this when it's pressed. Retro puts it at the left of the title bar. |
closeLabel | string | "Close" | Accessible name of the close box. |
tape | boolean | false | Sticks decorative tape on top, drawn differently by each personality. |
tilt | "left" | "right" | — | Sticks the card on at the personality's tilt angle. Retro and Arcade stay straight. |
headingLevel | 2 | 3 | 4 | 5 | 6 | 3 | Heading level of the title, so it fits your page's outline. |