feat: update toast doc

This commit is contained in:
jiangruowei
2017-03-15 16:26:12 +08:00
parent 2de6435873
commit 98071b8634
9 changed files with 66 additions and 61 deletions

View File

@@ -1,12 +1,12 @@
import Vue from 'vue';
const ToastConstructor = Vue.extend(require('./toast.vue'));
let toastPool = [];
let toastQueue = [];
let getInstance = () => {
if (toastPool.length > 0) {
let instance = toastPool[0];
toastPool.splice(0, 1);
if (toastQueue.length > 0) {
let instance = toastQueue[0];
toastQueue.splice(0, 1);
return instance;
}
return new ToastConstructor({
@@ -16,7 +16,7 @@ let getInstance = () => {
const returnInstance = instance => {
if (instance) {
toastPool.push(instance);
toastQueue.push(instance);
}
};
@@ -31,6 +31,7 @@ var Toast = (options = {}) => {
const duration = options.duration || 3000;
let instance = getInstance();
returnInstance(instance);
instance.closed = false;
clearTimeout(instance.timer);
instance.type = options.type ? options.type : 'text';
@@ -40,20 +41,15 @@ var Toast = (options = {}) => {
Vue.nextTick(function() {
instance.visible = true;
instance.$el.removeEventListener('transitionend', removeDom);
instance.timer = setTimeout(function() {
if (instance.closed) return;
instance.close();
instance.visible = false;
instance.$el.addEventListener('transitionend', removeDom);
instance.closed = true;
}, duration);
});
return instance;
};
Toast.close = function() {
this.visible = false;
this.$el.addEventListener('transitionend', removeDom);
this.closed = true;
returnInstance(this);
};
export default Toast;

View File

@@ -1,6 +1,6 @@
<template>
<transition name="zan-toast">
<div class="zan-toast" :class="['zan-toast' + displayStyle]" v-show="visible">
<div class="zan-toast" :class="['zan-toast--' + displayStyle]" v-show="visible">
<!-- 只显示文字 -->
<template v-if="displayStyle === 'text'" >
<div class="zan-toast__text">{{message}}</div>
@@ -10,8 +10,8 @@
<zan-loading v-if="type === 'loading'" type="gradient-circle" color="white"></zan-loading>
</template>
<!-- 图案加文字 -->
<template v-if="displayStyle === 'iconPlusText'">
<zan-cell class="zan-toast__icon":name="check"></zan-cell>
<template v-if="displayStyle === 'default'">
<zan-icon class="zan-toast__icon" name="check"></zan-icon>
<div class="zan-toast__text">{{message}}</div>
</template>
</div>
@@ -19,21 +19,17 @@
</template>
<script>
import zanLoading from 'packages/Loading';
import zanLoading from 'packages/loading';
import zanIcon from 'packages/icon';
const TOAST_TYPE = ['text', 'loading', 'success', 'failure'];
const TOAST_TYPES = ['text', 'loading', 'success', 'failure'];
/**
* zan-toast
* @module components/switch
* @desc 开关
* @param {boolean} [checked=false] - 开关状态
* @param {boolean} [disabled=false] - 禁用
* @param {boolean} [loading=false] - loading状态
* @param {callback} [onChange] - 开关状态改变回调函数。
* @module components/toast
* @desc toast
* @param {string} [type=false] - 类型
* @param {string} [message] - 信息
*
* @example
* <zan-switch checked="true" disabled="false"></zan-switch>
*/
export default {
name: 'zan-toast',
@@ -45,7 +41,10 @@ export default {
props: {
type: {
type: String,
default: false
default: 'text',
validate(value) {
return TOAST_TYPES.indexOf(value) > -1;
}
},
message: {
type: String,
@@ -57,6 +56,11 @@ export default {
}
}
},
data() {
return {
visible: false
};
},
computed: {
displayStyle() {
switch (this.type) {
@@ -65,7 +69,7 @@ export default {
case 'loading':
return 'loading';
default:
return 'iconPlusText';
return 'default';
}
},
iconName() {