From 9279965cc1f8998254c7b664716d0d0e5b899bd9 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Mon, 21 Sep 2020 17:16:49 +0800 Subject: [PATCH] refactor(TabsTitle): refactor with composition api --- src/tabs/{Title.js => TabsTitle.tsx} | 54 +++++++++++++++------------- src/tabs/index.js | 5 ++- 2 files changed, 31 insertions(+), 28 deletions(-) rename src/tabs/{Title.js => TabsTitle.tsx} (54%) diff --git a/src/tabs/Title.js b/src/tabs/TabsTitle.tsx similarity index 54% rename from src/tabs/Title.js rename to src/tabs/TabsTitle.tsx index e79cdd0ca..e89b6fed8 100644 --- a/src/tabs/Title.js +++ b/src/tabs/TabsTitle.tsx @@ -1,3 +1,4 @@ +import { computed } from 'vue'; import { createNamespace, isDef } from '../utils'; import Badge from '../badge'; @@ -16,20 +17,27 @@ export default createComponent({ activeColor: String, renderTitle: Function, inactiveColor: String, - swipeThreshold: [Number, String], }, - computed: { - style() { - const style = {}; - const { color, isActive } = this; - const isCard = this.type === 'card'; + setup(props) { + const style = computed(() => { + const style: Record = {}; + const { + type, + color, + disabled, + isActive, + activeColor, + inactiveColor, + } = props; + + const isCard = type === 'card'; // card theme color if (color && isCard) { style.borderColor = color; - if (!this.disabled) { + if (!disabled) { if (isActive) { style.backgroundColor = color; } else { @@ -38,50 +46,46 @@ export default createComponent({ } } - const titleColor = isActive ? this.activeColor : this.inactiveColor; + const titleColor = isActive ? activeColor : inactiveColor; if (titleColor) { style.color = titleColor; } return style; - }, - }, + }); - methods: { - genText() { + const renderText = () => { const Text = ( - - {this.renderTitle ? this.renderTitle() : this.title} + + {props.renderTitle ? props.renderTitle() : props.title} ); - if (this.dot || (isDef(this.badge) && this.badge !== '')) { + if (props.dot || (isDef(props.badge) && props.badge !== '')) { return ( {Text} - {} + {} ); } return Text; - }, - }, + }; - render() { - return ( + return () => ( ); }, diff --git a/src/tabs/index.js b/src/tabs/index.js index ffcc9b7a2..714536605 100644 --- a/src/tabs/index.js +++ b/src/tabs/index.js @@ -20,8 +20,8 @@ import { ParentMixin } from '../mixins/relation'; import { BindEventMixin } from '../mixins/bind-event'; // Components -import Title from './Title'; import Sticky from '../sticky'; +import TabsTitle from './TabsTitle'; import TabsContent from './TabsContent'; const [createComponent, bem] = createNamespace('tabs'); @@ -360,7 +360,7 @@ export default createComponent({ const Nav = this.children.map((item, index) => { return ( - { this.titleRefs[index] = val; }} @@ -376,7 +376,6 @@ export default createComponent({ renderTitle={item.$slots.title} activeColor={this.titleActiveColor} inactiveColor={this.titleInactiveColor} - swipeThreshold={this.swipeThreshold} onClick={() => { this.onClick(item, index); }}