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

Table of Contents

Steps for Migrating Applications
1. Replace the Entry File
2. Replace the Style Code
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
Less Application Automated Migration
NEXT
Migrating Less Components

相关资源

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 & 数字科技
‌
‌
‌
‌

Migrating Less Applications

createStyle can be used to create and write style code very simply, and it can provide intelligent prompts and type checking, which is completely sufficient for writing new styles. However, there are still a large amount of old project code in our hands. How can we quickly migrate to antd-style?

Steps for Migrating Applications

Taking the HeaderSearch in Ant Design Pro as an example, the core code related to styles is as follows:

1. Replace the Entry File

Change the style file from index.less to style.ts, and add the hooks const { styles } = useStyles() import. This way, the JSX layer code is modified.

diff

2. Replace the Style Code

Change the style code from less syntax to createStyles syntax. First, rename index.less to style.ts, and then add the following at the top:

diff

Next, use some tools to help us quickly convert CSS to CSS Object, for example:

  • https://transform.tools/css-to-js: Transform CSS to JS tool, which can handle nesting normally, but the converted result will retain the '.' prefix, which still needs to be manually removed;
  • https://staxmanade.com/CssToReact/: This can directly convert to the target style needed, but it seems that the support for nested CSS is not ideal;
  • https://marketplace.visualstudio.com/items?itemName=rishabh-rathod.css-to-js&ssr=false#qna: VSCode plugin that can convert with one click, but has poor compatibility with less variables;
ts

And change the nested style objects to be at the same level:

ts

Finally, replace the color values with antd's tokens

diff

The final effect is as follows:

After the migration is completed, thanks to the good type programming ability of TS, we not only have the ability to dynamically theme, but also have the ability to drill down into class names, improving the development experience.