Skip to content

主题定制

Aether UI 的主题系统基于 CSS 自定义属性,支持亮色/暗色切换和深度定制。

内置主题

ts
import { lightTheme, darkTheme } from '@aether/ui'

亮色主题 (lightTheme)

默认主题,以白色为基底,蓝色为主色。

暗色主题 (darkTheme)

深色背景主题,适配暗色模式。

切换主题

vue
<script setup lang="ts">
import { ref } from 'vue'
import { AConfigProvider, lightTheme, darkTheme } from '@aether/ui'

const theme = ref(lightTheme)
</script>

<template>
  <AConfigProvider :theme="theme">
    <button @click="theme = theme.name === 'light' ? darkTheme : lightTheme">
      切换主题
    </button>
  </AConfigProvider>
</template>

自定义主题

你可以通过覆盖 common 变量来创建自定义主题:

ts
import { lightTheme } from '@aether/ui'
import type { GlobalTheme } from '@aether/ui'

const myTheme: GlobalTheme = {
  name: 'light',
  common: {
    ...lightTheme.common,
    primaryColor: '#ff6b6b',
    primaryColorHover: '#ff8787',
    primaryColorPressed: '#e55a5a',
    borderRadius: '6px',
  },
}

通用主题变量

变量亮色默认值说明
primaryColor#2080f0主色
primaryColorHover#4098fc主色悬停
primaryColorPressed#1060c9主色按下
infoColor#2080f0信息色
successColor#18a058成功色
warningColor#f0a020警告色
errorColor#d03050错误色
textColor1rgb(31,34,37)一级文字
textColor2rgb(51,54,57)二级文字
textColor3rgb(118,124,130)三级文字
borderColorrgb(224,224,230)边框色
baseColor#fff基础背景色
borderRadius3px圆角
fontSize14px基础字号
heightSmall28px小号高度
heightMedium34px中号高度
heightLarge40px大号高度

组件级主题变量

每个组件都有独立的主题变量,格式为 --a-<property>,通过 CSS 自定义属性绑定到组件根元素。

例如 Button 组件的变量:

css
--a-height: 34px;
--a-font-size: 14px;
--a-color: #2080f0;
--a-text-color: #fff;
--a-border-radius: 3px;
--a-bezier: cubic-bezier(.4, 0, .2, 1);

Released under the MIT License.