From c010ee22acda57fba0e140a0344a483377aee1b7 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 1 Feb 2019 17:26:10 +0800 Subject: [PATCH] [improvement] Toast: jsx (#2664) --- packages/toast/Toast.js | 98 +++++++++++++++ packages/toast/Toast.vue | 114 ------------------ .../test/__snapshots__/index.spec.js.snap | 2 - 3 files changed, 98 insertions(+), 116 deletions(-) create mode 100644 packages/toast/Toast.js delete mode 100644 packages/toast/Toast.vue diff --git a/packages/toast/Toast.js b/packages/toast/Toast.js new file mode 100644 index 000000000..89c049613 --- /dev/null +++ b/packages/toast/Toast.js @@ -0,0 +1,98 @@ +import { use, isDef } from '../utils'; +import Icon from '../icon'; +import Loading from '../loading'; +import Popup from '../mixins/popup'; + +const [sfc, bem] = use('toast'); +const STYLE = ['success', 'fail', 'loading']; + +export default sfc({ + mixins: [Popup], + + props: { + forbidClick: Boolean, + message: [String, Number], + type: { + type: String, + default: 'text' + }, + loadingType: { + type: String, + default: 'circular' + }, + position: { + type: String, + default: 'middle' + }, + lockScroll: { + type: Boolean, + default: false + } + }, + + data() { + return { + clickable: false + }; + }, + + mounted() { + this.toggleClickale(); + }, + + destroyed() { + this.toggleClickale(); + }, + + watch: { + value() { + this.toggleClickale(); + }, + + forbidClick() { + this.toggleClickale(); + } + }, + + methods: { + toggleClickale() { + const clickable = this.value && this.forbidClick; + if (this.clickable !== clickable) { + this.clickable = clickable; + const action = clickable ? 'add' : 'remove'; + document.body.classList[action]('van-toast--unclickable'); + } + } + }, + + render(h) { + const { type, message } = this; + const style = STYLE.indexOf(type) !== -1 ? 'default' : type; + + const Content = () => { + switch (style) { + case 'text': + return
{message}
; + case 'html': + return
; + default: + return [ + type === 'loading' ? ( + + ) : ( + + ), + isDef(message) &&
{message}
+ ]; + } + }; + + return ( + +
+ {Content()} +
+
+ ); + } +}); diff --git a/packages/toast/Toast.vue b/packages/toast/Toast.vue deleted file mode 100644 index 3394b01e6..000000000 --- a/packages/toast/Toast.vue +++ /dev/null @@ -1,114 +0,0 @@ - - - diff --git a/packages/toast/test/__snapshots__/index.spec.js.snap b/packages/toast/test/__snapshots__/index.spec.js.snap index 68c72910e..9e8e33d85 100644 --- a/packages/toast/test/__snapshots__/index.spec.js.snap +++ b/packages/toast/test/__snapshots__/index.spec.js.snap @@ -3,7 +3,5 @@ exports[`create a forbidClick toast 1`] = ` `;