UNPKG

ant-design-vue

Version:

An enterprise-class UI design language and Vue-based implementation

193 lines (185 loc) 6.73 kB
import _extends from 'babel-runtime/helpers/extends'; import _defineProperty from 'babel-runtime/helpers/defineProperty'; import _typeof from 'babel-runtime/helpers/typeof'; import Icon from '../icon'; import VcTabs, { TabPane } from '../vc-tabs/src'; import ScrollableInkTabBar from '../vc-tabs/src/ScrollableInkTabBar'; import TabContent from '../vc-tabs/src/TabContent'; import isFlexSupported from '../_util/isFlexSupported'; import { hasProp, getComponentFromProp, isEmptyElement, getSlotOptions, getOptionProps, filterEmpty, mergeProps } from '../_util/props-util'; import warning from '../_util/warning'; import { cloneElement } from '../_util/vnode'; export default { TabPane: TabPane, name: 'ATabs', props: { prefixCls: { type: String, 'default': 'ant-tabs' }, activeKey: String, defaultActiveKey: String, hideAdd: { type: Boolean, 'default': false }, tabBarStyle: Object, tabBarExtraContent: [String, Number, Function], destroyInactiveTabPane: { type: Boolean, 'default': false }, type: { validator: function validator(value) { return ['line', 'card', 'editable-card'].includes(value); } }, tabPosition: { validator: function validator(value) { return ['top', 'right', 'bottom', 'left'].includes(value); } }, size: { validator: function validator(value) { return ['default', 'small', 'large'].includes(value); } }, animated: { type: [Boolean, Object], 'default': undefined }, tabBarGutter: Number }, model: { prop: 'activeKey', event: 'change' }, methods: { createNewTab: function createNewTab(targetKey) { this.$emit('edit', targetKey, 'add'); }, removeTab: function removeTab(targetKey, e) { e.stopPropagation(); if (!targetKey) { return; } this.$emit('edit', targetKey, 'remove'); }, handleChange: function handleChange(activeKey) { this.$emit('change', activeKey); }, onTabClick: function onTabClick(val) { this.$emit('tabClick', val); }, onPrevClick: function onPrevClick(val) { this.$emit('prevClick', val); }, onNextClick: function onNextClick(val) { this.$emit('nextClick', val); } }, mounted: function mounted() { var NO_FLEX = ' no-flex'; var tabNode = this.$el; if (tabNode && !isFlexSupported() && tabNode.className.indexOf(NO_FLEX) === -1) { tabNode.className += NO_FLEX; } }, render: function render(createElement) { var _cls, _this = this; var h = arguments[0]; var prefixCls = this.prefixCls, size = this.size, _type = this.type, type = _type === undefined ? 'line' : _type, tabPosition = this.tabPosition, tabBarStyle = this.tabBarStyle, hideAdd = this.hideAdd, onTabClick = this.onTabClick, onPrevClick = this.onPrevClick, onNextClick = this.onNextClick, animated = this.animated, tabBarGutter = this.tabBarGutter; var children = filterEmpty(this.$slots['default']); var tabBarExtraContent = getComponentFromProp(this, 'tabBarExtraContent'); var _ref = (typeof animated === 'undefined' ? 'undefined' : _typeof(animated)) === 'object' ? { // eslint-disable-line inkBarAnimated: !!animated.inkBar, tabPaneAnimated: !!animated.tabPane } : { inkBarAnimated: animated === undefined || animated, tabPaneAnimated: animated === undefined || animated // card tabs should not have animation }, inkBarAnimated = _ref.inkBarAnimated, tabPaneAnimated = _ref.tabPaneAnimated; if (type !== 'line') { tabPaneAnimated = animated === undefined ? false : tabPaneAnimated; } var cls = (_cls = {}, _defineProperty(_cls, prefixCls + '-small', size === 'small'), _defineProperty(_cls, prefixCls + '-large', size === 'large'), _defineProperty(_cls, prefixCls + '-default', size === 'default'), _defineProperty(_cls, prefixCls + '-vertical', tabPosition === 'left' || tabPosition === 'right'), _defineProperty(_cls, prefixCls + '-card', type.indexOf('card') >= 0), _defineProperty(_cls, prefixCls + '-' + type, true), _defineProperty(_cls, prefixCls + '-no-animation', !tabPaneAnimated), _cls); // only card type tabs can be added and closed var childrenWithClose = []; if (type === 'editable-card') { childrenWithClose = []; children.forEach(function (child, index) { var props = getOptionProps(child); var closable = props.closable; closable = typeof closable === 'undefined' ? true : closable; var closeIcon = closable ? h(Icon, { attrs: { type: 'close' }, on: { 'click': function click(e) { return _this.removeTab(child.key, e); } } }) : null; childrenWithClose.push(cloneElement(child, { props: { tab: h( 'div', { 'class': closable ? undefined : prefixCls + '-tab-unclosable' }, [getComponentFromProp(child, 'tab'), closeIcon] ) }, key: child.key || index })); }); // Add new tab handler if (!hideAdd) { tabBarExtraContent = h('span', [h(Icon, { attrs: { type: 'plus' }, 'class': prefixCls + '-new-tab', on: { 'click': this.createNewTab } }), tabBarExtraContent]); } } tabBarExtraContent = tabBarExtraContent ? h( 'div', { 'class': prefixCls + '-extra-content' }, [tabBarExtraContent] ) : null; var renderTabBar = function renderTabBar() { var scrollableInkTabBarProps = { props: { inkBarAnimated: inkBarAnimated, extraContent: tabBarExtraContent, tabBarGutter: tabBarGutter }, on: { tabClick: onTabClick, prevClick: onPrevClick, nextClick: onNextClick }, style: tabBarStyle }; return h(ScrollableInkTabBar, scrollableInkTabBarProps); }; var tabsProps = { props: _extends({}, getOptionProps(this), { tabBarPosition: tabPosition, renderTabBar: renderTabBar, renderTabContent: function renderTabContent() { return h(TabContent, { attrs: { animated: tabPaneAnimated, animatedWithMargin: true } }); }, children: childrenWithClose.length > 0 ? childrenWithClose : children, __propsSymbol__: Symbol() }), on: _extends({}, this.$listeners, { change: this.handleChange }), 'class': cls }; return h(VcTabs, tabsProps); } };