For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/guide/colors.md.

颜色

五个语义色各生成 7 档派生色,中性色保留 9 档色阶,浅色与深色模式共用。

全局颜色变量

每组展示独立保留的基色及其派生色带。五个语义色共 35 个派生色块,加上中性色的 9 档共 44 个。点击色块查看色值与 CSS 变量。

主题色

基色 #007aff--leaf-color-primary
--leaf-color-primary-light-3rgba(77, 162, 255, 1)

成功色

基色 #4bb418--leaf-color-success
--leaf-color-success-light-3rgba(129, 203, 93, 1)

危险色

基色 #ff4d4f--leaf-color-danger
--leaf-color-danger-light-3rgba(255, 130, 132, 1)

警告色

基色 #e69f12--leaf-color-warning
--leaf-color-warning-light-3rgba(238, 188, 89, 1)

信息色

基色 #1677ff--leaf-color-info
--leaf-color-info-light-3rgba(92, 160, 255, 1)

中性色

基色 #707070--leaf-color-neutral
--leaf-color-neutral-500#8c8c8c

修改基色

通过 ConfigProvider 的 theme.primaryColor 修改主题基色,其他五组通过 theme.tokens 修改。更新这些 JS 配置即可重新生成色阶;修改 DOM 样式不会触发 JS 主题重算。

示例固定为浅色外观,并把 tokens.mutedSurfaceColor 设为 rgb(244,243,239)。分层 Card 的外层画布使用这份底板,卡片内部内容与净白控件仍使用内容表面;组件显式覆盖优先。

所有 on*Color 默认白色,需要黑字时将对应字段设为 #000000。请根据实际背景选择合适的字色。

主题色
成功色
危险色
警告色
信息色
中性色
共享底板
成功色危险色警告色信息色

共享底板

选中的高亮与内嵌内容仍基于内容表面。
colors.tsx
import { Button, Card, ColorPicker, ConfigProvider, Flex, Tabs, Tag } from '@ifhover/leaf-ui';
import { useState } from 'react';

const colorOptions = [
  ['primary', '主题色'],
  ['success', '成功色'],
  ['danger', '危险色'],
  ['warning', '警告色'],
  ['info', '信息色'],
  ['neutral', '中性色'],
  ['mutedSurface', '共享底板'],
] as const;

export function ThemeColors() {
  const [colors, setColors] = useState({
    primary: '#007aff',
    success: '#4bb418',
    danger: '#ff4d4f',
    warning: '#e69f12',
    info: '#1677ff',
    neutral: '#707070',
    mutedSurface: 'rgb(244,243,239)',
  });
  const [blackText, setBlackText] = useState(false);
  const foreground = blackText ? '#000000' : '#ffffff';
  return (
    <ConfigProvider
      theme={{
        primaryColor: colors.primary,
        appearance: 'light',
        tokens: {
          successColor: colors.success,
          dangerColor: colors.danger,
          warningColor: colors.warning,
          infoColor: colors.info,
          neutralColor: colors.neutral,
          mutedSurfaceColor: colors.mutedSurface,
          onPrimaryColor: foreground,
          onSuccessColor: foreground,
          onDangerColor: foreground,
          onWarningColor: foreground,
          onInfoColor: foreground,
        },
      }}
    >
      <Flex direction="column" gap={16}>
        <Flex wrap gap={12}>
          {colorOptions.map(([name, label]) => (
            <Flex key={name} direction="column" gap={4}>
              <span>{label}</span>
              <ColorPicker
                aria-label={label}
                value={colors[name]}
                disableAlpha
                showText
                onChange={(value) => setColors((previous) => ({ ...previous, [name]: value }))}
              />
            </Flex>
          ))}
        </Flex>
        <Flex wrap gap={8}>
          <Button variant="solid">保存</Button>
          <Tag color="success" variant="soft">
            成功色
          </Tag>
          <Tag color="danger" variant="soft">
            危险色
          </Tag>
          <Tag color="warning" variant="soft">
            警告色
          </Tag>
          <Tag color="info" variant="soft">
            信息色
          </Tag>
        </Flex>
        <Button onClick={() => setBlackText(!blackText)}>
          {blackText ? '改为白字' : '改为黑字'}
        </Button>
        <Card
          variant="layered"
          size="sm"
          title="共享底板"
          description="分层 Card 的外层画布使用 mutedSurfaceColor。"
        >
          <Tabs
            type="segmented"
            size="sm"
            block
            aria-label="表面层级"
            items={[
              {
                key: 'surface',
                label: '内容表面',
                children: '选中的高亮与内嵌内容仍基于内容表面。',
              },
              {
                key: 'muted',
                label: '共享底板',
                children: '外层分层画布使用 mutedSurfaceColor,不覆盖净白轨道。',
              },
            ]}
          />
        </Card>
      </Flex>
    </ConfigProvider>
  );
}