From db76bdeef63e4ea6aa17ce2f151598197e5c67e5 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 21 Aug 2018 15:53:31 +0800 Subject: [PATCH] [new feature] support addGlobalClass (#449) --- example/pages/actionsheet/index.wxss | 2 +- packages/actionsheet/index.js | 4 ++++ packages/badge-group/index.js | 4 ++++ packages/badge/index.js | 4 ++++ packages/button/index.js | 4 ++++ packages/card/index.js | 3 ++- packages/cell-group/index.js | 4 ++++ packages/cell/index.js | 3 ++- packages/col/index.js | 4 ++++ packages/field/index.js | 3 ++- packages/icon/index.js | 4 ++++ packages/loading/index.js | 4 ++++ packages/nav-bar/index.js | 3 ++- packages/notice-bar/index.js | 4 ++++ packages/notify/index.js | 32 ++++++---------------------- packages/notify/notify.js | 25 ++++++++++++++++++++++ packages/overlay/index.js | 4 ++++ packages/panel/index.js | 3 ++- packages/popup/index.js | 4 ++++ packages/row/index.js | 4 ++++ packages/search/index.js | 3 ++- packages/stepper/index.js | 4 ++++ packages/steps/index.js | 4 ++++ packages/switch/index.js | 4 ++++ packages/tabbar-item/index.js | 5 ++--- packages/tabbar/index.js | 4 ++++ packages/tag/index.js | 4 ++++ packages/toast/index.js | 4 ++++ packages/transition/index.js | 4 ++++ packages/tree-select/index.js | 4 ++++ 30 files changed, 127 insertions(+), 35 deletions(-) create mode 100644 packages/notify/notify.js diff --git a/example/pages/actionsheet/index.wxss b/example/pages/actionsheet/index.wxss index c4db16ed..6323b951 100644 --- a/example/pages/actionsheet/index.wxss +++ b/example/pages/actionsheet/index.wxss @@ -1,3 +1,3 @@ .content { padding: 20px; -} \ No newline at end of file +} diff --git a/packages/actionsheet/index.js b/packages/actionsheet/index.js index d3f68a79..90092106 100644 --- a/packages/actionsheet/index.js +++ b/packages/actionsheet/index.js @@ -1,4 +1,8 @@ Component({ + options: { + addGlobalClass: true + }, + properties: { show: Boolean, title: String, diff --git a/packages/badge-group/index.js b/packages/badge-group/index.js index 6f9cda68..7fb2f27d 100644 --- a/packages/badge-group/index.js +++ b/packages/badge-group/index.js @@ -1,6 +1,10 @@ const BADGE_PATH = '../badge/index'; Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class'], relations: { diff --git a/packages/badge/index.js b/packages/badge/index.js index b046203d..4a27209d 100644 --- a/packages/badge/index.js +++ b/packages/badge/index.js @@ -1,6 +1,10 @@ const BADGE_GROUP_PATH = '../badge-group/index'; Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class'], relations: { diff --git a/packages/button/index.js b/packages/button/index.js index 5bbc0e18..5b263570 100644 --- a/packages/button/index.js +++ b/packages/button/index.js @@ -6,6 +6,10 @@ const observer = function() { }; Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class', 'loading-class'], behaviors: [nativeBehaviors], diff --git a/packages/card/index.js b/packages/card/index.js index 791ddbf3..dc1d9964 100644 --- a/packages/card/index.js +++ b/packages/card/index.js @@ -1,6 +1,7 @@ Component({ options: { - multipleSlots: true + multipleSlots: true, + addGlobalClass: true }, externalClasses: [ diff --git a/packages/cell-group/index.js b/packages/cell-group/index.js index 7c0cbd4b..61e9f502 100644 --- a/packages/cell-group/index.js +++ b/packages/cell-group/index.js @@ -1,4 +1,8 @@ Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class'], properties: { diff --git a/packages/cell/index.js b/packages/cell/index.js index 41455190..bbeb0271 100644 --- a/packages/cell/index.js +++ b/packages/cell/index.js @@ -9,7 +9,8 @@ Component({ ], options: { - multipleSlots: true + multipleSlots: true, + addGlobalClass: true }, properties: { diff --git a/packages/col/index.js b/packages/col/index.js index 956f5dc7..49b84ad5 100644 --- a/packages/col/index.js +++ b/packages/col/index.js @@ -1,6 +1,10 @@ const ROW_PATH = '../row/index'; Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class'], relations: { diff --git a/packages/field/index.js b/packages/field/index.js index 796873f5..f07713d2 100644 --- a/packages/field/index.js +++ b/packages/field/index.js @@ -6,7 +6,8 @@ Component({ ], options: { - multipleSlots: true + multipleSlots: true, + addGlobalClass: true }, properties: { diff --git a/packages/icon/index.js b/packages/icon/index.js index 8f2e645c..ea9e0f76 100644 --- a/packages/icon/index.js +++ b/packages/icon/index.js @@ -1,4 +1,8 @@ Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class'], properties: { diff --git a/packages/loading/index.js b/packages/loading/index.js index 5ab0a49a..85edb5ec 100644 --- a/packages/loading/index.js +++ b/packages/loading/index.js @@ -1,4 +1,8 @@ Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class'], properties: { diff --git a/packages/nav-bar/index.js b/packages/nav-bar/index.js index 45212d21..72ed2a16 100644 --- a/packages/nav-bar/index.js +++ b/packages/nav-bar/index.js @@ -5,7 +5,8 @@ Component({ ], options: { - multipleSlots: true + multipleSlots: true, + addGlobalClass: true }, properties: { diff --git a/packages/notice-bar/index.js b/packages/notice-bar/index.js index c30faf36..2666c75c 100644 --- a/packages/notice-bar/index.js +++ b/packages/notice-bar/index.js @@ -3,6 +3,10 @@ const FONT_COLOR = '#f60'; const BG_COLOR = '#fff7cc'; Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class'], properties: { diff --git a/packages/notify/index.js b/packages/notify/index.js index 849cbf97..bb7ae070 100644 --- a/packages/notify/index.js +++ b/packages/notify/index.js @@ -1,4 +1,10 @@ +import Notify from './notify'; + Component({ + options: { + addGlobalClass: true + }, + properties: { text: String, color: { @@ -40,28 +46,4 @@ Component({ } }); -const defaultOptions = { - selector: '#van-notify', - duration: 3000 -}; - -export default function Notify(options = {}) { - const pages = getCurrentPages(); - const ctx = pages[pages.length - 1]; - - options = Object.assign({}, defaultOptions, parseParam(options)); - - const el = ctx.selectComponent(options.selector); - delete options.selector; - - if (el) { - el.setData({ - ...options - }); - el.show(); - } -} - -function parseParam(params = '') { - return typeof params === 'object' ? params : { text: params }; -} +export default Notify; diff --git a/packages/notify/notify.js b/packages/notify/notify.js new file mode 100644 index 00000000..dd912e26 --- /dev/null +++ b/packages/notify/notify.js @@ -0,0 +1,25 @@ +const defaultOptions = { + selector: '#van-notify', + duration: 3000 +}; + +export default function Notify(options = {}) { + const pages = getCurrentPages(); + const ctx = pages[pages.length - 1]; + + options = Object.assign({}, defaultOptions, parseParam(options)); + + const el = ctx.selectComponent(options.selector); + delete options.selector; + + if (el) { + el.setData({ + ...options + }); + el.show(); + } +} + +function parseParam(params = '') { + return typeof params === 'object' ? params : { text: params }; +} diff --git a/packages/overlay/index.js b/packages/overlay/index.js index 67f32cfc..94506d95 100644 --- a/packages/overlay/index.js +++ b/packages/overlay/index.js @@ -1,4 +1,8 @@ Component({ + options: { + addGlobalClass: true + }, + properties: { show: Boolean, mask: Boolean, diff --git a/packages/panel/index.js b/packages/panel/index.js index 7d77342c..ec38b3de 100644 --- a/packages/panel/index.js +++ b/packages/panel/index.js @@ -5,7 +5,8 @@ Component({ ], options: { - multipleSlots: true + multipleSlots: true, + addGlobalClass: true }, properties: { diff --git a/packages/popup/index.js b/packages/popup/index.js index 9001d6d3..047ea7ef 100644 --- a/packages/popup/index.js +++ b/packages/popup/index.js @@ -1,4 +1,8 @@ Component({ + options: { + addGlobalClass: true + }, + externalClasses: [ 'custom-class', 'overlay-class' diff --git a/packages/row/index.js b/packages/row/index.js index 93a7345b..261b3fac 100644 --- a/packages/row/index.js +++ b/packages/row/index.js @@ -1,6 +1,10 @@ const COL_PATH = '../col/index'; Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class'], relations: { diff --git a/packages/search/index.js b/packages/search/index.js index 7f051545..4c68acc8 100644 --- a/packages/search/index.js +++ b/packages/search/index.js @@ -2,7 +2,8 @@ Component({ externalClasses: ['custom-class', 'cancel-class'], options: { - multipleSlots: true + multipleSlots: true, + addGlobalClass: true }, properties: { diff --git a/packages/stepper/index.js b/packages/stepper/index.js index cacdb9d8..db85d79b 100644 --- a/packages/stepper/index.js +++ b/packages/stepper/index.js @@ -3,6 +3,10 @@ const MAX = 2147483647; Component({ + options: { + addGlobalClass: true + }, + externalClasses: [ 'custom-class', 'input-class', diff --git a/packages/steps/index.js b/packages/steps/index.js index 9d5c16c7..e07415ca 100644 --- a/packages/steps/index.js +++ b/packages/steps/index.js @@ -1,4 +1,8 @@ Component({ + options: { + addGlobalClass: true + }, + externalClasses: [ 'custom-class' ], diff --git a/packages/switch/index.js b/packages/switch/index.js index b965b6cb..062298a6 100644 --- a/packages/switch/index.js +++ b/packages/switch/index.js @@ -1,4 +1,8 @@ Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class', 'node-class'], properties: { diff --git a/packages/tabbar-item/index.js b/packages/tabbar-item/index.js index da38910c..a888b510 100644 --- a/packages/tabbar-item/index.js +++ b/packages/tabbar-item/index.js @@ -1,8 +1,6 @@ const TABBAR_PATH = '../tabbar/index'; Component({ - name: 'tabbar-item', - properties: { info: null, icon: String, @@ -10,7 +8,8 @@ Component({ }, options: { - multipleSlots: true + multipleSlots: true, + addGlobalClass: true }, relations: { diff --git a/packages/tabbar/index.js b/packages/tabbar/index.js index c22d01be..a19c784a 100644 --- a/packages/tabbar/index.js +++ b/packages/tabbar/index.js @@ -1,6 +1,10 @@ const ITEM_PATH = '../tabbar-item/index'; Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class'], properties: { diff --git a/packages/tag/index.js b/packages/tag/index.js index 7a9299d1..f415cfac 100644 --- a/packages/tag/index.js +++ b/packages/tag/index.js @@ -1,4 +1,8 @@ Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class'], properties: { diff --git a/packages/toast/index.js b/packages/toast/index.js index a64e1306..fa0adba4 100644 --- a/packages/toast/index.js +++ b/packages/toast/index.js @@ -1,6 +1,10 @@ import Toast from './toast'; Component({ + options: { + addGlobalClass: true + }, + properties: { show: Boolean, mask: Boolean, diff --git a/packages/transition/index.js b/packages/transition/index.js index 51cb5ade..ad6fc717 100644 --- a/packages/transition/index.js +++ b/packages/transition/index.js @@ -1,4 +1,8 @@ Component({ + options: { + addGlobalClass: true + }, + externalClasses: ['custom-class'], properties: { diff --git a/packages/tree-select/index.js b/packages/tree-select/index.js index 4362686b..099c5e7e 100644 --- a/packages/tree-select/index.js +++ b/packages/tree-select/index.js @@ -1,6 +1,10 @@ const ITEM_HEIGHT = 44; Component({ + options: { + addGlobalClass: true + }, + properties: { items: { type: Array,