mirror of https://github.com/ElemeFE/element
parent
cf0197e02a
commit
71fca8e051
|
@ -1,2 +1,92 @@
|
||||||
## Custom theme
|
## Custom theme
|
||||||
Under construction.
|
Element uses BEM-styled CSS so that you can override styles easily. But if you need to replace styles at a large scale, e.g. change the theme color from blue to orange or green, maybe overriding them one by one is not a good idea, and this is where our theme customization tools kick in.
|
||||||
|
|
||||||
|
### Changing theme color
|
||||||
|
Under construction.
|
||||||
|
|
||||||
|
### More customizations
|
||||||
|
If you need more customization than just changing the theme color, please follow these steps:
|
||||||
|
|
||||||
|
#### <strong>Install related tool</strong>
|
||||||
|
First install the theme generator globally or locally. Local install is recommended because in this way, when others clone your project, npm will automatically install it for them.
|
||||||
|
```shell
|
||||||
|
npm i element-theme -g
|
||||||
|
```
|
||||||
|
|
||||||
|
Then install the chalk theme from npm or GitHub.
|
||||||
|
```shell
|
||||||
|
# from npm
|
||||||
|
npm i element-theme-chalk -D
|
||||||
|
|
||||||
|
# from GitHub
|
||||||
|
npm i https://github.com/ElementUI/theme-chalk -D
|
||||||
|
```
|
||||||
|
|
||||||
|
#### <strong>Initialize variable file</strong>
|
||||||
|
After successfully installing the above packages, a command named `et` is available in CLI (if the packages are installed locally, use `node_modules/.bin/et` instead). Run `-i` to initialize the variable file which outputs to `element-variables.scss` by default. And you can specify its output directory as you will.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
et -i [custom output file]
|
||||||
|
|
||||||
|
> ✔ Generator variables file
|
||||||
|
```
|
||||||
|
|
||||||
|
In `element-variables.scss` you can find all the variables we used to style Element and they are defined in SCSS format:
|
||||||
|
```css
|
||||||
|
$--color-primary: #409EFF !default;
|
||||||
|
$--color-primary-light-1: mix($--color-white, $--color-primary, 10%); /* 53a8ff */
|
||||||
|
$--color-primary-light-2: mix($--color-white, $--color-primary, 20%); /* 66b1ff */
|
||||||
|
$--color-primary-light-3: mix($--color-white, $--color-primary, 30%); /* 79bbff */
|
||||||
|
$--color-primary-light-4: mix($--color-white, $--color-primary, 40%); /* 8cc5ff */
|
||||||
|
$--color-primary-light-5: mix($--color-white, $--color-primary, 50%); /* a0cfff */
|
||||||
|
$--color-primary-light-6: mix($--color-white, $--color-primary, 60%); /* b3d8ff */
|
||||||
|
$--color-primary-light-7: mix($--color-white, $--color-primary, 70%); /* c6e2ff */
|
||||||
|
$--color-primary-light-8: mix($--color-white, $--color-primary, 80%); /* d9ecff */
|
||||||
|
$--color-primary-light-9: mix($--color-white, $--color-primary, 90%); /* ecf5ff */
|
||||||
|
|
||||||
|
$--color-success: #67c23a !default;
|
||||||
|
$--color-warning: #eb9e05 !default;
|
||||||
|
$--color-danger: #fa5555 !default;
|
||||||
|
$--color-info: #878d99 !default;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### <strong>Modify variables</strong>
|
||||||
|
Just edit `element-variables.scss`, e.g. changing the theme color to red:
|
||||||
|
```CSS
|
||||||
|
$--color-primary: red;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### <strong>Build theme</strong>
|
||||||
|
After saving the variable file, use `et` to build your theme. You can activate `watch` mode by adding a parameter `-w`. And if you customized the variable file's output, you need to add a parameter `-c` and variable file's name:
|
||||||
|
```shell
|
||||||
|
et
|
||||||
|
|
||||||
|
> ✔ build theme font
|
||||||
|
> ✔ build element theme
|
||||||
|
```
|
||||||
|
|
||||||
|
#### <strong>Import custom theme</strong>
|
||||||
|
By default the build theme file is placed inside `./theme`. You can specify its output directory with parameter `-o`. Importing your own theme is just like importing the default theme, only this time you import the file you just built:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import '../theme/index.css'
|
||||||
|
import ElementUI from 'element-ui'
|
||||||
|
import Vue from 'vue'
|
||||||
|
|
||||||
|
Vue.use(ElementUI)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### <strong>Import component theme on demand</strong>
|
||||||
|
If you are using `babel-plugin-component` for on-demand import, just modify `.babelrc` and specify `styleLibraryName` to the path where your custom theme is located relative to `.babelrc`. Note that `~` is required:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"plugins": [["component", [
|
||||||
|
{
|
||||||
|
"libraryName": "element-ui",
|
||||||
|
"styleLibraryName": "~theme"
|
||||||
|
}
|
||||||
|
]]]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are unfamiliar with `babel-plugin-component`, please refer to <a href="./#/en-US/component/quickstart">Quick Start</a>. For more details, check out the [project repository](https://github.com/ElementUI/element-theme) of `element-theme`.
|
|
@ -5,17 +5,15 @@
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return callback(new Error('Please input the age'));
|
return callback(new Error('Please input the age'));
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
if (!Number.isInteger(value)) {
|
||||||
if (!Number.isInteger(value)) {
|
callback(new Error('Please input digits'));
|
||||||
callback(new Error('Please input digits'));
|
} else {
|
||||||
|
if (value < 18) {
|
||||||
|
callback(new Error('Age must be greater than 18'));
|
||||||
} else {
|
} else {
|
||||||
if (value < 18) {
|
callback();
|
||||||
callback(new Error('Age must be greater than 18'));
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 1000);
|
}
|
||||||
};
|
};
|
||||||
var validatePass = (rule, value, callback) => {
|
var validatePass = (rule, value, callback) => {
|
||||||
if (value === '') {
|
if (value === '') {
|
||||||
|
@ -548,17 +546,15 @@ This example shows how to customize your own validation rules to finish a two-fa
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return callback(new Error('Please input the age'));
|
return callback(new Error('Please input the age'));
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
if (!Number.isInteger(value)) {
|
||||||
if (!Number.isInteger(value)) {
|
callback(new Error('Please input digits'));
|
||||||
callback(new Error('Please input digits'));
|
} else {
|
||||||
|
if (value < 18) {
|
||||||
|
callback(new Error('Age must be greater than 18'));
|
||||||
} else {
|
} else {
|
||||||
if (value < 18) {
|
callback();
|
||||||
callback(new Error('Age must be greater than 18'));
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 1000);
|
}
|
||||||
};
|
};
|
||||||
var validatePass = (rule, value, callback) => {
|
var validatePass = (rule, value, callback) => {
|
||||||
if (value === '') {
|
if (value === '') {
|
||||||
|
|
|
@ -1,2 +1,92 @@
|
||||||
## 自定义主题
|
## 自定义主题
|
||||||
|
Element 默认提供一套主题,CSS 命名采用 BEM 的风格方便使用者覆盖样式。如果你想完全替换主题色或者部分样式,可以使用下面的方法。
|
||||||
|
|
||||||
|
### 仅替换主题色
|
||||||
整理中。
|
整理中。
|
||||||
|
|
||||||
|
### 深层次的定制
|
||||||
|
如果仅仅改变主题色不能满足你的需求,请按以下步骤进行更深层次的主题定制:
|
||||||
|
|
||||||
|
#### <strong>安装工具</strong>
|
||||||
|
首先安装「主题生成工具」,可以全局安装或者安装在当前项目下,推荐安装在项目里,方便别人 clone 项目时能直接安装依赖并启动,这里以全局安装做演示。
|
||||||
|
```shell
|
||||||
|
npm i element-theme -g
|
||||||
|
```
|
||||||
|
|
||||||
|
安装白垩主题,可以从 npm 安装或者从 GitHub 拉取最新代码。
|
||||||
|
```shell
|
||||||
|
# 从 npm
|
||||||
|
npm i element-theme-chalk -D
|
||||||
|
|
||||||
|
# 从 GitHub
|
||||||
|
npm i https://github.com/ElementUI/theme-chalk -D
|
||||||
|
```
|
||||||
|
|
||||||
|
#### <strong>初始化变量文件</strong>
|
||||||
|
主题生成工具安装成功后,如果全局安装可以在命令行里通过 `et` 调用工具,如果安装在当前目录下,需要通过 `node_modules/.bin/et` 访问到命令。执行 `-i` 初始化变量文件。默认输出到 `element-variables.scss`,当然你可以传参数指定文件输出目录。
|
||||||
|
|
||||||
|
```shell
|
||||||
|
et -i [可以自定义变量文件]
|
||||||
|
|
||||||
|
> ✔ Generator variables file
|
||||||
|
```
|
||||||
|
|
||||||
|
如果使用默认配置,执行后当前目录会有一个 `element-variables.scss` 文件。内部包含了主题所用到的所有变量,它们使用 SCSS 的格式定义。大致结构如下:
|
||||||
|
```css
|
||||||
|
$--color-primary: #409EFF !default;
|
||||||
|
$--color-primary-light-1: mix($--color-white, $--color-primary, 10%); /* 53a8ff */
|
||||||
|
$--color-primary-light-2: mix($--color-white, $--color-primary, 20%); /* 66b1ff */
|
||||||
|
$--color-primary-light-3: mix($--color-white, $--color-primary, 30%); /* 79bbff */
|
||||||
|
$--color-primary-light-4: mix($--color-white, $--color-primary, 40%); /* 8cc5ff */
|
||||||
|
$--color-primary-light-5: mix($--color-white, $--color-primary, 50%); /* a0cfff */
|
||||||
|
$--color-primary-light-6: mix($--color-white, $--color-primary, 60%); /* b3d8ff */
|
||||||
|
$--color-primary-light-7: mix($--color-white, $--color-primary, 70%); /* c6e2ff */
|
||||||
|
$--color-primary-light-8: mix($--color-white, $--color-primary, 80%); /* d9ecff */
|
||||||
|
$--color-primary-light-9: mix($--color-white, $--color-primary, 90%); /* ecf5ff */
|
||||||
|
|
||||||
|
$--color-success: #67c23a !default;
|
||||||
|
$--color-warning: #eb9e05 !default;
|
||||||
|
$--color-danger: #fa5555 !default;
|
||||||
|
$--color-info: #878d99 !default;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### <strong>修改变量</strong>
|
||||||
|
直接编辑 `element-variables.scss` 文件,例如修改主题色为红色。
|
||||||
|
```CSS
|
||||||
|
$--color-primary: red;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### <strong>编译主题</strong>
|
||||||
|
保存文件后,到命令行里执行 `et` 编译主题,如果你想启用 `watch` 模式,实时编译主题,增加 `-w` 参数;如果你在初始化时指定了自定义变量文件,则需要增加 `-c` 参数,并带上你的变量文件名
|
||||||
|
```shell
|
||||||
|
et
|
||||||
|
|
||||||
|
> ✔ build theme font
|
||||||
|
> ✔ build element theme
|
||||||
|
```
|
||||||
|
|
||||||
|
#### <strong>引入自定义主题</strong>
|
||||||
|
默认情况下编译的主题目录是放在 `./theme` 下,你可以通过 `-o` 参数指定打包目录。像引入默认主题一样,在代码里直接引用 `theme/index.css` 文件即可。
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import '../theme/index.css'
|
||||||
|
import ElementUI from 'element-ui'
|
||||||
|
import Vue from 'vue'
|
||||||
|
|
||||||
|
Vue.use(ElementUI)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### <strong>搭配插件按需引入组件主题</strong>
|
||||||
|
如果是搭配 `babel-plugin-component` 一起使用,只需要修改 `.babelrc` 的配置,指定 `styleLibraryName` 路径为自定义主题相对于 `.babelrc` 的路径,注意要加 `~`。
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"plugins": [["component", [
|
||||||
|
{
|
||||||
|
"libraryName": "element-ui",
|
||||||
|
"styleLibraryName": "~theme"
|
||||||
|
}
|
||||||
|
]]]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
如果不清楚 `babel-plugin-component` 是什么,请阅读 <a href="./#/zh-CN/component/quickstart">快速上手</a> 一节。更多 `element-theme` 用法请参考[项目仓库](https://github.com/ElementUI/element-theme)。
|
|
@ -5,17 +5,15 @@
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return callback(new Error('年龄不能为空'));
|
return callback(new Error('年龄不能为空'));
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
if (!Number.isInteger(value)) {
|
||||||
if (!Number.isInteger(value)) {
|
callback(new Error('请输入数字值'));
|
||||||
callback(new Error('请输入数字值'));
|
} else {
|
||||||
|
if (value < 18) {
|
||||||
|
callback(new Error('必须年满18岁'));
|
||||||
} else {
|
} else {
|
||||||
if (value < 18) {
|
callback();
|
||||||
callback(new Error('必须年满18岁'));
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 1000);
|
}
|
||||||
};
|
};
|
||||||
var validatePass = (rule, value, callback) => {
|
var validatePass = (rule, value, callback) => {
|
||||||
if (value === '') {
|
if (value === '') {
|
||||||
|
@ -539,17 +537,15 @@
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return callback(new Error('年龄不能为空'));
|
return callback(new Error('年龄不能为空'));
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
if (!Number.isInteger(value)) {
|
||||||
if (!Number.isInteger(value)) {
|
callback(new Error('请输入数字值'));
|
||||||
callback(new Error('请输入数字值'));
|
} else {
|
||||||
|
if (value < 18) {
|
||||||
|
callback(new Error('必须年满18岁'));
|
||||||
} else {
|
} else {
|
||||||
if (value < 18) {
|
callback();
|
||||||
callback(new Error('必须年满18岁'));
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 1000);
|
}
|
||||||
};
|
};
|
||||||
var validatePass = (rule, value, callback) => {
|
var validatePass = (rule, value, callback) => {
|
||||||
if (value === '') {
|
if (value === '') {
|
||||||
|
|
|
@ -544,7 +544,7 @@
|
||||||
|
|
||||||
resetInputHeight() {
|
resetInputHeight() {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
if (!this.$refs.reference) return;
|
if (!this.$refs.reference || !this.$refs.tags) return;
|
||||||
let inputChildNodes = this.$refs.reference.$el.childNodes;
|
let inputChildNodes = this.$refs.reference.$el.childNodes;
|
||||||
let input = [].filter.call(inputChildNodes, item => item.tagName === 'INPUT')[0];
|
let input = [].filter.call(inputChildNodes, item => item.tagName === 'INPUT')[0];
|
||||||
input.style.height = this.selected.length === 0 && this.size === 'mini'
|
input.style.height = this.selected.length === 0 && this.size === 'mini'
|
||||||
|
|
Loading…
Reference in New Issue