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.
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.
When to use
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, intext-calloutandforeground-muted, only for a consequence (consequence), who sees it or whom it affects (audience), or how to recover (recovery). It takes only aHelperText, made withhelperText(content, { why, about }), and renders itswhyandaboutasdata-whyanddata-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"), intext-calloutand the base ink. Optional.
CardContent: the body. Optional.CardFooter: a helper note about the whole card, with its icon or link inside it, intext-captionandforeground-hint, with a hairline above it. It takes only aHelperText, made withhelperText(content, { why, about }), and renders itswhyandaboutasdata-whyanddata-about, likeCardDescription; data such as an owner or an updated time goes at the end ofCardContent. Optional.
Variants
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
CardContentinstead.
Accessibility
Card renders a div and adds no semantics.
- Render
CardTitleas a heading at the level the page needs, withrender:render={<h3 />}. - When a
SwitchorCheckboxinCardLeadingorCardTrailingis named by the title, give the title anidand point the control'saria-labelledbyat it. - For an
optioncard, render the whole card as alabel(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-hairlinefor 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
Also takes the attributes of its element.
CardContent
Also takes the attributes of its element.
CardDescription, CardFooter
Also takes the attributes of its element.
CardHeader, CardLeading, CardSubtitle, CardTitle, CardTrailing
Also takes the attributes of its element.
Related
Changes
- 0.103.0 · Breaking ChangesExplanation slots take only a
HelperText:FieldDescription,FormSection'sdescription, aChoiceListitem'sdescription,SelectItemDescription,DialogDescription,AlertDialogDescription,DrawerDescription,PopoverDescription,EmptyStateDescription,CardDescription,CardFooter,BannerDescription,DialogFooterNote(work in progress),MessageActionCardHint,MessageActionCardHeaderDescription,MessageActionCardScopeDescriptionandMessageActionCardActionsNote. AHelperTextis made only byhelperText(content, { why, about }):contentis anyReactNode(a string, a formatted message, aTextLinkinside a sentence),whyis"consequence","audience"or"recovery", andaboutnames the thing the line is about. Each slot renders the content withdata-whyanddata-about, and in development warns once when it is given anything else, which it still renders.ToastDescription,NotificationCenterItemBody,EmptyStateTitle,ListRowDescriptionand the status and data parts are unchanged. - 0.103.0 · Added
CardSubtitle: data about the card's subject under its title, whereCardDescriptionwould go (a handle, a time and place), inforegroundat the description's size (data-slot="card-subtitle"). - 0.10.0 · Breaking ChangesField frames (
Input,Textarea,InputGroup,Select,Combobox,ComboboxSelect,Composer, optionCard,SearchTrigger) are drawn at 1px inline-fieldinstead of 1.5px, on the phone too. - 0.3.0 · AddedAdded the composable
Cardcomponent withdefaultandinsetvariants and the finalCardHeader,CardLeading,CardTitle,CardDescription,CardTrailing,CardContent, andCardFooterparts.