# 🎨 主题变量快速参考卡 ## 常用替换速查表 ### 📦 背景色 | 用途 | 旧写法 | ✅ 新写法 | 说明 | |------|--------|----------|------| | 信息框/卡片 | `bg-gray-50` | `bg-muted` | 自动适配明暗 | | 信息框/卡片 | `bg-gray-100` | `bg-muted` | 自动适配明暗 | | 主背景 | `bg-white dark:bg-gray-900` | `bg-background` | 自动适配 | | 卡片背景 | `bg-white dark:bg-gray-800` | `bg-card` | 自动适配 | | 弹窗背景 | `bg-white dark:bg-gray-800` | `bg-popover` | 自动适配 | | 次要背景 | `bg-gray-100 dark:bg-gray-700` | `bg-secondary` | 自动适配 | | 强调背景 | `bg-gray-50 dark:bg-gray-700` | `bg-accent` | 自动适配 | ### 🖱️ 交互效果 | 用途 | 旧写法 | ✅ 新写法 | 说明 | |------|--------|----------|------| | 悬停高亮 | `hover:bg-gray-50` | `hover:bg-accent` | 轻微高亮 | | 悬停高亮 | `hover:bg-gray-100` | `hover:bg-accent` | 轻微高亮 | | 激活状态 | `active:bg-gray-200` | `active:bg-accent` | 按下效果 | ### 📝 文字颜色 | 用途 | 旧写法 | ✅ 新写法 | 说明 | |------|--------|----------|------| | 主文字 | `text-gray-900 dark:text-white` | `text-foreground` | 自动适配 | | 辅助文字 | `text-gray-600 dark:text-gray-400` | `text-muted-foreground` | 自动适配 | | 卡片文字 | `text-gray-900 dark:text-gray-100` | `text-card-foreground` | 自动适配 | | 主按钮文字 | `text-white dark:text-gray-900` | `text-primary-foreground` | 自动适配 | ### 🎨 状态色(保持不变) | 状态 | 类名 | 说明 | |------|------|------| | ✅ 成功/激活 | `bg-green-100 text-green-800` | 保持不变 | | ❌ 错误/危险 | `bg-red-100 text-red-800` | 保持不变 | | ⚠️ 告警 | `bg-orange-100 text-orange-800` | 保持不变 | | 💡 警告 | `bg-yellow-100 text-yellow-800` | 保持不变 | | ℹ️ 信息 | `bg-blue-100 text-blue-800` | 保持不变 | | ⚪ 离线/禁用 | `bg-gray-100 text-gray-800` | 保持不变 | | 💜 其他 | `bg-purple-100 text-purple-800` | 保持不变 | ### 🔲 边框 | 用途 | 旧写法 | ✅ 新写法 | 说明 | |------|--------|----------|------| | 普通边框 | `border-gray-200 dark:border-gray-700` | `border` | 自动适配 | | 输入框边框 | `border-gray-300 dark:border-gray-600` | `border-input` | 自动适配 | ### 📝 特殊组件 | 组件 | 旧写法 | ✅ 新写法 | 说明 | |------|--------|----------|------| | 代码块 | `bg-gray-100` | `bg-muted` | 自动适配 | | 字段值 | `field-value bg-gray-50` | `field-value` | 已含bg-muted | | 输入框 | `bg-gray-50 dark:bg-gray-800` | `bg-input-background` | 自动适配 | --- ## 🚫 禁止使用的写法 ```tsx ❌ className="bg-gray-50 dark:bg-gray-800" ❌ className="bg-white dark:bg-gray-900" ❌ className="text-gray-900 dark:text-white" ❌ className="hover:bg-gray-50 dark:hover:bg-gray-700" ❌ className="border-gray-200 dark:border-gray-700" ``` **原因:** 手动定义dark模式维护成本高,且不统一 --- ## ✅ 推荐使用的写法 ```tsx ✅ className="bg-muted" ✅ className="bg-background" ✅ className="text-foreground" ✅ className="hover:bg-accent" ✅ className="border" ``` **原因:** 自动适配明暗模式,统一主题管理 --- ## 📋 常见场景示例 ### 场景1:信息展示卡片 ```tsx // ❌ 旧写法
标题
描述
标题
描述
CODE-001
// ✅ 新写法
CODE-001
```
### 场景4:表单字段
```tsx
// ❌ 旧写法
描述文字