Browse Source

Merge pull request #3908 from ant-design/docs-customize-theme

Docs customize theme
pull/3888/merge
偏右 8 years ago
committed by GitHub
parent
commit
3caa85b3f3
  1. 2
      CHANGELOG.en-US.md
  2. 2
      CHANGELOG.zh-CN.md
  3. 2
      components/icon/index.en-US.md
  4. 2
      components/icon/index.zh-CN.md
  5. 55
      docs/react/customize-theme.en-US.md
  6. 56
      docs/react/customize-theme.zh-CN.md
  7. 2
      docs/react/upgrade-notes.md

2
CHANGELOG.en-US.md

@ -1,5 +1,5 @@
---
order: 3
order: 5
title: Change Log
toc: false
timeline: true

2
CHANGELOG.zh-CN.md

@ -1,5 +1,5 @@
---
order: 3
order: 5
title: 更新日志
toc: false
timeline: true

2
components/icon/index.en-US.md

@ -123,7 +123,7 @@ ul.anticons-list li:hover .anticon {
display: block;
text-align: center;
transform: scale(0.83);
font-family: Consolas;
font-family: "Lucida Console", Consolas;
white-space: nowrap;
}
</style>

2
components/icon/index.zh-CN.md

@ -124,7 +124,7 @@ ul.anticons-list li:hover .anticon {
display: block;
text-align: center;
transform: scale(0.83);
font-family: Consolas;
font-family: "Lucida Console", Consolas;
white-space: nowrap;
}
</style>

55
docs/react/customize-theme.en-US.md

@ -0,0 +1,55 @@
---
order: 4
title: Customize theme
---
Ant Design allow to customize some basic design tokens for meeting the needs of UI diversity from bussiness and brand, including primary color, border radius, border and etc.
![](https://zos.alipayobjects.com/rmsportal/zTFoszBtDODhXfLAazfSpYbSLSEeytoG.png)
## Less variables
We are using [Less](http://lesscss.org/) as development language of style. A series of less variables are defined for each design tokens which can be customized as your needs.
- [Default Variables](https://github.com/ant-design/ant-design/blob/master/components/style/themes/default.less)
Please report issue if the variables is not enough for you.
## How to use it
We recommand [modifyVars](http://lesscss.org/usage/#using-less-in-the-browser-modify-variables) to override the default variables. There are two way to achieve it in practive.
You can run this [example](https://github.com/ant-design/antd-init/tree/master/examples/customize-antd-theme) for playground.
### 1) package.theme (recommanded)
Specify the `theme` field in 'package.json', which could be a object or file path.
```js
"theme": {
"@primary-color": "#1DA57A",
},
```
or:
```js
"theme": "./theme.js", // https://github.com/ant-design/antd-init/blob/master/examples/customize-antd-theme/theme.js
```
This way is working only when using [atool-build](https://github.com/ant-tool/atool-build)(built in [antd-init](https://github.com/ant-design/antd-init) and [dva-cli](https://github.com/dvajs/dva-cli)). If you choose other boilerplates, you can write webpack config about [less-loader modifyVars](https://github.com/webpack/less-loader#less-options) like [atool-build ](https://github.com/ant-tool/atool-build/blob/a4b3e3eec4ffc09b0e2352d7f9d279c4c28fdb99/src/getWebpackCommonConfig.js#L131-L138) does.
Note: importing less style is necessary. Please specify `style` option of `babel-plugin-import` to be `true` or `less` if you are using it.
### 2) less
Override variables via less definition files.
Create a standalone less file like below, and import it in your project.
```css
@import "~antd/dist/antd.less"; // import official less entry file
@import "your-theme-file.less"; // override variables here
```
Note: this way will load style of all component regardless of your demand, which cause `style` option of `babel-plugin-import` not working.

56
docs/react/customize-theme.zh-CN.md

@ -0,0 +1,56 @@
---
order: 4
title: 定制主题
---
Ant Design 设计规范上支持一定程度的样式定制,以满足业务和品牌上多样化的视觉需求,包括但不限于主色、圆角、边框和部分组件的视觉定制。
![](https://zos.alipayobjects.com/rmsportal/zTFoszBtDODhXfLAazfSpYbSLSEeytoG.png)
## 样式变量
antd 的样式使用了 [Less](http://lesscss.org/) 作为开发语言,并定义了一系列全局/组件的样式变量,你可以根据需求进行相应调整。
- [默认样式变量](https://github.com/ant-design/ant-design/blob/master/components/style/themes/default.less)
如果以上变量不能满足你的定制需求,可以给我们提 issue。
## 定制方式
我们使用 [modifyVars](http://lesscss.org/usage/#using-less-in-the-browser-modify-variables) 的方式来覆盖变量。
在具体工程实践中,有 `package.theme``less` 两种方案,选择一种即可。
可以在本地运行[例子](https://github.com/ant-design/antd-init/tree/master/examples/customize-antd-theme) 查看定制效果。
### 1) package.theme(推荐)
配置在 `package.json` 下的 `theme` 字段。theme 可以为配置为一个对象或文件路径。
```js
"theme": {
"@primary-color": "#1DA57A",
},
```
或者:
```js
"theme": "./theme.js", // https://github.com/ant-design/antd-init/blob/master/examples/customize-antd-theme/theme.js
```
定义 `package.theme` 时, 需要配合 [atool-build](https://github.com/ant-tool/atool-build) 使用([antd-init](https://github.com/ant-design/antd-init) 和 [dva-cli](https://github.com/dvajs/dva-cli) 内建支持)。如果你使用的是其他脚手架,可以参考 [atool-build 中 less-loader 的 webpack 相关配置 ](https://github.com/ant-tool/atool-build/blob/a4b3e3eec4ffc09b0e2352d7f9d279c4c28fdb99/src/getWebpackCommonConfig.js#L131-L138),利用 [less-loader](https://github.com/webpack/less-loader#less-options) 的 `modifyVars` 配置来覆盖原来的样式变量。
注意,样式必须加载 less 格式。如果您使用了 `babel-plugin-import`,请将 style 属性配置为 `true``less`
### 2) less
用 less 文件进行变量覆盖。
建立一个单独的 `less` 文件如下,再引入这个文件。
```css
@import "~antd/dist/antd.less"; // 引入官方提供的 less 样式入口文件
@import "your-theme-file.less"; // 用于覆盖上面定义的变量
```
注意:这种方式会载入所有组件的样式,无法和按需加载插件 `babel-plugin-import``style` 属性一起使用。

2
docs/react/upgrade-notes.md

@ -1,5 +1,5 @@
---
order: 4
order: 6
title:
zh-CN: 升级指南
en-US: Upgrade Notes

Loading…
Cancel
Save