2019-01-12 03:33:27 +00:00
|
|
|
import PropTypes from '../../_util/vue-types';
|
|
|
|
import { cloneElement } from '../../_util/vnode';
|
2017-11-21 11:15:41 +00:00
|
|
|
import {
|
|
|
|
getTransformByIndex,
|
|
|
|
getActiveIndex,
|
|
|
|
getTransformPropValue,
|
|
|
|
getMarginStyle,
|
2019-01-12 03:33:27 +00:00
|
|
|
} from './utils';
|
2017-11-21 11:15:41 +00:00
|
|
|
export default {
|
|
|
|
name: 'TabContent',
|
|
|
|
props: {
|
|
|
|
animated: { type: Boolean, default: true },
|
|
|
|
animatedWithMargin: { type: Boolean, default: true },
|
|
|
|
prefixCls: {
|
|
|
|
default: 'ant-tabs',
|
|
|
|
type: String,
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2017-11-21 11:15:41 +00:00
|
|
|
tabBarPosition: String,
|
|
|
|
},
|
|
|
|
computed: {
|
2019-01-12 03:33:27 +00:00
|
|
|
classes() {
|
|
|
|
const { animated, prefixCls } = this;
|
2017-11-21 11:15:41 +00:00
|
|
|
return {
|
|
|
|
[`${prefixCls}-content`]: true,
|
2019-01-12 03:33:27 +00:00
|
|
|
[animated ? `${prefixCls}-content-animated` : `${prefixCls}-content-no-animated`]: true,
|
|
|
|
};
|
2017-11-21 11:15:41 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
2019-01-12 03:33:27 +00:00
|
|
|
getTabPanes() {
|
|
|
|
const props = this.$props;
|
|
|
|
const activeKey = props.activeKey;
|
|
|
|
const children = this.$slots.default || [];
|
|
|
|
const newChildren = [];
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
children.forEach(child => {
|
2018-09-05 13:28:54 +00:00
|
|
|
if (!child) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return;
|
2018-09-05 13:28:54 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
const key = child.key;
|
|
|
|
const active = activeKey === key;
|
|
|
|
newChildren.push(
|
|
|
|
cloneElement(child, {
|
|
|
|
props: {
|
|
|
|
active,
|
|
|
|
destroyInactiveTabPane: props.destroyInactiveTabPane,
|
|
|
|
rootPrefixCls: props.prefixCls,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
return newChildren;
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2017-11-21 11:15:41 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
const { activeKey, tabBarPosition, animated, animatedWithMargin, classes } = this;
|
|
|
|
let style = {};
|
2017-11-21 11:15:41 +00:00
|
|
|
if (animated && this.$slots.default) {
|
2019-01-12 03:33:27 +00:00
|
|
|
const activeIndex = getActiveIndex(this.$slots.default, activeKey);
|
2017-11-21 11:15:41 +00:00
|
|
|
if (activeIndex !== -1) {
|
|
|
|
const animatedStyle = animatedWithMargin
|
|
|
|
? getMarginStyle(activeIndex, tabBarPosition)
|
2019-01-12 03:33:27 +00:00
|
|
|
: getTransformPropValue(getTransformByIndex(activeIndex, tabBarPosition));
|
|
|
|
style = animatedStyle;
|
2017-11-21 11:15:41 +00:00
|
|
|
} else {
|
|
|
|
style = {
|
|
|
|
display: 'none',
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2017-11-21 11:15:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (
|
2019-01-12 03:33:27 +00:00
|
|
|
<div class={classes} style={style}>
|
2018-09-05 13:28:54 +00:00
|
|
|
{this.getTabPanes()}
|
2017-11-21 11:15:41 +00:00
|
|
|
</div>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2017-11-21 11:15:41 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|