suiss/ui · Component
Card
A raised container that groups related content and actions about a single subject.
Card is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
A Card stacks a CardHeader, CardContent and CardFooter with consistent spacing. The header holds a CardTitle, an optional CardDescription, and an optional CardAction that sits in the top-end corner. An img placed as the first child runs edge to edge, with rounded top corners and no top padding.
Use a card to present a self-contained summary, such as a plan, a metric or a place. For dense lists of rows, use Item or a table instead.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
-
Add the
cnhelper. -
Copy and paste the following code into your project.
- Update the import paths to match your project setup.
Usage
Composition
Use the following composition to build a Card:
Examples
Small
Set size="sm" for tighter spacing.
Filled
Set variant="filled" for a flat bg-muted surface with no shadow.
With action
Place an icon button in the header with CardAction. The header switches to a two-column grid and puts the action in the top-end corner.
With borders
Add border-b to CardHeader or border-t to CardFooter to draw a divider; the card adds matching padding on that side.
With image
Place an img as the first child of the card to run it edge to edge above the header, with rounded top corners and no top padding.
Accessibility
- Card parts are non-semantic
divelements, andCardTitleis not a heading. If the title belongs in the document outline, place a heading element such ash2inside it. - Icon-only buttons in
CardActionneed anaria-label.
API Reference
Card
The rounded container that sets size and surface.
| Prop | Type | Default |
|---|---|---|
size | "default" | "sm" | "default" |
variant | "default" | "filled" | "default" |
Also accepts the props of React.ComponentProps<"div">.
The default variant is raised with a shadow and ring; filled uses bg-muted with no shadow. Spacing comes from the --card-spacing custom property, which the sm size reduces. All parts are plain div elements, so you can omit any of them.
CardHeader
Lays out the title, description and action.
Also accepts the props of React.ComponentProps<"div">.
CardTitle
The card's heading text.
Also accepts the props of React.ComponentProps<"div">.
CardDescription
Secondary text below the title.
Also accepts the props of React.ComponentProps<"div">.
CardAction
A slot in the header's top-end corner for a button or menu.
Also accepts the props of React.ComponentProps<"div">.
CardContent
The main body, padded to the card's spacing.
Also accepts the props of React.ComponentProps<"div">.
CardFooter
A row for actions or summary at the bottom.
Also accepts the props of React.ComponentProps<"div">.
Each part sets a data-slot, such as card-header or card-content, for styling, and the root also sets data-size and data-variant. Calendar detects data-slot="card-content" and drops its own background inside a card.
Web preview
Card is a rounded View that stacks a CardHeader, CardContent and CardFooter with consistent spacing. The default variant is a raised surface with a hairline border and a shadow; the filled variant is a flat bg-muted surface.
The sm size reduces the padding and gaps for dense layouts. All parts read the size from context, so their horizontal padding stays aligned.
Installation
The CLI also adds what it builds on: Text.
- Install the following dependencies:
-
Add the pieces it builds on: Text.
-
Copy and paste the following code into
components/ui/card.tsx:
- Update the import paths to match your project setup.
- Install the following dependencies:
-
Add the pieces it builds on: Text.
-
Copy and paste the following code into
components/ui/card.tsx:
- Update the import paths to match your project setup.
-
Add the pieces it builds on: Text.
-
Copy and paste the following code into
components/ui/card.tsx:
- Update the import paths to match your project setup.
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Examples
Small
The compact sm size.
Web preview
With action
Add a CardAction anywhere in the header and it is placed in the top-end corner beside the title.
Web preview
With image
An edge-to-edge image above the header.
To show an image edge to edge, place it directly in the card before the header and add pt-0 to the card; only the header, content and footer are padded horizontally.
Web preview
Filled
The flat filled variant.
Web preview
Accessibility
CardTitlehas theheadingrole.- The card itself adds no role; actions inside provide their own.
API Reference
Card
Outer container that sets the size and variant.
| Prop | Type | Default |
|---|---|---|
size | CardSize | "default" |
variant | CardVariant | "default" |
Also accepts the props of React.ComponentProps<typeof View>, React.RefAttributes<View>.
size is "default" or "sm", and variant is "default" (raised) or "filled". The filled variant uses bg-muted without the shadow, and the border is stronger in dark mode. Colors follow the system appearance.
CardHeader
Title area; places a CardAction beside the text.
Also accepts the props of React.ComponentProps<typeof View>, React.RefAttributes<View>.
Put a CardTitle and CardDescription in it.
CardTitle
Bold heading.
Also accepts the props of Text.
CardDescription
Secondary text below the title.
Also accepts the props of Text.
CardAction
Slot for a button in the header.
Also accepts the props of React.ComponentProps<typeof View>, React.RefAttributes<View>.
CardContent
Padded body.
Also accepts the props of React.ComponentProps<typeof View>, React.RefAttributes<View>.
CardFooter
Padded row for actions.
Also accepts the props of React.ComponentProps<typeof View>, React.RefAttributes<View>.
Card
Outer container that sets the size and variant.
| Parameter | Type | Default |
|---|---|---|
_ variant | Variant: .default | .filled | .default |
size | Size: .default | .sm | .default |
content | () -> Content | - |
CardHeader
Title area; places a CardAction beside the text.
| Parameter | Type | Default |
|---|---|---|
_ title | LocalizedStringKey | - |
description | LocalizedStringKey? | nil |
action | () -> Action | - |
Overloads: init(_:description:action:), init(_:description:).
CardTitle
Bold heading.
| Parameter | Type | Default |
|---|---|---|
_ title | LocalizedStringKey | - |
CardDescription
Secondary text below the title.
| Parameter | Type | Default |
|---|---|---|
_ text | LocalizedStringKey | - |
CardContent
Padded body.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
CardFooter
Padded row for actions.
| Parameter | Type | Default |
|---|---|---|
content | () -> Content | - |
CardVariant
Values: Default, Filled.
CardSize
Values: Default, Sm.
Card
Outer container that sets the size and variant.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
variant | CardVariant: Default | Filled | CardVariant.Default |
size | CardSize: Default | Sm | CardSize.Default |
content | @Composable ColumnScope.() -> Unit | - |
CardHeader
Title area; places a CardAction beside the text.
| Parameter | Type | Default |
|---|---|---|
title | String | - |
modifier | Modifier | Modifier |
description | String? | null |
action | (@Composable () -> Unit)? | null |
CardTitle
Bold heading.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
CardDescription
Secondary text below the title.
| Parameter | Type | Default |
|---|---|---|
text | String | - |
modifier | Modifier | Modifier |
CardContent
Padded body.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable ColumnScope.() -> Unit | - |
CardFooter
Padded row for actions.
| Parameter | Type | Default |
|---|---|---|
modifier | Modifier | Modifier |
content | @Composable RowScope.() -> Unit | - |