Ant Design StyleAnt Design Style
Quick Start
Best Practices
API Reference
Release Notes
⌘ K

Table of Contents

Customize Ant Design Theme
Compatible usage of ConfigProvider theme
Function writing method
Custom Token
Custom Appearance Mode
Basic Knowledge
Introduction
Quick Start to CSS in JS
Comparison of CSS in JS Writing Methods
Design Philosophy and Implementation Strategy
Quick Start
Writing Style
Theme Switching
Custom Theme
Advanced Usage
Babel Plugin
SSR Integration
Component Development
Integrated styled
🚧 Stylish Composite Styles
Performance Comparison of CSS-in-JS Libraries
Migrating from Less
Less Application Automated Migration
Manual Migration of Less Applications
Migrating Less Components
🚧 Compilation Differences Between CSS-in-JS and Less
PREV
Theme Switching
NEXT
Babel Plugin

相关资源

Ant Design
Ant Design Pro
Ant Design Pro Components
Umi-React 应用开发框架
Dumi-组件/文档研发工具
qiankun-微前端框架

社区

Medium
Twitter
yuqueAnt Design 语雀专栏
Ant Design 知乎专栏
体验科技专栏
seeconfSEE Conf-SEE Conf-蚂蚁体验科技大会

帮助

GitHub
更新日志
讨论

more products更多产品

yuque语雀-知识创作与分享工具
AntVAntV-数据可视化解决方案
EggEgg-企业级 Node.js 框架
kitchenKitchen-Sketch 工具集
xtech蚂蚁体验科技
Copyright © 2022-2024
Made with ❤️ by 蚂蚁集团 - AFX & 数字科技
‌
‌
‌
‌

Custom Theme

antd-style, combined with complete experience in business development, provides powerful and flexible theme customization capabilities, which will be introduced in the following three aspects: 1) antd theme customization, 2) custom application token, 3) custom appearance mode.

Customize Ant Design Theme

The ConfigProvider of antd v5 provides the theme configuration, which can pass in a custom theme object to achieve custom themes. The ThemeProvider of antd-style provides a more convenient way for custom themes based on ConfigProvider.

Compatible usage of ConfigProvider theme

tsx

Function writing method

For antd, to ensure the atomicity and composability of functions, ConfigProvider only saves one theme state. Therefore, if you need to support common light and dark theme switching, you need to encapsulate it at the application layer.

As an application layer, antd-style defines the appearance field, and thus supports light and dark theme switching by default. Therefore, the theme configuration also supports passing in a function to set different themes under different appearance modes.

tsx

The input parameter of the function is the current theme appearance, and the output is the theme object.

ts
Usage

In actual application development, due to the possibility of multiple theme configurations, it is recommended to extract the theme configuration into a separate file, and then uniformly export and use it as getAntdTheme. (Example reference)

Custom Token

At the beginning of the design, the default Token system of Ant Design was not created for all business customization demands, it only contains the tokens necessary for the Ant Design design system. In most business scenarios, we often need to customize some tokens to be uniformly consumed in the application. You may think that only designers need to care about tokens, but in fact, the token system is the foundation of application specifications, from a gradient style to the width of the top navigation bar, all can be uniformly managed and consumed in the token system.

Therefore, antd-style provides the ability to customize tokens, allowing the application layer to customize its own tokens and use them in createStyles, styled, and other style methods.

In the ThemeProvider, you can pass in custom tokens through the customToken field. Similar to the usage logic of theme, you can pass in an object or a function.

tsx

The input parameter of the function is some of our built-in methods, but the output is the token object. In this method's input parameter, you can get the current theme appearance, antd's token value, and thus achieve the inheritance effect of custom token themes.

tsx

For detailed introductions on the demo of custom Token API, TypeScript type definition integration, etc., please refer to ThemeProvider - Inject Custom Token Theme.

Application

The document theme package used by antd-style has customized some custom tokens required by the theme package. If interested, you can go to dumi-theme-antd-style to view.

Custom Appearance Mode

In addition, since appearance can be controlled and used, it is also possible to customize the Appearance mode to extend different themes.

WARNING

If you need to customize the Appearance mode, it is not recommended to set themeMode to auto, as this will cause the Appearance mode to be affected by system theme switching, which may not meet your expectations.