mand-mobile/site/docs/theme.en-US.md

121 lines
3.6 KiB
Markdown
Raw Permalink Normal View History

2018-05-16 20:57:22 +08:00
---
2018-05-28 19:32:11 +08:00
title: Theme Customization
2018-05-16 20:57:22 +08:00
---
`Mand Mobile` provides a set of UI themes based on `DiDi financial business design specifications` by default. It also supports theme customization. You can freely adjust the colors, fonts, and element sizes to meet the visual requirements in different business scenarios.
<p>
<img src="http://static.galileo.xiaojukeji.com/static/tms/other/mand-theme.jpg" width="800">
</p>
2019-06-18 21:17:55 +08:00
<iframe src="https://codesandbox.io/embed/mand-mobile-custom-theme-ofbut?fontsize=12&module=%2Fsrc%2Fassets%2Ftheme.custom.styl" title="Mand Mobile Custom Theme" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
2018-05-16 20:57:22 +08:00
### Style Variables
2018-05-28 19:32:11 +08:00
`Mand Mobile` style is based on <a href="http://stylus-lang.com/" target="_blank">Stylus</a> and can adjust theme styles through global and component style variables.
2018-05-16 20:57:22 +08:00
2019-01-29 18:06:59 +08:00
A complete list of variables can be found in built-in variables <a href="https://github.com/didi/mand-mobile/blob/master/components/_style/mixin/theme.basic.styl" target="_blank">Global Variables</a><a href="https://github.com/didi/mand-mobile/blob/master/components/_style/mixin/theme.components.styl" target="_blank">Components Variables</a>
2018-05-16 20:57:22 +08:00
### Variable Coverage
You can achieve theme customization by importing component source code and overriding style variables.
* First, install dependencies`babel-plugin-import stylus stylus-loader css-loader`
```shell
npm install --save-dev babel-plugin-import stylus stylus-loader css-loader
```
* Configure `babel-plugin-import` to ensure that component source code is imported
```javascript
// .babelrc or babel-loader/ts-loader option
{
"plugins": [
["import", {"libraryName": "mand-mobile", "libraryDirectory": "components"}],
]
}
```
2019-09-11 17:06:46 +08:00
2018-05-28 19:32:11 +08:00
* Create a customized theme file, such as `theme.custom.styl`
2018-05-16 20:57:22 +08:00
```stylus
@import '~mand-mobile/components/_style/mixin/util'
2018-12-12 17:24:41 +08:00
@import '~mand-mobile/components/_style/mixin/theme.components'
@import '~mand-mobile/components/_style/mixin/theme.basic'
2018-05-16 20:57:22 +08:00
// Import nib (Optional)
@import '~nib/lib/nib/vendor'
@import '~nib/lib/nib/gradients'
// Override style variables
color-primary = #1AAD19
```
2019-09-11 17:06:46 +08:00
* Import the `mand-mobile` global style (either in the project entry or global style), for example:
main.js
```js
import 'mand-mobile/components/_style/global'
```
or global.styl
```stylus
@import '~mand-mobile/components/_style/global'
```
* Configure `webpack` and import customized theme file `theme.custom.styl`
2018-05-16 20:57:22 +08:00
```javascript
const poststylus = require('poststylus')
const pxtorem = require('postcss-pxtorem')
module.exports = {
// ...
module: {
rules: [
// ...
{
test: /\.js$/,
loader: 'babel-loader',
include: /node_modules\/mand-mobile/
},
{
test: /\.styl$/,
use: [
'css-loader',
{
loader: 'stylus-loader',
options: {
import:['theme.custom.styl']
}
}
]
},
{
test: /\.(png|jpe?g|gif)(\?.*)?$/,
loader: 'url-loader',
include: /node_modules\/mand-mobile/
},
// ...
]
},
plugins: [
// ...
new webpack.LoaderOptionsPlugin({
options: {
stylus: {
// pxtorem (According to needs of your project)
use: [poststylus(pxtorem({ rootValue: 100, minPixelValue: 2, propWhiteList: [] }))]
2018-05-16 20:57:22 +08:00
}
}
}),
// ...
]
}
```