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/api/theme-tokens.md.

主题变量

日常定制优先设置 ConfigProvider 的 theme.primaryColor、theme.borderRadius 和 theme.controlHeight,其他样式会自动派生,见定制主题。

LeafThemeTokens

需要单独调整某个派生值时,再通过 theme.tokens 覆盖。所有字段均可选,嵌套区域继承未设置的字段。长度为数字时按 px 处理,动效时长为数字时按 ms 处理。

属性类型默认值说明
onPrimaryColorstring按主题生成主题背景上的文字色;默认自动选择可读的黑色或白色
dangerColorstring按外观生成危险色 / 危险背景上的文字色
onDangerColorstring按外观生成危险色 / 危险背景上的文字色
successColorstring按外观生成成功 / 警告 / 信息颜色
warningColorstring按外观生成成功 / 警告 / 信息颜色
infoColorstring按外观生成成功 / 警告 / 信息颜色
textColorstring按外观生成主要 / 次要文字
mutedTextColorstring按外观生成主要 / 次要文字
subtleTextColorstring—更轻的辅助文字色。
surfaceColorstring按外观生成表面 / 次级表面
mutedSurfaceColorstring按外观生成表面 / 次级表面
raisedSurfaceColorstring—浮层与抬升表面色。
borderColorstring按外观生成全局外框色;显式设置时统一覆盖实色控件和弱描边外框,组件级覆盖优先。
borderHoverColorstring—悬停时的中性边框色。
dividerColorstring—分区分隔线颜色;默认从边框和表面颜色派生。
borderWidthnumber | string—控件、内容表面和浮层的边框宽度;数字为 px。
controlShadowstring—可交互控件的默认阴影。
surfaceShadowstring—内容表面与浮层的默认阴影;未设置时保留组件的分层阴影。
borderRadiusSmnumber | string基础圆角 × 0.6单独覆盖小 / 大圆角
borderRadiusMdnumber | string基础圆角 × 1.2单独覆盖卡片、提示等内容表面的中圆角
borderRadiusLgnumber | string基础圆角 × 1.6单独覆盖大圆角
controlHeightSmnumber | string基础高度 − 6px,最小 1px单独覆盖小尺寸控件高度
controlHeightLgnumber | string基础高度 + 6px单独覆盖大尺寸控件高度
fontSizeSmnumber | string基础字号 − 1px单独覆盖小 / 大字号
fontSizeLgnumber | string基础字号 + 2px单独覆盖大字号
fontWeightnumber500按钮、标签与组件标题的强调字重
motionDurationnumber | string200基础过渡时间;数字为 ms,也支持 CSS 时间。motion=false 时为 0。
motionEasingstring'cubic-bezier(0.22, 1, 0.36, 1)'悬停、内容与普通过渡的曲线。
motionSpringstring'cubic-bezier(0.22, 1.28, 0.36, 1)'选择与形状变化的轻微弹性曲线。
popupZIndexnumber1000浮层 / 弹窗 / 消息层级
modalZIndexnumber1100浮层 / 弹窗 / 消息层级
messageZIndexnumber1200浮层 / 弹窗 / 消息层级
buttonBorderRadiusnumber | string当前控件尺寸仅按钮的圆角 / 共用高度覆盖
buttonHeightnumber | string当前控件尺寸仅按钮的圆角 / 共用高度覆盖
choiceBorderRadiusnumber | string基础圆角 × 0.5复选框圆角
focusColorstring当前语义色自动生成焦点轮廓颜色
primaryHoverColorstring主题色自动生成主色悬停 / 按下
primaryActiveColorstring主题色自动生成主色悬停 / 按下
primarySoftColorstring主题色自动生成主色柔和背景与交互状态
primarySoftHoverColorstring主题色自动生成主色柔和背景与交互状态
primarySoftActiveColorstring主题色自动生成主色柔和背景与交互状态
primaryBorderColorstring主题色自动生成主题色边框
dangerHoverColorstring危险色自动生成危险状态悬停 / 按下
dangerActiveColorstring危险色自动生成危险状态悬停 / 按下
spacingSmnumber | string—设置 spacingSm。
spacingLgnumber | string—设置 spacingLg。
shadowSmstring—设置 shadowSm。
shadowXsstring—最轻的表面阴影。
shadowMdstring—设置 shadowMd。
shadowLgstring—设置 shadowLg。
lineHeightnumber—正文行高。

类型导入

import type { LeafThemeTokens } from '@ifhover/leaf-ui';

const tokens = {
  controlHeightSm: 28,
  borderRadiusLg: 14,
} satisfies LeafThemeTokens;

将该对象传给 <ConfigProvider theme={{ tokens }}>。

LeafComponentTokens

供 theme.components 按组件名称覆盖样式。各组件支持的字段以组件文档为准。

交互状态使用 hover、active、focus、disabled,字段类型见 LeafComponentStateTokens。组件参数的默认值仍通过 ConfigProvider 的 components 设置。

覆盖范围配置键与作用区域
四种交互状态Button、Input、InputNumber、Textarea、Select、AutoComplete、Cascader、TreeSelect、ColorPicker、DatePicker。
选择控件Checkbox、Radio 设置原生选择控件的外观与标签文字色;Switch 设置轨道与标签文字色;Tabs 设置标签按钮。
内容和反馈表面Card、Alert、Table、Modal、Drawer、Confirm、Message 等支持基础描边与阴影,不消费四种交互状态。
浮层Floating 设置共享浮层;Select、AutoComplete、Cascader、TreeSelect、ColorPicker、DatePicker、TimePicker、Dropdown、Mentions、Popover 可覆盖所属浮层的背景、文字色、边框与阴影。

日期、时间、范围选择器复用 DatePicker 的输入外壳状态;例如 TimePicker 的输入聚焦样式通过 DatePicker.focus 配置,所属面板的外观通过 TimePicker 配置。InputOTP 不支持完整的四种状态覆盖。状态用于表中指定的控件区域,不会递归修改组件内部的所有子节点。

属性类型说明
borderRadiusstring | number圆角;数字表示像素。
borderWidthstring | number此组件的边框宽度;数字为 px。
controlHeightstring | number控件高度;数字表示像素。
paddingstring | number内容内边距。
gapstring | number子项之间的间距。
fontSizestring | number字号;数字表示像素。
colorstring颜色或语义色。
backgroundstring组件表面背景。
borderColorstring外层边框与分区分隔线颜色。
headerBackgroundstring标题区域背景。
footerBackgroundstring底部操作区域背景。
shadowstringCSS box-shadow 的值。
hoverLeafComponentStateTokens悬停状态覆盖;嵌套区域逐字段合并。
activeLeafComponentStateTokens按下状态覆盖;嵌套区域逐字段合并。
focusLeafComponentStateTokens键盘聚焦状态覆盖;保留可见焦点轮廓。
disabledLeafComponentStateTokens禁用状态覆盖;不改变禁用行为。

LeafComponentStateTokens

状态只覆盖明确设置的外观字段。嵌套主题按字段继承,不修改父配置;undefined 不覆盖已有值。禁用状态优先于悬停、按下和聚焦,原生禁用行为与键盘焦点轮廓继续生效。

属性类型说明
colorstring当前状态的文字颜色。
backgroundstring当前状态的背景。
borderColorstring当前状态的边框颜色。
shadowstring当前状态的 CSS box-shadow。

LeafThemeStyle

带 --leaf-* 自定义属性的 React 样式类型。业务 CSS 读取变量的示例见 定制主题。

属性类型说明
[key: `--leaf-${string}`]string | number | undefined可复用的 CSS 自定义属性。