Steps, conventions, and examples for writing styles for new components in a monorepo, describing how to use @vanilla-extract with centralized token management and best practices for implementing variant classes and low-specificity selectors.
新组件实践指南(中文)——创建样式
本文档记录了在本 monorepo 中新增 UI 组件的可复用流程,以 <component> 组件为示例。目标是形成一套可重复、可复用的惯例:样式通过类名控制、React 组件保持精简。
目标
@vanilla-extract(集中在 @idealjs/camphora-styled 包):颜色、尺寸、状态等变体以类的形式存在。className 与原生 HTML 属性,不增加过多自定义 props。前置准备
packages/camphora-styled/src/tokens 中新增或复用 token(颜色、尺寸、层级、字体等)。packages/camphora-styled/src/index.ts 导出新增的样式文件。本次示例涉及的文件
packages/camphora-styled/src/<component>.css.ts —— 基础样式与变体类(如 <componentPrimary>, <componentSm>)。可复用步骤(样式部分)
packages/camphora-styled/src/tokens 中新增或复用所需 token(颜色、尺寸、层级、排版)。@vanilla-extract/css 在 packages/camphora-styled/src/<component>.css.ts 中实现基础 <component> 样式。<component> 组合(例如使用 ${<component>}& 模式),保持选择器简洁且低优先级。selectors 对象中,使用 ${baseClass}& 来表示当元素同时具有基础类和当前变体类时应用样式。这利用了 vanilla-extract 的 & 占位符,代表当前类的名称。避免直接嵌套选择器,因为 vanilla-extract 不支持 Sass 风格的嵌套。为什么优先用类名?
注意与约定
selectors 与 ${base}& 的组合模式。记录时间:2026-01-10
npx skills add idealjs/create-component-style下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer