跳转到内容

Card 卡片 ​

用于组织相关内容与操作的中性表面。

用法 ​

Header 放标题与说明,Content 放主体

本月账单

账期 7 月 1 日至 7 月 31 日

共 128 笔支出,合计 3,240.00 元。

组件结构 ​

加粗的是必需部件。

data-scope="card":root · header · title · description · content · footer

示例 ​

变体 ​

outline 为默认卡面,subtle 淡底嵌入,ghost 用于嵌套

outline

一段用来看表面层级的正文。

subtle

一段用来看表面层级的正文。

ghost

一段用来看表面层级的正文。

横向布局 ​

Card 只提供内容面,方向和媒体尺寸由使用场景决定

七月总结

收入与支出趋势已生成

更新于今天 09:30

带媒体 ​

图片或自绘媒体作为普通子节点放入,由内容自己决定比例与圆角

七月总结

媒体与文字共享卡片的统一节奏

本月共完成 18 个里程碑。

设计指引 ​

何时使用 ​

  • 把一组相关信息收成一个可以整体感知的单元。
  • 内容块之间需要视觉边界。

何时不用 ​

  • 页面上每一块都使用卡片会使边界失效。
  • 只需要一条分隔时,使用分隔线。

特性 ​

  • root 必需;header、title、description、content、footer 按内容组合。
  • outline 是默认卡面,subtle 用淡底嵌在别的面里,ghost 用于嵌套内容不再画面。
  • 根统一提供 16px 内边距、12px 段间距和 surface 圆角;横向布局与媒体比例由使用场景决定。

组合 ​

最佳实践 ​

  • 整卡可点时提供明显的悬停与聚焦反馈,并让整卡进入 Tab 序列。
  • 同组卡片保持相同宽度和内容节奏。

反模式 ​

  • 卡片嵌套卡片,两层边界互相削弱。
  • 整卡可点的同时卡内还有其他按钮,点击结果不可预期。

API 参考 ​

产物 ​

层值
自定义元素<xh-card>
Vue 组件XhCardContent XhCardDescription XhCardFooter XhCardHeader XhCardRoot XhCardTitle
状态机无,connect 直接由 props 算属性
皮肤@xihan-ui/styles/card.css

Props ​

属性类型必填说明
variantControlVariant形态:outline 为带影的抬起面,subtle 为淡底,ghost 无底无影。默认 outline。

connect API ​

getXxxProps() 返回对应部件的宿主属性。

成员类型说明
getRootProps() => T['element']
getHeaderProps() => T['element']
getTitleProps() => T['element']
getDescriptionProps() => T['element']
getContentProps() => T['element']
getFooterProps() => T['element']

无障碍 ​

键盘 ​

规格出处:W3C APG

无键盘交互(不接收焦点,或焦点行为完全由原生元素提供)。

样式参考 ​

皮肤 ​

@xihan-ui/styles/card.css 使用 [data-scope="card"][data-part="root"] 部件选择器,位于 xihan.components 层。覆盖样式使用 xihan.overrides。

forced-colors: active 下另有一套规则:颜色交给系统,边框与状态标记改用系统色关键字。

CSS 变量 ​

本组件公开覆盖槽由独立皮肤的实际消费位生成;默认来源、作用部件和状态均与 CSS 同源。

变量部件CSS 属性状态默认来源说明
--xh-card-bgrootbackgrounddefault
variant=subtle
--xh-bg-subtle
--xh-bg-surface
card 的 root 部件 background 覆盖槽。
--xh-card-borderrootborderdefault--xh-border-defaultcard 的 root 部件 border 覆盖槽。
--xh-card-content-gapcontentgapdefault--xh-space-1card 的 content 部件 gap 覆盖槽。
--xh-card-description-fgdescriptioncolordefault--xh-fg-mutedcard 的 description 部件 color 覆盖槽。
--xh-card-description-font-sizedescriptionfont-sizedefault--xh-text-secondary-sizecard 的 description 部件 font-size 覆盖槽。
--xh-card-description-leadingdescriptionline-heightdefault--xh-leading-normalcard 的 description 部件 line-height 覆盖槽。
--xh-card-fgrootcolordefault--xh-fg-defaultcard 的 root 部件 color 覆盖槽。
--xh-card-font-sizerootfont-sizedefault--xh-text-label-sizecard 的 root 部件 font-size 覆盖槽。
--xh-card-footer-gapfootergapdefault--xh-space-2card 的 footer 部件 gap 覆盖槽。
--xh-card-gaprootgapdefault--xh-space-3card 的 root 部件 gap 覆盖槽。
--xh-card-leadingrootline-heightdefault--xh-text-body-leadingcard 的 root 部件 line-height 覆盖槽。
--xh-card-prootpaddingdefault--xh-surface-pad-lgcard 的 root 部件 padding 覆盖槽。
--xh-card-radiusrootborder-radiusdefault--xh-shape-surfacecard 的 root 部件 border-radius 覆盖槽。
--xh-card-shadowrootbox-shadowdefault
variant=ghost
variant=subtle
--xh-elevation-raised
none
card 的 root 部件 box-shadow 覆盖槽。
--xh-card-title-fgtitlecolordefault--xh-fg-defaultcard 的 title 部件 color 覆盖槽。
--xh-card-title-font-sizetitlefont-sizedefault--xh-text-label-sizecard 的 title 部件 font-size 覆盖槽。
--xh-card-title-font-weighttitlefont-weightdefault--xh-font-weight-semiboldcard 的 title 部件 font-weight 覆盖槽。
--xh-card-title-leadingtitleline-heightdefault--xh-leading-relaxedcard 的 title 部件 line-height 覆盖槽。

动效 ​

本组件皮肤不含过渡与关键帧,也没有脚本驱动的动效:状态一变,外观立即到位。

Released under The MIT License