Skip to content

Card ​

A block of a screen: a bordered surface with an optional one-line header and a body. Use it for a group of facts, a chart or a short list on a dashboard or an overview. For a card that floats over content, use a Surface.

tsx
import { Card } from '@adecore/ui';
tsx
import { Card, KeyValueList, Pill } from '@adecore/ui';
import { Info } from 'lucide-react';

export default function CardDemo() {
    return (
        <Card.Root className="w-full max-w-sm">
            <Card.Header title="Device" icon={Info}>
                <Pill tone="muted">paired</Pill>
            </Card.Header>
            <Card.Body>
                <KeyValueList.Root divided>
                    <KeyValueList.Item>
                        <KeyValueList.Name>Identifier</KeyValueList.Name>
                        <KeyValueList.Value mono>AA:BB:CC:DD:EE:FF</KeyValueList.Value>
                    </KeyValueList.Item>
                    <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>
    );
}
tsx
<Card.Root>
    <Card.Header title="Device" icon={Info}>
        <Pill tone="muted">paired</Pill>
    </Card.Header>
    <Card.Body>…</Card.Body>
</Card.Root>

Parts ​

PartWhat it is
Card.RootThe card, a <section>. ground is raised (the default) or surface. collapsible, open, defaultOpen and onOpenChange fold it. span sets its place in a CardGrid.
Card.HeaderOne line of at least 44 pixels. title is the heading, icon a 16 pixel Lucide icon before it. The children sit at the end in small muted text: a pill, a link, an icon button, a Segmented. toggle places the fold toggle at the start or the end (the default).
Card.BodyThe content, padded 16 pixels. flush runs it to the edges.
Card.FooterOne line at the bottom edge, under a hairline: a summary, a link to more, actions.

Every part takes the props of its element, plus render to draw another one.

The card is named by its title, so a screen reader announces it as a region. It is a container too, so its content can respond to the card's width with a container query (@md:grid-cols-2) instead of the window's.

Plain text or a link at either end of the header or footer lines up with the body's 16 pixel edge. Any other element there counts as a box and moves into the corner, 8 pixels from the edge. An icon button sits exactly as far from the edge as from the top and bottom of the line, at any size.

Header only, body only ​

Leave out the body for a card that says everything in its header, and the header for a card that is content only. Neither needs a prop.

tsx
import { Card, IconButton } from '@adecore/ui';
import { Activity, RotateCcw, Tv } from 'lucide-react';

export default function CardStatesDemo() {
    return (
        <div className="grid w-full max-w-2xl grid-cols-1 items-start gap-4 sm:grid-cols-2">
            <Card.Root>
                <Card.Header title="Event loop" icon={Activity}>
                    <IconButton icon={RotateCcw} label="Reset the peak" size="sm" />
                </Card.Header>
                <Card.Body className="text-xs text-text-muted">Delay p99 4 ms</Card.Body>
            </Card.Root>
            <Card.Root collapsible defaultOpen={false}>
                <Card.Header title="Extra keys" icon={Tv} />
                <Card.Body className="text-xs text-text-muted">Home, menu, volume and the four arrows.</Card.Body>
            </Card.Root>
            <Card.Root>
                <Card.Header title="Last 90 days">99.98% up</Card.Header>
            </Card.Root>
            <Card.Root>
                <Card.Body className="text-xs text-text-muted">No outage in the last 90 days.</Card.Body>
            </Card.Root>
        </div>
    );
}

Folding ​

collapsible adds a toggle at the end of the header. A folded card shows only its header, and hides the header's other children and the footer. defaultOpen sets where it starts; open and onOpenChange let you hold the state yourself.

toggle="start" puts the toggle before the icon and title instead. Only the header row moves to make room for it: the body and footer keep their 16 pixel edge, and the header's children stay at the end.

tsx
import { Card, KeyValueList, Pill } from '@adecore/ui';
import { Info, Tv } from 'lucide-react';

export default function CardToggleDemo() {
    return (
        <div className="grid w-full max-w-2xl grid-cols-1 items-start gap-4 sm:grid-cols-2">
            <Card.Root collapsible>
                <Card.Header title="Receiver" icon={Info}>
                    <Pill tone="muted">2</Pill>
                </Card.Header>
                <Card.Body>
                    <KeyValueList.Root>
                        <KeyValueList.Item>
                            <KeyValueList.Name>Model</KeyValueList.Name>
                            <KeyValueList.Value>Living room</KeyValueList.Value>
                        </KeyValueList.Item>
                        <KeyValueList.Item>
                            <KeyValueList.Name>Firmware</KeyValueList.Name>
                            <KeyValueList.Value mono>17.4</KeyValueList.Value>
                        </KeyValueList.Item>
                    </KeyValueList.Root>
                </Card.Body>
            </Card.Root>
            <Card.Root collapsible>
                <Card.Header title="Extra keys" icon={Tv} toggle="start">
                    <Pill tone="muted">7</Pill>
                </Card.Header>
                <Card.Body className="text-xs text-text-muted">Home, menu, volume and the four arrows.</Card.Body>
            </Card.Root>
        </div>
    );
}

A table or list ​

flush drops the body's padding, for a table or list whose rows bring their own.

tsx
import { Card, Table } from '@adecore/ui';

const COLUMNS = [{ width: 'minmax(0,1fr)' }, { width: 'auto' }, { width: 'auto' }] as const;

const APPS = [
    { name: 'Desktop', sessions: '18,204', crashFree: '99.4%' },
    { name: 'Phone', sessions: '6,311', crashFree: '98.7%' },
    { name: 'Daemon', sessions: '1,208', crashFree: '99.9%' }
];

export default function CardFlushDemo() {
    return (
        <Card.Root className="w-full max-w-md">
            <Card.Header title="Crash-free sessions">Last 7 days</Card.Header>
            <Card.Body flush>
                <Table.Root label="Crash-free sessions per app" columns={COLUMNS}>
                    <Table.Head>
                        <Table.Column>App</Table.Column>
                        <Table.Column>Sessions</Table.Column>
                        <Table.Column>Crash-free</Table.Column>
                    </Table.Head>
                    {APPS.map((app) => (
                        <Table.Row key={app.name}>
                            <Table.Cell>{app.name}</Table.Cell>
                            <Table.Cell>{app.sessions}</Table.Cell>
                            <Table.Cell>{app.crashFree}</Table.Cell>
                        </Table.Row>
                    ))}
                </Table.Root>
            </Card.Body>
        </Card.Root>
    );
}

Card.Footer stays at the bottom edge, also when a grid stretches the card taller than its content. The body takes the height in between and hands it on as a column, so a chart or a list in it can grow into it or scroll. A card with a header and a footer needs no body.

tsx
import { Card, IconButton, Table } from '@adecore/ui';
import { RefreshCw } from 'lucide-react';

const COLUMNS = [{ width: 'minmax(0,1fr)' }, { width: 'auto' }] as const;

const CLIENTS = [
    { bundle: 'com.example.music', state: 'playing' },
    { bundle: 'com.example.podcasts', state: 'paused' }
];

export default function CardFooterDemo() {
    return (
        <Card.Root className="w-full max-w-md">
            <Card.Header title="Clients">
                <IconButton icon={RefreshCw} label="Refresh" size="sm" />
            </Card.Header>
            <Card.Body flush>
                <Table.Root label="Clients" columns={COLUMNS}>
                    <Table.Head>
                        <Table.Column>Bundle</Table.Column>
                        <Table.Column>State</Table.Column>
                    </Table.Head>
                    {CLIENTS.map((client) => (
                        <Table.Row key={client.bundle}>
                            <Table.Cell mono>{client.bundle}</Table.Cell>
                            <Table.Cell>{client.state}</Table.Cell>
                        </Table.Row>
                    ))}
                </Table.Root>
            </Card.Body>
            <Card.Footer>
                2 of 14 clients
                <a href="#clients" className="ml-auto hover:text-text">
                    View all
                </a>
            </Card.Footer>
        </Card.Root>
    );
}

CardRootProps, CardHeaderProps, CardBodyProps, CardFooterProps and CardGround are exported types.

Licenses and third-party notices are listed in each package.