Skip to content

CdsCard

A card gathers related content — a title, text, an image, actions — into one bordered block. Use it when an object (a product, a plan, a document) should read as a whole: a card can act as a link and as a selectable item in a group.

Storybook GitLab Figma
Test coverage: 100% — good coverage
API in specs
98 / 98 props, events, slots and exposed members with a test
Test cases
139 unit · 0 browser · 2 planned
Known bugs
8 pinned by an it.fails test
Code coverage
100% lines · 97.9% branches measured in v4.0.0-alpha.13
A11y (axe)
7 recommendations in 14 stories measured in v4.0.0-alpha.11

For uniform lists of rows use CdsList, for collapsible sections use CdsExpandablePanel, and when you only need a surface without any structure, use CdsSurface.

Anatomy ​

A card is assembled from ready-made blocks. The first diagram shows the frame: header, divider, text and the actions bar. The second one shows how the CdsCardItem header works: the prepend and append areas at the edges, the title and the subtitle in the middle. Every block is available as a prop, as a slot and as a separate component.

Variations ​

Content ​

There are three ways to fill a card: the title, subtitle and text props for typical cases; the slots of the same name when you need your own markup instead of a string; the CdsCardItem, CdsCardTitle, CdsCardSubtitle and CdsCardText components when you need full control over the structure. The divider prop adds a divider between the header and the text.

SlotDescription
title / subtitle / textReplace the props of the same name
prepend / appendContent at the edges of the header; replace *-icon and *-avatar
itemExtra header content below the title
defaultArbitrary card content
imageBackground image; replaces image
actionsActions bar — rendered inside CdsCardActions
loaderYour own loading indicator while loading is on

The prepend-icon and append-icon props put an icon at the edges of the header, prepend-avatar and append-avatar put an avatar by image URL. By default the prepend and append areas are pinned to the top of the header; item-align="center" centers them against the title and the subtitle (on CdsCardItem this prop is called align).

Appearance ​

A clickable card — one with a link, a click handler, inside a group or with the link prop — highlights its border on hover by itself, you do not need to turn anything on. borderless removes the border — for cards on a surface or inside other containers.

Pass href (or to with a vue-router route) and the card is rendered as an a tag and becomes clickable as a whole, keeping its appearance.

Images ​

An image at the top is a CdsImage component placed first inside the card. You can overlay content on top of it by putting the header into the image slot.

The image prop stretches the image as the background of the whole card. Take care of the contrast: set the text color through color and pick a dark image or a gradient.

Group with selection ​

Wrap the cards in CdsCardGroup and give each of them a value — the group turns into a selection control with v-model, and the selected card gets a highlighted border. required forbids clearing the selection.

The multiple prop enables multiple selection — v-model then holds an array of values.

Guidelines ​

Scenarios ​

Choosing a plan ​

A group of cards replaces radio buttons when every option needs room for a price and a description. The check-fill icon in append-icon repeats the selection in the header, and the button below stays disabled until an option is picked.

Product cards ​

A storefront is assembled from ready-made blocks: CdsImage with the photo, a rating made of icons in CdsCardText, CdsTag tags with the specs and a pair of actions in CdsCardActions — the main "add to cart" button and a secondary icon button for favorites that toggles the bookmark and tints it with a utility class. The loading and disabled props show the loading bar and protect the card from repeated clicks while the request runs — press «В корзину».

Expandable details ​

Hide secondary content behind an expander: a block with v-if is wrapped in CdsTransitionExpand for a smooth animation. Anything can trigger the expansion — a chevron icon or a button in the actions bar.

Cards nest into each other: the outer one is an album with a header and a counter, the inner ones are photo tiles in a mosaic built on a CSS grid with a fixed row height; col-span / row-span make individual shots larger. The absolute mode of CdsImage stretches the photo across the whole tile, borderless removes the borders, and a gradient darkens the last tile under the counter of the remaining photos.

API ​

CdsCard ​

Props

NameTypeDefaultDescription
activeColorstring | undefined—Color of the component in its active state
appendAvatarstring | undefined—Avatar shown after (to the right of) the content in the card header.
appendIconIconValue | undefined—Icon shown after (to the right of) the content in the card header.
baseColorstring | undefined—Color of the component in its inactive state
bgColorstring | undefined—Background color of the component
borderlessboolean | undefined—Removes the border of the card
colorstring | undefined—Component color
contentstring | number | undefined—Content displayed in the component.
disabledboolean | null | undefinednullDisabled state
dividerboolean | undefined—Adds a divider between the header and the content
exactboolean | undefined—If true, the active state applies only on an exact route match
heightstring | number | undefined—Component height
hrefstring | undefined—The href attribute of the link. When set, the component behaves as a regular link
imagestring | undefined—URL of the background image of the card.
itemAlign"start" | "end" | "center" | undefined—Alignment of the prepend / append areas against the header content. Passed to CdsCardItem as align.
linkboolean | undefined—Gives the card the styles and the behavior of a link.
loadingstring | boolean | undefined—Loading indicator for the component
locationAnchor | null | undefined—Position of the element relative to its container, for example "top left", "center", "bottom right".
maxHeightstring | number | undefined—Maximum component height
maxWidthstring | number | undefined—Maximum component width
minHeightstring | number | undefined—Minimum component height
minWidthstring | number | undefined—Minimum component width
position"absolute" | "static" | "fixed" | "relative" | "sticky" | undefined—CSS positioning of the component — the value of the position property
prependAvatarstring | undefined—Avatar shown before (to the left of) the content in the card header.
prependIconIconValue | undefined—Icon shown before (to the left of) the content in the card header.
replaceboolean | undefined—If true, navigation replaces the current history entry instead of pushing a new one
selectedClassstring | undefined—CSS class applied in the selected state
subtitlestring | number | boolean | undefined—Card subtitle. Rendered inside CdsCardItem below the title.
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render
textstring | number | undefined—Text displayed in the component.
textColorstring | undefined—Text color of the component
themestring | undefined—Component theme
titlestring | number | boolean | undefined—Card title. Rendered inside CdsCardItem above the subtitle.
toLinkTo | undefined—Target route or route location object for RouterLink. When set, the component behaves as a RouterLink
valueany—Value of the component within the group
widthstring | number | undefined—Component width

Slots

NameTypeDescription
actionsanyActions bar of the card
appendanyContent after the main content (in place of the append icon or avatar)
defaultanyDefault content inside the card
imageanyBackground image of the card
itemanyCustom rendering of the card item (CdsCardItem)
loaderLoaderSlotPropsSlot for a custom loading indicator, shown while the loading prop is true.
prependanyContent before the main content (in place of the prepend icon or avatar)
subtitleanySubtitle content
textanyMain text content of the card
titleanyTitle content

CdsCardActions ​

Props

NameTypeDefaultDescription
align"start" | "end" | "center" | undefined'start'Horizontal alignment of the action buttons
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render

Slots

NameTypeDescription
defaultanyCard actions, usually buttons

CdsCardDivider ​

Props

NameTypeDefaultDescription
colorstring | undefined—Color of the divider.
contentOffsetstring | number | (string | number)[] | undefined—Increases the spacing between the content and the lines. When passed as an array, the second value shifts the slot content down (or right when vertical = true).
gradientboolean | undefined—Adds a fade-out effect on both ends.
insetboolean | undefined—Adds an indent to horizontal dividers and reduces the maximum height of vertical ones.
lengthstring | number | undefined—Length of the divider. Defaults to pixels.
opacitystring | number | undefined—Opacity of the divider.
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render
themestring | undefined—Component theme
thicknessstring | number | undefined—Thickness of the divider. Defaults to pixels.
variant"solid" | "dotted" | "dashed" | "double" | undefined'solid'Visual variant of the divider
verticalboolean | undefined—Renders the divider vertically

Slots

NameTypeDescription
defaultanyContent of the card divider

CdsCardGroup ​

Props

NameTypeDefaultDescription
direction"horizontal" | "vertical" | undefined'horizontal'Switches the component between horizontal and vertical layout.
disabledboolean | null | undefinednullDisabled state
mandatoryboolean | "force" | undefined—Requires at least one item to stay selected
maxnumber | undefined—Maximum number of items that can be selected
modelValueany—Value of the selected items of the group
multipleboolean | undefined—Allows selecting several items at once
requiredboolean | "force" | undefined—Requires at least one item to stay selected
selectedClassstring | undefined'cds-card--selected'CSS class applied in the selected state
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render
themestring | undefined—Component theme

Slots

NameTypeDescription
defaultGroupProvideCards of the group. The slot props expose the group state (selection, navigation).

Exposed

NameTypeDescription
isSelected(id: string) => booleanChecks whether a card with the given id is selected
next() => voidSelects the next card
prev() => voidSelects the previous card
select(id: string, value: boolean) => voidSelects a card by its id
selectedreadonly string[]Identifiers of the selected cards

CdsCardItem ​

Props

NameTypeDefaultDescription
align"start" | "end" | "center" | undefined—Alignment of the prepend / append areas against the content.
appendAvatarstring | undefined—Avatar shown after (to the right of) the content.
appendIconIconValue | undefined—Icon shown after (to the right of) the content.
prependAvatarstring | undefined—Avatar shown before (to the left of) the content.
prependIconIconValue | undefined—Icon shown before (to the left of) the content.
subtitlestring | number | boolean | undefined—Subtitle of the card item.
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render
titlestring | number | boolean | undefined—Title of the card item.

Slots

NameTypeDescription
appendanyContent after the main content (in place of the append icon or avatar)
defaultanyDefault content inside the body of the card item
prependanyContent before the main content (in place of the prepend icon or avatar)
subtitleanySubtitle content
titleanyTitle content

CdsCardSubtitle ​

Props

NameTypeDefaultDescription
opacitystring | number | undefined—Opacity of the subtitle text.
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render

Slots

NameTypeDescription
defaultanyContent of the card subtitle

CdsCardText ​

Props

NameTypeDefaultDescription
opacitystring | number | undefined—Opacity of the card text.
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render

Slots

NameTypeDescription
defaultanyText content of the card

CdsCardTitle ​

Props

NameTypeDefaultDescription
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render

Slots

NameTypeDescription
defaultanyContent of the card title