Skip to content

第五章:视觉设计

定义视觉系统和品牌风格


5.1 设计令牌 (Design Tokens)

颜色系统

品牌色

css
/* 主色 - Bioforest Green */
--primary: oklch(0.6 0.13 163);
--primary-foreground: oklch(0.98 0.02 166);

/* 深色模式 */
.dark {
  --primary: oklch(0.7 0.15 162);
  --primary-foreground: oklch(0.26 0.05 173);
}

语义色

用途浅色模式深色模式使用场景
成功green-500green-400交易成功、验证通过
警告yellow-500yellow-400提醒、注意事项
错误red-500red-400错误提示、危险操作
信息blue-500blue-400一般提示

中性色

css
--background: oklch(1 0 0);           /* 页面背景 */
--foreground: oklch(0.145 0 0);       /* 主要文字 */
--muted: oklch(0.97 0 0);             /* 次级背景 */
--muted-foreground: oklch(0.556 0 0); /* 次级文字 */
--border: oklch(0.922 0 0);           /* 边框 */

字体系统

字体家族

字体CSS 类用途
DM Sansfont-sansUI 文本、按钮、标签(默认)
DM Monofont-mono地址、金额、代码
DM Serif Displayfont-serif协议、提示、正式内容

字体大小

级别大小行高使用场景
xs12px16px辅助信息、时间戳
sm14px20px次要文字、标签
base16px24px正文、按钮文字
lg18px28px小标题
xl20px28px页面标题
2xl24px32px金额显示
3xl30px36px大额数字

间距系统

css
/* 基于 4px 网格 */
--spacing-1: 4px;
--spacing-2: 8px;
--spacing-3: 12px;
--spacing-4: 16px;
--spacing-5: 20px;
--spacing-6: 24px;
--spacing-8: 32px;
--spacing-10: 40px;
--spacing-12: 48px;

使用规范

  • 组件内部间距:4px, 8px
  • 组件之间间距:16px, 24px
  • 区块之间间距:32px, 48px

圆角系统

用途大小使用场景
sm4px小按钮、标签
md8px输入框、卡片
lg12px大卡片、弹窗
xl16px底部弹窗
full9999px圆形按钮、头像

5.2 组件样式

按钮

变体

┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐
│   Primary       │  │   Secondary     │  │   Outline       │
│   主要操作      │  │   次要操作      │  │   边框按钮      │
└─────────────────┘  └─────────────────┘  └─────────────────┘

┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐
│   Ghost         │  │   Destructive   │  │   Link          │
│   幽灵按钮      │  │   危险操作      │  │   链接按钮      │
└─────────────────┘  └─────────────────┘  └─────────────────┘

尺寸

尺寸高度内边距字体大小
sm32px12px14px
md40px16px14px
lg48px20px16px

渐变按钮

css
.gradient-blue {
  background: linear-gradient(180deg, #6de7fe 0%, #44b5f7 100%);
}
.gradient-purple {
  background: linear-gradient(180deg, #a694f8 0%, #8970ff 100%);
}
.gradient-red {
  background: linear-gradient(180deg, #f77fa2 0%, #ea4879 100%);
}

卡片

钱包卡片

┌─────────────────────────────────────┐
│                                     │
│  ┌──┐  钱包名称                     │
│  │🔷│  0x71C7...976F    [复制]     │
│  └──┘                              │
│                                     │
│  ═══════════════════════════════   │
│                                     │
│    转账        铸造        收款     │
│                                     │
└─────────────────────────────────────┘

样式特点:

  • 圆角 16px
  • 阴影 shadow-md
  • 背景渐变或纯色

资产卡片

┌─────────────────────────────────────┐
│  ┌──┐                               │
│  │🔶│  ETH                    10.5 │
│  └──┘  Ethereum              $2,100│
└─────────────────────────────────────┘

输入框

默认状态

┌───────────────────────────────────┐
│ 请输入地址                         │
└───────────────────────────────────┘

聚焦状态

┌───────────────────────────────────┐
│ 0x71C7656EC7ab88b098defB751B...   │  ← 边框高亮
└───────────────────────────────────┘

错误状态

┌───────────────────────────────────┐
│ invalid_address                   │  ← 红色边框
└───────────────────────────────────┘
  ⚠️ 地址格式不正确                     ← 错误提示

底部弹窗

┌─────────────────────────────────────┐
│                                     │
│           (页面内容变暗)             │
│                                     │
├─────────────────────────────────────┤
│          ━━━━━━━━━━━                │  ← 拖动指示条
│                                     │
│  选择链                              │  ← 标题
│                                     │
│  ○ Ethereum                         │
│  ● BSC                              │  ← 当前选中
│  ○ Tron                             │
│  ○ BFMeta                           │
│                                     │
│  ┌───────────────────────────────┐ │
│  │          确定                  │ │  ← 操作按钮(可选)
│  └───────────────────────────────┘ │
│                                     │
└─────────────────────────────────────┘

5.3 图标系统

图标来源

使用 Tabler Icons,React 组件:@tabler/icons-react

常用图标

功能图标名称
返回IconArrowLeft
复制📋IconCopy
扫码📷IconScan
设置⚙️IconSettings
钱包💼IconWallet
发送↗️IconSend
接收↙️IconDownload
锁定🔒IconLock
警告⚠️IconAlertTriangle
成功IconCheck

图标尺寸

场景尺寸使用
按钮内图标16px小型按钮
列表项图标20px列表左侧图标
导航图标24pxTab Bar
状态图标48px空状态、结果页

5.4 深色模式

颜色映射

元素浅色模式深色模式
背景#ffffff#0a0a0a
前景#0a0a0a#fafafa
卡片#ffffff#171717
边框#e5e5e5#262626
次级文字#737373#a3a3a3

实现方式

css
@custom-variant dark (&:is(.dark *));

:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
}

.dark {
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
}

切换逻辑

  1. 默认跟随系统
  2. 用户可手动切换
  3. 存储用户偏好

5.5 响应式设计

断点定义

断点宽度设备
xs< 360px小型手机
sm360-414px标准手机
md414-600px大屏手机
lg600-840px折叠屏展开
xl> 840px平板

容器查询

组件使用容器查询实现自适应:

tsx
<div className="@container">
  <div className={cn(
    "flex flex-col gap-2",           // 默认:垂直布局
    "@xs:flex-row @xs:gap-4",        // >320px:水平布局
    "@md:p-6"                        // >448px:更大内边距
  )}>
    {/* 内容 */}
  </div>
</div>

5.6 动画规范

时长

类型时长使用场景
快速150mshover、focus
标准200ms展开、收起
中等300ms页面过渡
慢速500ms复杂动画

缓动函数

css
--ease-out: cubic-bezier(0, 0, 0.2, 1);
--ease-in: cubic-bezier(0.4, 0, 1, 1);
--ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

常用动画

淡入

css
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

滑入

css
@keyframes slide-in-from-bottom {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

本章小结

  • 设计令牌定义了颜色、字体、间距、圆角
  • 组件样式包括按钮、卡片、输入框、弹窗
  • 图标使用 Tabler Icons
  • 支持深色模式
  • 响应式设计使用容器查询
  • 动画规范保证一致的交互体验

下一章

继续阅读 第六章:设计原则,了解设计决策的指导原则。

Released under the MIT License.