组件规范
components 分组将具体的 UI 组件名称映射到一组样式属性,并直接引用前文定义的颜色、字体、圆角与间距 Token。
组件属性
DESIGN.md 规范为每个组件条目定义了以下样式属性:
| 属性名 | 合法值类型 |
|---|---|
backgroundColor | 颜色字面量或 {colors.*} 引用 |
textColor | 颜色字面量或 {colors.*} 引用 |
typography | 组合字体 Token 引用(如 {typography.label-md}) |
rounded | 尺寸字面量或 {rounded.*} 引用 |
padding | 尺寸字面量或 {spacing.*} 引用 |
size | 尺寸字面量或 {spacing.*} 引用 |
height | 尺寸字面量或 {spacing.*} 引用 |
width | 尺寸字面量或 {spacing.*} 引用 |
components:
button-primary:
backgroundColor: "{colors.primary}"
textColor: "{colors.on-primary}"
typography: "{typography.label-md}"
rounded: "{rounded.md}"
padding: 12px与顶层 Token 分组不同,components 内部允许引用 {typography.*} 这类组合对象。
用并列条目表达交互状态
hover、active、focus、disabled 等状态应写成并列兄弟键,不要在组件对象内部继续嵌套子对象:
components:
button-primary:
backgroundColor: "{colors.primary}"
textColor: "{colors.on-primary}"
rounded: "{rounded.md}"
padding: 12px
button-primary-hover:
backgroundColor: "#3730a3"
textColor: "{colors.on-primary}"
rounded: "{rounded.md}"
padding: 12px
button-primary-disabled:
backgroundColor: "{colors.surface}"
textColor: "{colors.text-muted}"
rounded: "{rounded.md}"
padding: 12px扁平命名能让符号表路径(如 components.button-primary-hover.backgroundColor)保持一致,并顺利导出给各类 Agent 与代码生成器。
哪些内容应该写在散文里
边框样式、阴影层级、内部弹性布局间距(gap)、图标对齐和响应式堆叠规则不属于 YAML components 的属性集合,应当放在正文 ## Components 章节中说明:
## Components
- **Primary button (`button-primary`):** 最小宽度 `96px`,保留 `1px` 透明边框以在并排次级按钮时避免高度抖动,图标与文案间距 `8px`。
- **Card surface (`card-surface`):** 桌面端使用 `1px solid` `{colors.border}` 细线描边,不使用大面积投影。引用外部模板文件
组件说明中可以用行内代码引用仓库里的 HTML 或组件模板文件:
@components/button.html@components/card.html#card-elevated
路径相对于当前 DESIGN.md 所在目录解析。
组件级 WCAG 对比度检查
在 DesignMD Pro 在线校验器中,工具会自动检查每个组件内的前景色属性(color、text、textColor、foreground)与背景色属性(background、backgroundColor、bg、surface、fill)之间的对比度:
- 对比度
< 3:1→ 错误(low-contrast) - 对比度
3:1至4.49:1→ 警告(low-contrast) - 对比度
>= 4.5:1→ 通过常规文本 WCAG AA 要求
例如上方 button-primary-disabled 使用 {colors.text-muted} 搭配 {colors.surface} 时,即可在校验器里即时确认文字可读性。
下一步
- 散文章节 —— 编写
## Components与其余标准章节 - 完整示例 —— 查看可直接复制通过校验的完整范例
- 校验器与 Lint 规则 —— 查看全部错误码与对比度匹配规则
Last updated on