CardGrid
Lays out Cards with one 16 pixel gutter both ways. With a title it is a group of cards under a heading.
import { CardGrid } from '@adecore/ui';import { Card, CardGrid, Meter } from '@adecore/ui';
const APPS = [
{ name: 'Desktop', count: 31 },
{ name: 'Phone', count: 12 },
{ name: 'Daemon', count: 5 }
];
export default function CardGridDemo() {
return (
<CardGrid columns={3} className="w-full">
<Card.Root span={2}>
<Card.Header title="Error events per day">
<a href="#issues" className="hover:text-text">
View issues
</a>
</Card.Header>
<Card.Body>
<div className="min-h-24 grow rounded-md bg-surface-sunken" />
</Card.Body>
</Card.Root>
<Card.Root>
<Card.Header title="Open issues by app" />
<Card.Body className="gap-2 text-xs">
{APPS.map((app) => (
<div key={app.name} className="flex items-center gap-2">
<span className="w-16 text-text">{app.name}</span>
<Meter label={`Open issues in ${app.name}`} value={app.count} max={31} className="grow" />
</div>
))}
</Card.Body>
<Card.Footer>48 open</Card.Footer>
</Card.Root>
<Card.Root span="full">
<Card.Body className="text-xs text-text">This outage opened three issues.</Card.Body>
</Card.Root>
</CardGrid>
);
}<CardGrid columns={3}>
<Card.Root span={2}>…</Card.Root>
<Card.Root>…</Card.Root>
</CardGrid>columns is 1, 2 (the default), 3 or 4. The grid answers to its own width, not the window's: once a column would be narrower than 280 pixels it falls back to one column.
A card sets its own place with span on Card.Root: a number of columns, or full for the whole row. A span never reaches past the grid, so a wide card in the one-column fallback is one column wide. Because the card reads its place from the grid around it, a component of your own that returns a Card.Root takes its span like any other card.
Rows
The default flow="grid" lines the cards up in rows. Every card in a row is as tall as the tallest one, and its body takes the extra height, so a chart or a list can fill it. Give a card className="self-start" to keep its own height.
Any other element in the grid takes one place like a card.
Masonry
flow="masonry" closes each card up under the one above it, in columns, and keeps every card at its own height. A card with span="full" runs across all columns; the cards after it start new columns under it. A span of 2 or 3 has no column to join in masonry, so it runs across the full row too.
import { Card, CardGrid, KeyValueList, Meter, Pill } from '@adecore/ui';
import { Info, Music, Smartphone, TriangleAlert, Volume2 } from 'lucide-react';
export default function CardGridMasonryDemo() {
return (
<CardGrid flow="masonry" className="w-full">
<Card.Root>
<Card.Header title="Now playing" icon={Music} />
<Card.Body className="gap-3 text-xs">
<span className="text-text">Weather report, 1:42 of 3:58</span>
<Meter label="Playback position" value={43} />
</Card.Body>
</Card.Root>
<Card.Root>
<Card.Header title="Volume" icon={Volume2}>
<Pill tone="muted">absolute</Pill>
</Card.Header>
<Card.Body>
<Meter label="Volume" value={35} />
</Card.Body>
</Card.Root>
<Card.Root>
<Card.Header title="Device" icon={Info} />
<Card.Body>
<KeyValueList.Root>
<KeyValueList.Item>
<KeyValueList.Name>Address</KeyValueList.Name>
<KeyValueList.Value mono>192.168.1.42</KeyValueList.Value>
</KeyValueList.Item>
<KeyValueList.Item>
<KeyValueList.Name>Port</KeyValueList.Name>
<KeyValueList.Value mono>7000</KeyValueList.Value>
</KeyValueList.Item>
</KeyValueList.Root>
</Card.Body>
</Card.Root>
<Card.Root>
<Card.Header title="Recent errors" icon={TriangleAlert} />
<Card.Body className="text-xs text-text-muted">No errors logged for this device.</Card.Body>
</Card.Root>
<Card.Root span="full">
<Card.Header title="Clients" icon={Smartphone}>
<Pill tone="muted" mono>
2
</Pill>
</Card.Header>
<Card.Body className="text-xs text-text-muted">Two apps hold a session with the device.</Card.Body>
</Card.Root>
</CardGrid>
);
}Groups
title puts a heading 12 pixels above the cards, with icon before it. The grid is then a section named by that heading, and the titles of its cards are one heading level below it.
A grid inside a grid takes the full row of the outer one, so the cards of two groups never share a column. Stack groups and the other blocks of a screen, such as a banner, in a CardGrid of one column: it keeps one gutter between them. A group without a title starts its own set of columns the same way. A group inside a group nests.
import { Banner, Card, CardGrid } from '@adecore/ui';
import { ListMusic, Settings2, Shuffle, Tv, Unplug } from 'lucide-react';
export default function CardGridGroupsDemo() {
return (
<CardGrid columns={1} className="w-full">
<Banner placement="inline" icon={Unplug} tone="attention" message="Not connected. The controls below wait for the device." />
<CardGrid flow="masonry">
<Card.Root>
<Card.Header title="Transport" />
<Card.Body className="text-xs text-text-muted">Play, pause and skip.</Card.Body>
</Card.Root>
<Card.Root>
<Card.Header title="Volume" />
<Card.Body className="text-xs text-text-muted">35%</Card.Body>
</Card.Root>
</CardGrid>
<CardGrid title="Modes and queue" icon={ListMusic} flow="masonry">
<Card.Root>
<Card.Header title="Modes" icon={Shuffle} />
<Card.Body className="text-xs text-text-muted">Shuffle off, repeat all.</Card.Body>
</Card.Root>
<Card.Root>
<Card.Header title="Queue" />
<Card.Body className="text-xs text-text-muted">Four items after this one.</Card.Body>
</Card.Root>
<CardGrid title="Advanced" icon={Settings2} flow="masonry">
<Card.Root collapsible defaultOpen={false}>
<Card.Header title="Extra keys" icon={Tv} />
<Card.Body className="text-xs text-text-muted">Home, menu and the four arrows.</Card.Body>
</Card.Root>
</CardGrid>
</CardGrid>
</CardGrid>
);
}CardGrid renders a <div>, or a <section> with a title, and takes its props, plus render. CardGridProps, CardGridColumns, CardGridFlow and CardSpan are exported types.