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

Table of Contents

Typical Example
Detailed Introduction
Style 1: No Dynamic Requirement
Style 2: Using antd Tokens
Style 3: Using External Props
Organizing Code Files
Other Common CSS Syntax
Keyframes
API
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
Design Philosophy and Implementation Strategy
NEXT
Theme Switching

相关资源

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

Writing Styles Using createStyles

The core API provided by antd-style is createStyles, which allows organizing styles using class names, similar to the writing style of CSS Modules.

Default

This is our first recommended writing style. It can be used to write application styles or override basic component styles.

Typical Example

A demo example containing basic usage, understanding this demo will enable you to use the createStyles method.

Detailed Introduction

createStyles provides several writing styles to meet development needs and improve the development experience for different scenarios.

Style 1: No Dynamic Requirement

If there is no dynamic requirement, you can directly use createStyles to pass in a style object.

Style 2: Using antd Tokens

The createStyles method can use antd tokens and custom tokens. In this case, the parameter of createStyles needs to be a function.

ts

Style 3: Using External Props

The second parameter of the function can receive external props.

tsx

The following demo is an example of overriding the antd Select component with external input parameters.

Organizing Code Files

If the component styles are simple, they can be merged into one file. However, if the style file is large, it is strongly recommended to separate the style file into a style.ts file. As shown below:

Other Common CSS Syntax

Keyframes

Supports two types of keyframes writing, using the keyframes method or the native CSS @keyframes.

API

For detailed API documentation of the createStyles method, please refer to the createStyles API documentation.

createStyles 标准用法

包含了两种css书写方式,且集成了 token 的使用

index.tsx
tsx
index.tsx
tsx
结合 antd token

当切换站点亮暗色模式时,Demo 均能适应站点主题实现自动切换

带有props入参的写法

打开面板时,描边会变色 / 当选中选项1时,变成主色样式

复杂样式场景下建议独立拆分样式文件

Demo 示例参考 https://designmaestro.io/

index.tsx
style.ts
tsx
index.tsx
tsx
createStyles Demo
当前主题模式:light
用法一

普通对象,无需动态性

操作按钮
普通卡片
主要卡片
选项2
选项1
keyframes 写法一
keyframes 写法二