跳转到内容
Nacre
组件配色
EN

快速开始

在应用里引入组件、套主题、写第一个界面;以及改组件库要遵守的规则。

把 Nacre 仓库克隆到应用旁边,进入应用目录,将它加入依赖。组件按包名导入。

Terminal window
git clone https://github.com/Lemenxzy/nacre ../nacre
nsh add --path ../nacre
import { Button, Dialog, TextField } from 'nacre'

会话和电话组件分别从 nacre/chat 和 nacre/call 导入。

在应用的 nsh.json 中设置 "theme": "theme.json",再从应用目录生成主题。

Terminal window
node ../nacre/theme/theme-import.ts --app .
node ../nacre/theme/theme-import.ts --app . --check

颜色使用语义 token,例如 bg-background 和 text-muted-foreground。在应用的 themes/app.json 中可以覆盖品牌色。

import { View, signal } from 'nsh'
import { Button, Field, TextField } from 'nacre'
export function RemarkForm() {
const remark = signal('')
return (
<View class="gap-3">
<Field label="备注" required>
<TextField value={remark()} onChange={(v) => remark.set(v)} accessibilityLabel="备注" />
</Field>
<Button variant="primary" disabled={!remark().trim()}>保存</Button>
</View>
)
}

NSH 不是 React:组件函数只执行一次,之后靠 signal / computed / effect 更新;props 在 JSX 里写 props.x,解构会丢响应性。

  • 新组件先在画廊有示例与文档页(packages/ui/docs/pages/<key>.ts + <key>.examples.tsx),再写测试(packages/ui/example/tests/<key>.test.tsx,开头 // covers:)。
  • 改完跑:
Terminal window
node packages/ui/scripts/ui-exports.ts --check # 公开导出清单与测试覆盖
node packages/ui/scripts/ui-api.ts # API 表
node packages/ui/scripts/ui-docs.ts # 文档 Markdown 与 llms.txt
node packages/ui/scripts/ui-mcp.selftest.ts # MCP 服务器读到的数据完整
nsh test packages/ui/example/tests/<key>.test.tsx