Raft Design System

Components · Layout

Card

A white container with a hairline that groups one subject on a page — a header with a title and description, content and a footer — or makes a selectable option inside a form.

Stable
import { Card } from "@botiverse/raft-ui";

A card groups one subject on a page: a title and a line of description, the content that belongs to it, and an optional footer note. It sits flat on the page, on layer-card with a line-hairline outline and radius-container, and casts no shadow. Its option variant is a selectable choice inside a form.

card/compositions/project-summary

When to use

SituationUse
One subject on a page, with a title and its own content or controlsCard
A setting that turns a feature on, with its configuration under itCard with variant="inset": a switch when the feature works without the fields, a checkbox and one Save when it needs them (Forms)
A choice among a few options in a form, where each option is a blockCard with variant="option", holding a Checkbox or a radio
A group of rows: settings, members, agentsListRowGroup (ListRow)
Properties of one item, label and valueDescriptionList
A part of a large formFormSection
A column of the main areaPanel
A task, a file on a message, a person or an app's item on hoverTaskCard, MessageAttachment, PreviewCard

Anatomy

  • Card: the container. Required.
  • CardHeader: the top row. It lays out the parts below in a grid.
    • CardLeading: an icon, avatar or switch before the title, spanning the title and description rows. Optional.
    • CardTitle: the title. Optional, but most cards have one.
    • CardTrailing: a status, badge or switch at the end of the title row. Optional.
    • CardDescription: a helper line under the title, in text-callout and foreground-muted, only for a consequence (consequence), who sees it or whom it affects (audience), or how to recover (recovery). It takes only a HelperText, made with helperText(content, { why, about }), and renders its why and about as data-why and data-about (Writing › Helper text). Optional.
    • CardSubtitle: data under the title in the description's place, such as a handle ("@ada") or a time and place ("Public beta · Thursday at 10:00"), in text-callout and the base ink. Optional.
  • CardContent: the body. Optional.
  • CardFooter: a helper note about the whole card, with its icon or link inside it, in text-caption and foreground-hint, with a hairline above it. It takes only a HelperText, made with helperText(content, { why, about }), and renders its why and about as data-why and data-about, like CardDescription; data such as an owner or an updated time goes at the end of CardContent. Optional.

Variants

VariantUse for
variant="default"A card on its own, or one with little inside it
variant="inset"A card that holds many controls or nested components: a hairline separates the header and each CardContent
variant="option"An option inside a form: radius-control, the field border (1.5px line-field) and a title at the size of a field label, so it doesn't outrank the label above it
card/compositions/workspace-mode
card/compositions/dense-settings
checkbox/compositions/selection

Content

  • Write the title in sentence case: Release readiness (Writing).
  • Give a card a description only when it has a consequence its title doesn't say, who sees it, or how to recover. A line on what the card is for ("Receive selected Raft events at a webhook") is cut; where it stands is data, in CardSubtitle.
  • Use the footer for a helper note about the whole card, such as who gets its alerts, with a link to read more. Put a card-level action at the end of CardContent instead.

Accessibility

Card renders a div and adds no semantics.

  • Render CardTitle as a heading at the level the page needs, with render: render={<h3 />}.
  • When a Switch or Checkbox in CardLeading or CardTrailing is named by the title, give the title an id and point the control's aria-labelledby at it.
  • For an option card, render the whole card as a label (render={<label />}) so a click anywhere on it toggles the control.

Rules

  • Keep cards flat. Only things that float cast a shadow (Elevation); the open comment card is lifted (Comment).
  • Don't put a card inside a card. An action inside a section is an ordinary row, with the description on the left and the button on the right (Forms).
  • Use line-hairline for every line inside a card; it is content, not a region (Color).
  • Don't attach a progress bar or a colored band to a card's edge (Shape).
  • Apply a switch in a card at once, without a Save button (Forms).

API

Card

PropTypeDefault
variant"option" | "default" | "inset""default"
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

CardContent

PropTypeDefault
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

CardDescription, CardFooter

PropTypeDefault
children (required)HelperText
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

CardHeader, CardLeading, CardSubtitle, CardTitle, CardTrailing

PropTypeDefault
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

Changes

  • 0.103.0 · Breaking ChangesExplanation slots take only a HelperText: FieldDescription, FormSection's description, a ChoiceList item's description, SelectItemDescription, DialogDescription, AlertDialogDescription, DrawerDescription, PopoverDescription, EmptyStateDescription, CardDescription, CardFooter, BannerDescription, DialogFooterNote (work in progress), MessageActionCardHint, MessageActionCardHeaderDescription, MessageActionCardScopeDescription and MessageActionCardActionsNote. A HelperText is made only by helperText(content, { why, about }): content is any ReactNode (a string, a formatted message, a TextLink inside a sentence), why is "consequence", "audience" or "recovery", and about names the thing the line is about. Each slot renders the content with data-why and data-about, and in development warns once when it is given anything else, which it still renders. ToastDescription, NotificationCenterItemBody, EmptyStateTitle, ListRowDescription and the status and data parts are unchanged.
  • 0.103.0 · AddedCardSubtitle: data about the card's subject under its title, where CardDescription would go (a handle, a time and place), in foreground at the description's size (data-slot="card-subtitle").
  • 0.10.0 · Breaking ChangesField frames (Input, Textarea, InputGroup, Select, Combobox, ComboboxSelect, Composer, option Card, SearchTrigger) are drawn at 1px in line-field instead of 1.5px, on the phone too.
  • 0.3.0 · AddedAdded the composable Card component with default and inset variants and the final CardHeader, CardLeading, CardTitle, CardDescription, CardTrailing, CardContent, and CardFooter parts.