Components / Structure
Card
A content container. Give it href or onClick and the whole card becomes one link or one button. For a plain grouping with no surface, use Stack.
When to useLink to "When to use"
surface(default): a raised panel for settings sections, dashboard tiles, plan options.outline: border only, for lower emphasis or crowded layouts.soft: a tone-tinted fill to highlight a state (info, warning).href/onClick: the whole card is one target, such as a plan picker or a list of destinations.
Use something else when:
- the card holds its own buttons, links or inputs: use a static Card (no
href/onClick) and put those controls inside - you only need spacing between items: Stack or Inline
UsageLink to "Usage"
import { Card } from "@arshad-shah/cynosure";
<Card variant="outline" padding="lg" as="section">…</Card>
<Card href="/settings">Whole card is one link</Card>
<Card onClick={choose}>Whole card is one button</Card>
<Card variant="soft" tone="info">Heads up</Card>
<Card edge="success">Water the garden <Badge tone="success">Home</Badge></Card>
<Card as="section" title="Connection" description="Where the client connects.">…</Card>Title and descriptionLink to "Title and description"
title and description put a header above the content; headingLevel (default 3) fits the title into the page outline. In a static or link card the title is a heading, and a section, article or aside card is named by it. A button may not hold a heading, so in a button card the title is plain text that still names the button.
With actions the header shares its row with them: the title wraps before the actions instead of running under them, on static cards and on link and button cards, where the actions stay outside the card's one target.
PaddingLink to "Padding"
padding is none, sm, md (default) or lg, and uses space tokens.
Coloured edgeLink to "Coloured edge"
edge draws a coloured edge on the card's inline-start side: the left in left-to-right text, the right in right-to-left. A tone name (accent, neutral, danger, success, warning, info) uses that tone's colour. Any other string is a CSS colour, for categories with their own colours.
The edge is the card's own start border, so it follows the card's radius, and the content starts after it. It works with every variant and tone, on link and button cards and with actions, and it keeps its colour when the card is hovered or focused.
Colour must not be the only carrier of meaning. Some people cannot tell the colours apart and a screen reader does not announce them. Say the same thing in the card's text or with a Badge, as the cards above do.
Interactive cardsLink to "Interactive cards"
With href the card renders as a link; unsafe URL schemes are not linked. With onClick it renders as a button and supports disabled. Keep the content non-interactive: one card, one target. When a card is interactive, as is ignored.
PropsLink to "Props"
| Prop | What it does | Type | Default |
|---|---|---|---|
variant | surface raised panel, outline border only, soft tone-tinted fill. | "soft" | "outline" | "surface" | |
padding | Space between the card's edge and its content. Default "md". | "sm" | "md" | "lg" | "none" | "md" |
tone | Semantic colour. Default "neutral". | Tone | "neutral" |
edge | A coloured edge on the card's inline-start side (left in left-to-right text), e.g. a task's category. A tone name uses that tone's colour; any other string is a CSS colour. Colour alone carries no meaning for many people: say the same thing in the card's text or a Badge. Default: no edge. | Edge | no edge |
title | A heading at the top of the card, above the content, beside the actions. In a static or link card it is a heading (headingLevel); in a button card it is plain text, as a button may not hold a heading. A section, article or aside card is named by it. | ReactNode | |
description | A quieter line under the title. | ReactNode | |
headingLevel | Heading level of the title, to fit the page outline. Default 3. | 2 | 3 | 4 | 5 | 6 | 1 | 3 |
as | Element for a static card. Ignored when href or onClick makes the whole card interactive. | "div" | "section" | "article" | "li" | "aside" | |
href | Makes the whole card a link (rendered through LinkBase, so unsafe schemes are not linked). | string | |
target | With href: where it opens, e.g. _blank. | string | |
onClick | Makes the whole card a button. | MouseEventHandler<HTMLElement> | |
disabled | With onClick (and no href): the card cannot be pressed. | boolean | |
actions | Buttons that sit on the card but act on their own (a game card's 2-player mode, a file card's menu). They are placed over the card's top end, outside its one link or button, so nothing interactive is nested. | ReactNode | |
className | Added to the card element, for layout. | string | |
style | Layout only. | CSSProperties | |
children | The card's content. Keep it non-interactive when the card is a link or a button. | ReactNode | |
aria-label | Accessible name of the card, set on the card element. | string | |
aria-current | Marks a link or button card as the current one of a set: "page" for the page being shown (a card grid of sections), or "step", "location", true. Read by screen readers, and the card's border takes the accent. | boolean | "false" | "true" | "page" | "step" | "location" | "date" | "time" | |
data-testid | Set on the card element, to find it in tests. | string |
Generated from the type definitions in @arshad-shah/cynosure 0.5.0.
Behaviour and accessibilityLink to "Behaviour and accessibility"
| Input | Result |
|---|---|
| Click, Enter | Follows the link (href) or fires onClick |
| Space | Fires onClick on a button card |
| Tab | Moves focus to an interactive card |
- Static cards: choose the element with
as(div,section,article,li,aside). - Names: a
section,articleorasidecard with atitleis named by it. Otherwise addaria-labelwhen the card's content doesn't give a clear name. - Ref: the ref points at the rendered element.
- Edge:
edgeis visual only and adds no element or name. In forced colours it stays as a thicker edge in the system text colour.
ThemingLink to "Theming"
Tokens: --cy-card-bg, --cy-card-border, --cy-card-radius, --cy-card-shadow and --cy-card-soft-mix.
| Token | Controls |
|---|---|
--cy-card-edge-width | Thickness of the edge. Default --cy-space-2. |
--cy-card-title-size | Font size of the title. Default --cy-font-size-lg. |
createTheme({ components: { card: { radius: "12px", shadow: "none", edgeWidth: "6px" } } });className and style are for layout only.
RelatedLink to "Related"
These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.