安装与接入
GitHub Packages 配置、依赖安装、样式引入与 Tailwind 4 类名扫描
1. 配置 GitHub Packages
@mox-hub/ui 发布在 GitHub Packages(私有仓)。消费方项目根 .npmrc:
@mox-hub:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=<YOUR_GITHUB_PAT>PAT 需 read:packages 权限。
2. 安装
pnpm add @mox-hub/uipeer 依赖:react / react-dom(^17 || ^18 || ^19)与 @base-ui/react(^1.3)。
3. 引入样式(Tailwind 4)
@import 'tailwindcss';
@import '@mox-hub/ui/theme.css';
/* 类名扫描:让 Tailwind 看见包内的类名字面量 */
@source '../node_modules/@mox-hub/ui/dist';theme.css 提供:全套语义色/字阶/圆角/间距/动效 token(@theme)、base-ui data-* 自定义变体、:root/.dark 双主题基线、motion-* 动效 utilities。
4. 使用组件
import { Button } from '@mox-hub/ui'
export function Demo() {
return <Button variant="outline">打开</Button>
}5. 字体
库不捆绑字体。组件使用 --font-sans/--font-mono 链(默认 Inter + 思源黑体回落)。建议消费方自装 fontsource:
pnpm add @fontsource-variable/inter @fontsource-variable/jetbrains-mono @fontsource-variable/noto-sans-sc并在入口 css 顶部 @import 三件(禁 CDN,宪法 §2.2)。
6. 主题与语言(可选)
import { ThemeProvider, ThemeScript } from '@mox-hub/ui/theme'
import { I18nProvider } from '@mox-hub/ui/i18n'
<html lang="zh-CN" suppressHydrationWarning>
<head>
<ThemeScript theme={{ baseColor: 'zinc', radius: 'md' }} />
</head>
<body>
<ThemeProvider theme={{ baseColor: 'zinc', radius: 'md' }} defaultMode="system">
<I18nProvider locale="zh-CN">{children}</I18nProvider>
</ThemeProvider>
</body>
</html>不包 Provider 也能用:组件会回落内置 zh-CN 文案与默认主题。详见主题定制与 Foundations。