Skip to content
Nacre
Color palette
中文

Card

stableCard · SectionHeaderOpen in playground
Card
Runs the real component in your browser.

The one way to put content in a rounded box: tile floats on the gray plane, outline sits on a white background, and muted is a light gray inset block; the SectionHeader section title works both inside and outside cards.

Status: stable · Components: Card, SectionHeader

import { Card, SectionHeader } from 'nacre'

Defaults to outline, md: a group on a white background, with SectionHeader for the title and trailing action.

import { Text } from 'nsh'
import { Button, Card, SectionHeader, TEXT_SIZE } from 'nacre'
export function CardUsage() {
return (
<Card testID="card-outline-md">
<SectionHeader title="Service Notes" action={<Button size="sm" variant="outline">New</Button>} />
<Text class={`${TEXT_SIZE.body} text-muted-foreground`}>Customer asked about their HK stock account opening; reminded them to add proof of address. Follow-up call set for tomorrow.</Text>
</Card>
)
}

The xs outline has smaller corners and 8 × 4 padding. Use a tinted fill, a secondary surface with a status border, or inverse with primary foreground content.

Phone: On phones xs keeps 8 × 4 padding, and outline cards use the same 12 radius as grouped cards.

import { Text, View } from 'nsh'
import { Card, TEXT_SIZE } from 'nacre'
export function CardSurfaces() {
return (
<View class="flex-row flex-wrap gap-2">
<Card size="xs" testID="card-xs"><Text class={`${TEXT_SIZE.small} text-foreground`}>Idle</Text></Card>
<Card size="xs" tone="success" testID="card-success"><Text class={`${TEXT_SIZE.small} text-success-text`}>Ringing</Text></Card>
<Card size="xs" tone="success" surface="secondary"><Text class={`${TEXT_SIZE.small} text-foreground`}>Connected</Text></Card>
<Card size="xs" surface="inverse" testID="card-inverse"><Text class={`${TEXT_SIZE.small} text-primary-foreground`}>Emphasized surface</Text></Card>
</View>
)
}

Small cards on dashboards and settings pages: placed on bg-plane, with no border and a shadow; it only works on the gray background.

Phone: On phones the page itself is the plane, so tiles sit directly on it with the same 16 side margin as other content.

import { Text, View } from 'nsh'
import { Button, Card, SectionHeader, TEXT_SIZE, TOUCH } from 'nacre'
export function CardTile() {
return (
<View class="flex-row flex-wrap" classList={{ 'gap-3 px-4': TOUCH, 'gap-[21px] p-[21px] rounded-xl bg-plane': !TOUCH }}>
<View class="grow basis-[240px]">
<Card variant="tile" testID="card-tile-md">
<SectionHeader title="Notifications" hint="How you’re alerted to new messages" action={<Button size="sm" variant="ghost">Edit</Button>} />
<Text class={`${TEXT_SIZE.body} text-muted-foreground`}>Sound · Dock badge · System notifications</Text>
</Card>
</View>
<View class="grow basis-[240px]">
<Card variant="tile" size="sm" testID="card-tile-sm">
<SectionHeader title="Queued" extra={<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>3</Text>} />
<Text class={`${TEXT_SIZE.body} text-muted-foreground`}>Longest wait 2 min 14 s</Text>
</Card>
</View>
</View>
)
}

md has 21 padding, sm has 13 (right panel, narrow columns); muted is an explanatory block on a light gray fill, with no border or shadow.

Phone: On phones md has 16 padding and sm 12; muted is a light gray note block with no border or shadow.

import { Text, View } from 'nsh'
import { Card, SectionHeader, TEXT_SIZE, TOUCH } from 'nacre'
export function CardSizes() {
return (
<View class="flex-row flex-wrap gap-[21px]">
<View class="grow basis-[240px]">
<Card>
<SectionHeader title="Customer info" hint={TOUCH ? 'md: 16 padding' : 'md: 21 padding'} />
<Text class={`${TEXT_SIZE.body} text-muted-foreground`}>Lin Jiayi · HK stock account · Opened</Text>
</Card>
</View>
<View class="grow basis-[240px]">
<Card size="sm" testID="card-outline-sm">
<SectionHeader title="Recent tickets" hint={TOUCH ? 'sm: 12 padding' : 'sm: right panel, record details'} />
<Text class={`${TEXT_SIZE.body} text-muted-foreground`}>T023 · Withdrawal not received · In progress</Text>
</Card>
</View>
<View class="grow basis-[240px]">
<Card variant="muted" size="sm" testID="card-muted">
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>No customer visits in the last 30 days.</Text>
</Card>
</View>
</View>
)
}

Use flush when the content brings its own row padding (disclosure rows, list rows), keeping only the frame; classList carries a business highlight, viewRef gets the node for reveal, and onLayout lays content out by card width.

import { Text, View, signal } from 'nsh'
import { Card, DisclosureRow, Icon, TEXT_SIZE } from 'nacre'
export function CardFlush() {
const open = signal(false)
return (
<Card size="sm" flush testID="card-flush" classList={{ 'bg-selected-tint': open() }}>
<DisclosureRow testID="card-flush-row" expanded={open()} onPress={() => open.set(!open())}>
<View class="flex-row items-center gap-1.5">
<Icon name={open() ? 'chevron-down' : 'chevron-right'} size={12} color="muted-foreground" />
<Text class={`flex-1 ${TEXT_SIZE.small} text-foreground`}>11-17 12:02 · Inbound · Answered</Text>
</View>
</DisclosureRow>
<If when={open()}>
{/* 展开的内容与标题文字左对齐(行内边距 10 + 箭头 12 + 间距 6 = 28),与标题行隔 4,底边距同行的上内边距 10:上下对称 */}
<Text class={`pl-7 pr-2.5 pt-1 pb-2.5 ${TEXT_SIZE.small} text-muted-foreground`}>Call 3 min 12 s; asked when a withdrawal arrives.</Text>
</If>
</Card>
)
}

SectionHeader’s hint, extra (a count), icon and action; settings sections outside cards use it too, so font size and weight aren’t written ad hoc.

import { Text, View, signal } from 'nsh'
import { Button, Card, Icon, SectionHeader, Switch, TEXT_SIZE, TOUCH } from 'nacre'
export function CardSectionHeader() {
const sound = signal(true)
return (
<View class="gap-4">
<SectionHeader title="Personal settings" hint={TOUCH ? 'Section title outside a card: 16 semibold title + 14 hint' : 'Section title outside a card: 13 semibold title + 12 hint'} />
<Card size="sm">
<SectionHeader icon={<Icon name="bell" size={14} color="muted-foreground" />} title="New message sound" action={<Switch accessibilityLabel="New message sound" checked={sound()} onChange={(v) => sound.set(v)} />} />
<SectionHeader title="Quick Reply" extra={<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>12</Text>} action={<Button size="sm" variant="ghost">Manage</Button>} />
</Card>
</View>
)
}
  • Card is a static container. Give it an accessibilityLabel when the group needs a name. Buttons and rows inside it own their interactions.
  • SectionHeader’s title is plain text, not a screen reader heading level.

Do

  • Use flush for cards holding disclosure or list rows instead of hand-writing rounded-* border
  • Put tile cards on the plane
  • Put outline / muted on a white background
  • Use size=“sm” in narrow columns and the right panel
  • Use SectionHeader for every section title (the same one inside and outside cards)

Don’t

  • Hand-write rounded-* bg-card border p-*
  • Put a tile directly on a white background (the shadow doesn’t work)
  • Nest cards in cards

Property descriptions follow the Chinese source comments.

Prop Type Default Description
variant CardVariant 'outline' tile:浮在 plane 灰底上的小卡(看板、设置),无描边、带投影、圆角 16; outline:直接放在白色内容卡里的卡(右栏、记录详情),1pt foreground/10 描边、无投影、圆角 14; muted:浅灰底的嵌入块(说明、空数据框),无描边无投影、圆角 10。
size CardSize 'md' md / sm 内边距在桌面为 21 / 13,手机为 16 / 12;xs 用于密集工具卡,内边距 8 × 4,outline 圆角收小
tone 'neutral' | 'success' 'neutral' outline 的描边与底色;success 标出需要关注的状态
surface 'default' | 'secondary' | 'inverse' 'default' outline 默认随语气染底,secondary 用中性底强调描边,inverse 用主色实底
accessibilityLabel string — 给有名称的分组(例如热线)标注读屏名,子控件保留各自的角色
gap number — 子元素之间的间距,默认 md 13、sm 8、xs 2,flush 时 0
flush boolean — 不加内边距:内容自带行内边距时用(折叠行 DisclosureRow、列表行、通栏分隔的行),只要外框、底色与圆角。 行要裁进圆角时再加 class="overflow-hidden"
class string —
classList Record<string, boolean | null | undefined> — 随状态切换的类,例如业务高亮 { 'bg-selected-tint': lit() }
viewRef (node: ViewRef) => void — 拿外框节点:滚动到可见(reveal)、量位置
onLayout (event: { bounds: Bounds }) => void — 外框尺寸变化:按卡宽决定内容排法(图表刻度、放不下时换下拉)
testID string —
children JSX.Element —

* required

Prop Type Default Description
title * string —
hint string — 标题下一行说明,12 muted
icon JSX.Element — 标题前的图标
extra JSX.Element — 标题后面紧跟的小字或徽标(条数)
action JSX.Element — 右侧操作(按钮、开关、状态),与标题行底对齐
testID string —

* required