From 0bfbcf6ca9c26394d6a352a6960962bf0188bf6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Sun, 19 Jan 2020 17:36:22 +0800 Subject: [PATCH] chore: split jsx blocks --- src/dialog/Dialog.js | 65 ++++++++--------- src/number-keyboard/index.js | 131 +++++++++++++++++++---------------- 2 files changed, 104 insertions(+), 92 deletions(-) diff --git a/src/dialog/Dialog.js b/src/dialog/Dialog.js index 621e38c6d..3f3005257 100644 --- a/src/dialog/Dialog.js +++ b/src/dialog/Dialog.js @@ -91,6 +91,39 @@ export default createComponent({ onClosed() { this.$emit('closed'); }, + + genButtons() { + const multiple = this.showCancelButton && this.showConfirmButton; + + return ( +
+ {this.showCancelButton && ( +
+ ); + }, }, render() { @@ -122,36 +155,6 @@ export default createComponent({ ); - const hasButtons = this.showCancelButton && this.showConfirmButton; - const ButtonGroup = ( -
- {this.showCancelButton && ( -
- ); - return ( {Title} {Content} - {ButtonGroup} + {this.genButtons()} ); diff --git a/src/number-keyboard/index.js b/src/number-keyboard/index.js index b46494545..29a57489a 100644 --- a/src/number-keyboard/index.js +++ b/src/number-keyboard/index.js @@ -134,83 +134,92 @@ export default createComponent({ this.$emit('update:value', value + text); } }, + + genTitle() { + const { title, theme, closeButtonText } = this; + const titleLeft = this.slots('title-left'); + const showClose = closeButtonText && theme === 'default'; + const showTitle = title || showClose || titleLeft; + + if (!showTitle) { + return; + } + + return ( +
+ {titleLeft && {titleLeft}} + {title && {title}} + {showClose && ( + + {closeButtonText} + + )} +
+ ); + }, + + genKeys() { + return this.keys.map(key => ( + + {key.type === 'delete' && this.slots('delete')} + {key.type === 'extra' && this.slots('extra-key')} + + )); + }, + + genSidebar() { + if (this.theme === 'custom') { + return ( +
+ + {this.slots('delete')} + + +
+ ); + } + }, }, render() { - const { title, theme, onPress, closeButtonText } = this; - - const titleLeftSlot = this.slots('title-left'); - const showTitleClose = closeButtonText && theme === 'default'; - const showTitle = title || showTitleClose || titleLeftSlot; - - const Title = showTitle && ( -
- {titleLeftSlot && ( - {titleLeftSlot} - )} - {title && {title}} - {showTitleClose && ( - - {closeButtonText} - - )} -
- ); - - const Keys = this.keys.map(key => ( - - {key.type === 'delete' && this.slots('delete')} - {key.type === 'extra' && this.slots('extra-key')} - - )); - - const Sidebar = theme === 'custom' && ( -
- - {this.slots('delete')} - - -
- ); - return (
- {Title} + {this.genTitle()}
- {Keys} - {Sidebar} + {this.genKeys()} + {this.genSidebar()}