TabBar.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import _extends from 'babel-runtime/helpers/extends';
  2. import _defineProperty from 'babel-runtime/helpers/defineProperty';
  3. import _typeof from 'babel-runtime/helpers/typeof';
  4. import Icon from '../icon';
  5. import ScrollableInkTabBar from '../vc-tabs/src/ScrollableInkTabBar';
  6. import { cloneElement } from '../_util/vnode';
  7. import PropTypes from '../_util/vue-types';
  8. import { getListeners } from '../_util/props-util';
  9. var TabBar = {
  10. name: 'TabBar',
  11. inheritAttrs: false,
  12. props: {
  13. prefixCls: PropTypes.string,
  14. tabBarStyle: PropTypes.object,
  15. tabBarExtraContent: PropTypes.any,
  16. type: PropTypes.oneOf(['line', 'card', 'editable-card']),
  17. tabPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']).def('top'),
  18. tabBarPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
  19. size: PropTypes.oneOf(['default', 'small', 'large']),
  20. animated: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
  21. renderTabBar: PropTypes.func,
  22. panels: PropTypes.array.def([]),
  23. activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  24. tabBarGutter: PropTypes.number
  25. },
  26. render: function render() {
  27. var _cls;
  28. var h = arguments[0];
  29. var _$props = this.$props,
  30. tabBarStyle = _$props.tabBarStyle,
  31. _$props$animated = _$props.animated,
  32. animated = _$props$animated === undefined ? true : _$props$animated,
  33. renderTabBar = _$props.renderTabBar,
  34. tabBarExtraContent = _$props.tabBarExtraContent,
  35. tabPosition = _$props.tabPosition,
  36. prefixCls = _$props.prefixCls,
  37. _$props$type = _$props.type,
  38. type = _$props$type === undefined ? 'line' : _$props$type,
  39. size = _$props.size;
  40. var inkBarAnimated = (typeof animated === 'undefined' ? 'undefined' : _typeof(animated)) === 'object' ? animated.inkBar : animated;
  41. var isVertical = tabPosition === 'left' || tabPosition === 'right';
  42. var prevIconType = isVertical ? 'up' : 'left';
  43. var nextIconType = isVertical ? 'down' : 'right';
  44. var prevIcon = h(
  45. 'span',
  46. { 'class': prefixCls + '-tab-prev-icon' },
  47. [h(Icon, {
  48. attrs: { type: prevIconType },
  49. 'class': prefixCls + '-tab-prev-icon-target' })]
  50. );
  51. var nextIcon = h(
  52. 'span',
  53. { 'class': prefixCls + '-tab-next-icon' },
  54. [h(Icon, {
  55. attrs: { type: nextIconType },
  56. 'class': prefixCls + '-tab-next-icon-target' })]
  57. );
  58. // Additional className for style usage
  59. var cls = (_cls = {}, _defineProperty(_cls, prefixCls + '-' + tabPosition + '-bar', true), _defineProperty(_cls, prefixCls + '-' + size + '-bar', !!size), _defineProperty(_cls, prefixCls + '-card-bar', type && type.indexOf('card') >= 0), _cls);
  60. var renderProps = {
  61. props: _extends({}, this.$props, this.$attrs, {
  62. inkBarAnimated: inkBarAnimated,
  63. extraContent: tabBarExtraContent,
  64. prevIcon: prevIcon,
  65. nextIcon: nextIcon
  66. }),
  67. style: tabBarStyle,
  68. on: getListeners(this),
  69. 'class': cls
  70. };
  71. var RenderTabBar = void 0;
  72. if (renderTabBar) {
  73. RenderTabBar = renderTabBar(renderProps, ScrollableInkTabBar);
  74. // https://github.com/vueComponent/ant-design-vue/issues/2157
  75. return cloneElement(RenderTabBar, renderProps);
  76. } else {
  77. return h(ScrollableInkTabBar, renderProps);
  78. }
  79. }
  80. };
  81. export default TabBar;