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: {
|
2020-06-23 14:34:08 +00:00
|
|
|
animated: PropTypes.bool.def(true),
|
|
|
|
animatedWithMargin: PropTypes.bool.def(true),
|
|
|
|
prefixCls: PropTypes.string.def('ant-tabs'),
|
2019-01-12 03:33:27 +00:00
|
|
|
activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
2020-06-23 14:34:08 +00:00
|
|
|
tabBarPosition: PropTypes.string,
|
2020-03-07 11:45:13 +00:00
|
|
|
direction: PropTypes.string,
|
|
|
|
destroyInactiveTabPane: PropTypes.bool,
|
2020-06-24 08:07:03 +00:00
|
|
|
children: PropTypes.any,
|
2017-11-21 11:15:41 +00:00
|
|
|
},
|
|
|
|
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: {
|
2020-06-23 14:34:08 +00:00
|
|
|
getTabPanes(children) {
|
2019-01-12 03:33:27 +00:00
|
|
|
const props = this.$props;
|
|
|
|
const activeKey = props.activeKey;
|
|
|
|
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, {
|
2020-06-23 14:34:08 +00:00
|
|
|
active,
|
|
|
|
destroyInactiveTabPane: props.destroyInactiveTabPane,
|
|
|
|
rootPrefixCls: props.prefixCls,
|
2019-01-12 03:33:27 +00:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
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() {
|
2020-06-24 08:07:03 +00:00
|
|
|
const {
|
|
|
|
activeKey,
|
|
|
|
tabBarPosition,
|
|
|
|
animated,
|
|
|
|
animatedWithMargin,
|
|
|
|
direction,
|
|
|
|
classes,
|
|
|
|
children,
|
|
|
|
} = this;
|
2019-01-12 03:33:27 +00:00
|
|
|
let style = {};
|
2020-06-23 14:34:08 +00:00
|
|
|
if (animated && children) {
|
|
|
|
const activeIndex = getActiveIndex(children, activeKey);
|
2017-11-21 11:15:41 +00:00
|
|
|
if (activeIndex !== -1) {
|
|
|
|
const animatedStyle = animatedWithMargin
|
|
|
|
? getMarginStyle(activeIndex, tabBarPosition)
|
2020-03-07 11:45:13 +00:00
|
|
|
: getTransformPropValue(getTransformByIndex(activeIndex, tabBarPosition, direction));
|
2019-01-12 03:33:27 +00:00
|
|
|
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}>
|
2020-06-23 14:34:08 +00:00
|
|
|
{this.getTabPanes(children || [])}
|
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
|
|
|
};
|