HapplyUI

Components

Widget Card

The surface for a single chart, list or metric. Set the card's height on Root; the content area fills what the header leaves and can scroll inside it rather than overflowing the card.


Installation

bunx @happlyui/cli@latest add widget-card

Dependencies

Registry dependencies

These are automatically installed when you add this component.

  • happly-ui-utils

Usage

import * as WidgetCard from "@/components/ui/widget-card"

<WidgetCard.Root className="h-[288px]">
  <WidgetCard.Header>
    <WidgetCard.Title>Card title</WidgetCard.Title>
  </WidgetCard.Header>
  <WidgetCard.Content>{chart}</WidgetCard.Content>
</WidgetCard.Root>

Examples

Default

A title and whatever the card holds. The card's height comes from className on Root.

Card title

Content
<WidgetCard.Root className="h-[288px]">
  <WidgetCard.Header>
    <WidgetCard.Title>Card title</WidgetCard.Title>
  </WidgetCard.Header>
  <WidgetCard.Content>{chart}</WidgetCard.Content>
</WidgetCard.Root>

With details

Anything placed after the title sits at the end of the header row. Use a neutral stroke xxsmall Button for the Details action.

Card title

Content
<WidgetCard.Header>
  <WidgetCard.Title>Card title</WidgetCard.Title>
  <Button.Root variant="neutral" mode="stroke" size="xxsmall" onClick={openDetails}>
    Details
  </Button.Root>
</WidgetCard.Header>

Compact title

KPI cards use a smaller, muted title and a tighter gap. Both are className overrides.

Metric title

1,234
<WidgetCard.Root className="gap-1">
  <WidgetCard.Header>
    <WidgetCard.Title className="text-paragraph-sm text-text-sub-600">Metric title</WidgetCard.Title>
  </WidgetCard.Header>
  <WidgetCard.Content>...</WidgetCard.Content>
</WidgetCard.Root>

API Reference

WidgetCard.Root

The card surface. Set its height with className; it has none by default.

PropTypeDefaultDescription
classNamestring-Height, width and any other overrides

WidgetCard.Header

The title row. The first child sits at the start, anything after it at the end.

PropTypeDefaultDescription

WidgetCard.Title

The card title, rendered as an h3.

PropTypeDefaultDescription

WidgetCard.Content

Fills the space below the header and can shrink below its content, so a fixed-height card constrains it.

PropTypeDefaultDescription
classNamestring-Add overflow-y-auto when the content can outgrow the card

Previous
Spark Stat
Next
Chat