Skip to content

Commit

Permalink
fix: make zIndex configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
AngusFu committed Mar 27, 2019
1 parent 41f7bab commit ecd8e05
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
16 changes: 16 additions & 0 deletions docs/content/component/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ import 'clair/dist/clair.css'
Vue.use(Clair)
```

## 配置 zIndex 起始大小

```javascript
import Vue from 'vue'
import Clair from 'clair'
import 'clair/dist/clair.css'

Vue.use(Clair, { zIndex: 12345 })
```

如果你是通过 `<script>` 标签直接引入 Clair 的话,则可以使用如下方式配置:

```javascript
window.Clair.setInitialZIndex(12345)
```

## 关于 polyfill,兼谈在 vue-cli 3 项目中的使用

因为 Clair 项目中使用到了一些新的 ES201x 特性(主要是 Array 和 Object 的一些拓展),在构建时我们并未对这些特性(如`Array#findIndex` `Object.assign`等)进行 polyfill。我们认为,对这些特性的 polyfill 工作应该交给开发者/使用者。
Expand Down
8 changes: 7 additions & 1 deletion docs/plugins/clair.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ if (process.env.NODE_ENV === 'production') {
require('../../src/styles/entry.css')
}

module.exports = process.env.NODE_ENV === 'production'
const Clair = process.env.NODE_ENV === 'production'
? require('../../dist/clair.cjs')
: require('../../src/entry')

module.exports = {
install (Vue) {
Clair.setInitialZIndex(1999)
}
}
10 changes: 9 additions & 1 deletion src/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import Notification from './plugins/notification'
import validatable from './mixins/validatable'
import resettable from './mixins/resettable'

import zIndexManager from './utils/zIndexManager'

const mixins = { validatable, resettable }

export const Clair = {
mixins,
install (Vue) {
install (Vue, option = {}) {
zIndexManager.setInitialZIndex(option.zIndex || 1992)

const VuePrototype = Vue.prototype
const defineReadOnly = function (key, val) {
Object.defineProperty(VuePrototype, key, {
Expand Down Expand Up @@ -52,5 +56,9 @@ export const Clair = {
Vue.use(Modal)
Vue.use(Responsive)
Vue.use(Notification)
},

setInitialZIndex (zIndex) {
zIndexManager.setInitialZIndex(Number(zIndex) || 1992)
}
}
3 changes: 3 additions & 0 deletions src/scripts/utils/zIndexManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ let start = 1992
export default {
next () {
return start++
},
setInitialZIndex (zIndex) {
start = zIndex
}
}

0 comments on commit ecd8e05

Please sign in to comment.