ant-design-vue
Version:
An enterprise-class UI design language and Vue-based implementation
231 lines (200 loc) • 7.74 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _typeof2 = require('babel-runtime/helpers/typeof');
var _typeof3 = _interopRequireDefault(_typeof2);
var _icon = require('../icon');
var _icon2 = _interopRequireDefault(_icon);
var _src = require('../vc-tabs/src');
var _src2 = _interopRequireDefault(_src);
var _ScrollableInkTabBar = require('../vc-tabs/src/ScrollableInkTabBar');
var _ScrollableInkTabBar2 = _interopRequireDefault(_ScrollableInkTabBar);
var _TabContent = require('../vc-tabs/src/TabContent');
var _TabContent2 = _interopRequireDefault(_TabContent);
var _isFlexSupported = require('../_util/isFlexSupported');
var _isFlexSupported2 = _interopRequireDefault(_isFlexSupported);
var _propsUtil = require('../_util/props-util');
var _warning = require('../_util/warning');
var _warning2 = _interopRequireDefault(_warning);
var _vnode = require('../_util/vnode');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
exports['default'] = {
TabPane: _src.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 && !(0, _isFlexSupported2['default'])() && 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 = (0, _propsUtil.filterEmpty)(this.$slots['default']);
var tabBarExtraContent = (0, _propsUtil.getComponentFromProp)(this, 'tabBarExtraContent');
var _ref = (typeof animated === 'undefined' ? 'undefined' : (0, _typeof3['default'])(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 = {}, (0, _defineProperty3['default'])(_cls, prefixCls + '-small', size === 'small'), (0, _defineProperty3['default'])(_cls, prefixCls + '-large', size === 'large'), (0, _defineProperty3['default'])(_cls, prefixCls + '-default', size === 'default'), (0, _defineProperty3['default'])(_cls, prefixCls + '-vertical', tabPosition === 'left' || tabPosition === 'right'), (0, _defineProperty3['default'])(_cls, prefixCls + '-card', type.indexOf('card') >= 0), (0, _defineProperty3['default'])(_cls, prefixCls + '-' + type, true), (0, _defineProperty3['default'])(_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 = (0, _propsUtil.getOptionProps)(child);
var closable = props.closable;
closable = typeof closable === 'undefined' ? true : closable;
var closeIcon = closable ? h(_icon2['default'], {
attrs: {
type: 'close'
},
on: {
'click': function click(e) {
return _this.removeTab(child.key, e);
}
}
}) : null;
childrenWithClose.push((0, _vnode.cloneElement)(child, {
props: {
tab: h(
'div',
{ 'class': closable ? undefined : prefixCls + '-tab-unclosable' },
[(0, _propsUtil.getComponentFromProp)(child, 'tab'), closeIcon]
)
},
key: child.key || index
}));
});
// Add new tab handler
if (!hideAdd) {
tabBarExtraContent = h('span', [h(_icon2['default'], {
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(_ScrollableInkTabBar2['default'], scrollableInkTabBarProps);
};
var tabsProps = {
props: (0, _extends3['default'])({}, (0, _propsUtil.getOptionProps)(this), {
tabBarPosition: tabPosition,
renderTabBar: renderTabBar,
renderTabContent: function renderTabContent() {
return h(_TabContent2['default'], {
attrs: { animated: tabPaneAnimated, animatedWithMargin: true }
});
},
children: childrenWithClose.length > 0 ? childrenWithClose : children,
__propsSymbol__: Symbol()
}),
on: (0, _extends3['default'])({}, this.$listeners, {
change: this.handleChange
}),
'class': cls
};
return h(_src2['default'], tabsProps);
}
};
module.exports = exports['default'];
;