Col.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import _defineProperty from 'babel-runtime/helpers/defineProperty';
  2. import PropTypes from '../_util/vue-types';
  3. import { getOptionProps, getSlots, getComponentFromProp } from '../_util/props-util';
  4. var ColProps = {
  5. child: PropTypes.any,
  6. bordered: PropTypes.bool,
  7. colon: PropTypes.bool,
  8. type: PropTypes.oneOf(['label', 'content']),
  9. layout: PropTypes.oneOf(['horizontal', 'vertical'])
  10. };
  11. var Col = {
  12. functional: true,
  13. props: ColProps,
  14. render: function render(h, ctx) {
  15. var _ref;
  16. var _ctx$props = ctx.props,
  17. child = _ctx$props.child,
  18. bordered = _ctx$props.bordered,
  19. colon = _ctx$props.colon,
  20. type = _ctx$props.type,
  21. layout = _ctx$props.layout;
  22. var _getOptionProps = getOptionProps(child),
  23. prefixCls = _getOptionProps.prefixCls,
  24. _getOptionProps$span = _getOptionProps.span,
  25. span = _getOptionProps$span === undefined ? 1 : _getOptionProps$span;
  26. var key = ctx.data.key;
  27. var label = getComponentFromProp(child, 'label');
  28. var slots = getSlots(child);
  29. var labelProps = {
  30. attrs: {},
  31. 'class': [prefixCls + '-item-label', (_ref = {}, _defineProperty(_ref, prefixCls + '-item-colon', colon), _defineProperty(_ref, prefixCls + '-item-no-label', !label), _ref)],
  32. key: key + '-label'
  33. };
  34. if (layout === 'vertical') {
  35. labelProps.attrs.colSpan = span * 2 - 1;
  36. }
  37. if (bordered) {
  38. if (type === 'label') {
  39. return h(
  40. 'th',
  41. labelProps,
  42. [label]
  43. );
  44. }
  45. return h(
  46. 'td',
  47. { 'class': prefixCls + '-item-content', key: key + '-content', attrs: { colSpan: span * 2 - 1 }
  48. },
  49. [slots['default']]
  50. );
  51. }
  52. if (layout === 'vertical') {
  53. if (type === 'content') {
  54. return h(
  55. 'td',
  56. {
  57. attrs: { colSpan: span },
  58. 'class': prefixCls + '-item' },
  59. [h(
  60. 'span',
  61. { 'class': prefixCls + '-item-content', key: key + '-content' },
  62. [slots['default']]
  63. )]
  64. );
  65. }
  66. return h(
  67. 'td',
  68. {
  69. attrs: { colSpan: span },
  70. 'class': prefixCls + '-item' },
  71. [h(
  72. 'span',
  73. {
  74. 'class': [prefixCls + '-item-label', _defineProperty({}, prefixCls + '-item-colon', colon)],
  75. key: key + '-label'
  76. },
  77. [label]
  78. )]
  79. );
  80. }
  81. return h(
  82. 'td',
  83. {
  84. attrs: { colSpan: span },
  85. 'class': prefixCls + '-item' },
  86. [h(
  87. 'span',
  88. labelProps,
  89. [label]
  90. ), h(
  91. 'span',
  92. { 'class': prefixCls + '-item-content', key: key + '-content' },
  93. [slots['default']]
  94. )]
  95. );
  96. }
  97. };
  98. export default Col;