跳转到内容
Nacre
组件配色
EN

卡片 Card

stableCard · SectionHeader在画廊运行
Card
在浏览器里运行真实组件。

把一块内容装进圆角框的唯一写法:tile 浮在 plane 灰底上,outline 放在白底上,muted 是浅灰嵌入块;区块标题 SectionHeader 卡片内外通用。

状态:stable · 组件:Card、SectionHeader

import { Card, SectionHeader } from 'nacre'

默认 outline、md:白底上的一块分组,SectionHeader 给标题与右侧操作。

import { Text } from 'nsh'
import { Button, Card, SectionHeader, TEXT_SIZE } from 'nacre'
export function CardUsage() {
return (
<Card testID="card-outline-md">
<SectionHeader title="服务小记" action={<Button size="sm" variant="outline">新建</Button>} />
<Text class={`${TEXT_SIZE.body} text-muted-foreground`}>客户咨询港股开户进度,已提醒补充地址证明,约定明天回访。</Text>
</Card>
)
}

xs 默认用 8 × 4 内边距和小圆角。outline 可按语气染底、在 secondary 上突出描边,或用 inverse 配主色前景。

手机:手机上 xs 留 8 × 4 内边距,outline 卡的圆角 12 与分组卡一致。

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`}>空闲</Text></Card>
<Card size="xs" tone="success" testID="card-success"><Text class={`${TEXT_SIZE.small} text-success-text`}>响铃中</Text></Card>
<Card size="xs" tone="success" surface="secondary"><Text class={`${TEXT_SIZE.small} text-foreground`}>已连接</Text></Card>
<Card size="xs" surface="inverse" testID="card-inverse"><Text class={`${TEXT_SIZE.small} text-primary-foreground`}>强调面</Text></Card>
</View>
)
}

看板、设置页的小卡:放在 bg-plane 上,无描边、带投影;它只在灰底上成立。

手机:手机页面本身就是 plane 灰底,tile 直接放在页面上,左右与其他内容同样留 16。

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="通知方式" hint="新消息到达时如何提醒" action={<Button size="sm" variant="ghost">编辑</Button>} />
<Text class={`${TEXT_SIZE.body} text-muted-foreground`}>声音提醒 · Dock 角标 · 系统通知</Text>
</Card>
</View>
<View class="grow basis-[240px]">
<Card variant="tile" size="sm" testID="card-tile-sm">
<SectionHeader title="排队中" extra={<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>3</Text>} />
<Text class={`${TEXT_SIZE.body} text-muted-foreground`}>最长等待 2 分 14 秒</Text>
</Card>
</View>
</View>
)
}

md 内边 21,sm 内边 13(右栏、窄栏);muted 是浅灰底的说明块,无描边无投影。

手机:手机上 md 内边 16、sm 内边 12;muted 是浅灰底的说明块,无描边无投影。

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="客户资料" hint={TOUCH ? 'md:内边 16' : 'md:内边 21'} />
<Text class={`${TEXT_SIZE.body} text-muted-foreground`}>林嘉怡 · 港股账户 · 已开户</Text>
</Card>
</View>
<View class="grow basis-[240px]">
<Card size="sm" testID="card-outline-sm">
<SectionHeader title="最近工单" hint={TOUCH ? 'sm:内边 12' : 'sm:右栏、记录详情'} />
<Text class={`${TEXT_SIZE.body} text-muted-foreground`}>T023 · 出金未到账 · 处理中</Text>
</Card>
</View>
<View class="grow basis-[240px]">
<Card variant="muted" size="sm" testID="card-muted">
<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>客户近 30 天没有来访记录。</Text>
</Card>
</View>
</View>
)
}

内容自带行内边距(折叠行、列表行)时用 flush,只留外框;classList 挂业务高亮,viewRef 拿节点做滚动到可见,onLayout 按卡宽排内容。

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 · 呼入 · 已接通</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`}>通话 3 分 12 秒,客户咨询出金到账时间。</Text>
</If>
</Card>
)
}

SectionHeader 的 hint、extra(计数)、icon、action;卡片外的设置分区也用它,字号字重不再各写各的。

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="个人设置" hint={TOUCH ? '卡片外的分区标题:16 semibold 标题 + 14 说明' : '卡片外的分区标题:13 semibold 标题 + 12 说明'} />
<Card size="sm">
<SectionHeader icon={<Icon name="bell" size={14} color="muted-foreground" />} title="新消息提示音" action={<Switch accessibilityLabel="新消息提示音" checked={sound()} onChange={(v) => sound.set(v)} />} />
<SectionHeader title="快捷回复" extra={<Text class={`${TEXT_SIZE.small} text-muted-foreground`}>12</Text>} action={<Button size="sm" variant="ghost">管理</Button>} />
</Card>
</View>
)
}
  • Card 默认是静态容器。需要标识分组时可给 accessibilityLabel,组内的按钮和列表行各自负责交互。
  • SectionHeader 的标题是普通文字,不是读屏标题层级。

该用

  • 折叠行、列表行装进卡时用 flush,不再手写 rounded-* border
  • tile 卡放在 plane 上
  • outline / muted 放在白底上
  • 窄栏、右栏用 size=“sm”
  • 区块标题统一用 SectionHeader(卡片内外同一个)

不该用

  • 手写 rounded-* bg-card border p-*
  • tile 直接放在白底上(投影不成立)
  • 卡片套卡片
属性 类型 默认 说明
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 —

* 必填

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

* 必填