组件 · 布局
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
| Situation | Use |
|---|---|
| One subject on a page, with a title and its own content or controls | Card |
| A setting that turns a feature on, with its configuration under it | Card with variant="inset" |
| A choice among a few options in a form, where each option is a block | Card with variant="option", holding a Checkbox or a radio |
| A group of rows: settings, members, agents | ListRowGroup (ListRow) |
| Properties of one item, label and value | DescriptionList |
| A part of a large form | FormSection |
| A column of the main area | Panel |
| A task, a file on a message, a person on hover | TaskCard, 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: one line under the title, intext-calloutandforeground-muted. Optional.
CardContent: the body. Optional.CardFooter: a supporting note or a link, intext-captionandforeground-hint, with a hairline above it. Optional.
Variants
| Variant | Use 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 |
Content
- Write the title in sentence case: Release readiness (Writing).
- Write the description as one line on what the card is for or where it stands.
- Use the footer for a note about the whole card, such as where 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
| Prop | 类型 | 默认值 |
|---|---|---|
| "option" | "default" | "inset" | "default" | |
| Allows 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, CardDescription, CardFooter, CardHeader, CardLeading, CardTitle, CardTrailing
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows 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.
相关组件
改动
- 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.