You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/tabs/index.vue

153 lines
3.8 KiB

7 years ago
<script>
import Tabs from './Tabs'
import isFlexSupported from '../_util/isFlexSupported'
export default {
props: {
prefixCls: { type: String, default: 'ant-tabs' },
activeKey: String,
defaultActiveKey: String,
hideAdd: { type: Boolean, default: false },
tabBarStyle: Object,
7 years ago
tabBarExtraContent: [String, Number, Function],
destroyInactiveTabPane: { type: Boolean, default: false },
7 years ago
type: {
validator (value) {
return ['line', 'card', 'editable-card'].includes(value)
},
},
tabPosition: {
validator (value) {
return ['top', 'right', 'bottom', 'left'].includes(value)
},
},
size: {
validator (value) {
return ['default', 'small'].includes(value)
},
},
7 years ago
animated: { type: [Boolean, Object], default: undefined },
},
model: {
prop: 'activeKey',
event: 'change',
7 years ago
},
methods: {
createNewTab (targetKey) {
7 years ago
this.$emit('edit', targetKey, 'add')
7 years ago
},
removeTab (targetKey, e) {
e.stopPropagation()
if (!targetKey) {
return
}
7 years ago
this.$emit('edit', targetKey, 'remove')
7 years ago
},
handleChange (activeKey) {
7 years ago
this.$emit('change', activeKey)
7 years ago
},
7 years ago
onTabClick (val) {
this.$emit('tabClick', val)
},
onPrevClick (val) {
this.$emit('prevClick', val)
},
onNextClick (val) {
this.$emit('nextClick', val)
},
7 years ago
},
mounted () {
const NO_FLEX = ' no-flex'
const tabNode = this.$el
if (tabNode && !isFlexSupported() && tabNode.className.indexOf(NO_FLEX) === -1) {
tabNode.className += NO_FLEX
}
},
7 years ago
render (createElement) {
7 years ago
const {
prefixCls,
size,
type = 'line',
tabPosition,
tabBarStyle,
7 years ago
hideAdd,
7 years ago
onTabClick,
onPrevClick,
onNextClick,
7 years ago
animated,
destroyInactiveTabPane = false,
activeKey,
defaultActiveKey,
7 years ago
$slots,
7 years ago
} = this
7 years ago
let { tabBarExtraContent } = this.$props
7 years ago
let { inkBarAnimated, tabPaneAnimated } = typeof animated === 'object' ? { // eslint-disable-line
7 years ago
inkBarAnimated: !!animated.inkBar, tabPaneAnimated: !!animated.tabPane,
7 years ago
} : {
7 years ago
inkBarAnimated: animated === undefined || animated, tabPaneAnimated: animated === undefined || animated,
7 years ago
}
// card tabs should not have animation
if (type !== 'line') {
7 years ago
tabPaneAnimated = animated === undefined ? false : tabPaneAnimated
7 years ago
}
const cls = {
[`${prefixCls}-mini`]: size === 'small' || size,
[`${prefixCls}-vertical`]: tabPosition === 'left' || tabPosition === 'right',
[`${prefixCls}-card`]: type.indexOf('card') >= 0,
[`${prefixCls}-${type}`]: true,
[`${prefixCls}-no-animation`]: !tabPaneAnimated,
}
7 years ago
tabBarExtraContent = tabBarExtraContent || ((h) => {
return h('span', [$slots.tabBarExtraContent])
})
7 years ago
const tabBarProps = {
inkBarAnimated,
extraContent: tabBarExtraContent,
onTabClick,
onPrevClick,
onNextClick,
style: tabBarStyle,
7 years ago
hideAdd,
removeTab: this.removeTab,
createNewTab: this.createNewTab,
7 years ago
}
7 years ago
const tabContentProps = {
animated: tabPaneAnimated,
animatedWithMargin: true,
}
7 years ago
const self = this
const tabsProps = {
props: {
prefixCls,
tabBarPosition: tabPosition,
onChange: this.handleChange,
tabBarProps: tabBarProps,
tabContentProps: tabContentProps,
destroyInactiveTabPane,
activeKey,
defaultActiveKey,
type,
onTabClick: this.onTabClick,
},
on: {
change (val) {
self.handleChange(val)
},
},
}
7 years ago
return (
<Tabs
class={cls}
7 years ago
{...tabsProps}
7 years ago
>
7 years ago
{this.$slots.default}
7 years ago
</Tabs>
)
},
}
</script>