Row.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { Fragment as _Fragment, createVNode as _createVNode } from "vue";
  3. import Cell from './Cell';
  4. import { getSlot, getClass, getStyle } from '../_util/props-util';
  5. import { inject, ref } from 'vue';
  6. import { descriptionsContext } from './index';
  7. var Row = function Row(props) {
  8. var renderCells = function renderCells(items, _ref, _ref2) {
  9. var colon = _ref.colon,
  10. prefixCls = _ref.prefixCls,
  11. bordered = _ref.bordered;
  12. var component = _ref2.component,
  13. type = _ref2.type,
  14. showLabel = _ref2.showLabel,
  15. showContent = _ref2.showContent,
  16. rootLabelStyle = _ref2.labelStyle,
  17. rootContentStyle = _ref2.contentStyle;
  18. return items.map(function (item, index) {
  19. var _item$children, _item$children$label;
  20. var itemProps = item.props || {};
  21. var _itemProps$prefixCls = itemProps.prefixCls,
  22. itemPrefixCls = _itemProps$prefixCls === void 0 ? prefixCls : _itemProps$prefixCls,
  23. _itemProps$span = itemProps.span,
  24. span = _itemProps$span === void 0 ? 1 : _itemProps$span,
  25. _itemProps$labelStyle = itemProps.labelStyle,
  26. labelStyle = _itemProps$labelStyle === void 0 ? itemProps['label-style'] : _itemProps$labelStyle,
  27. _itemProps$contentSty = itemProps.contentStyle,
  28. contentStyle = _itemProps$contentSty === void 0 ? itemProps['content-style'] : _itemProps$contentSty,
  29. _itemProps$label = itemProps.label,
  30. label = _itemProps$label === void 0 ? (_item$children = item.children) === null || _item$children === void 0 ? void 0 : (_item$children$label = _item$children.label) === null || _item$children$label === void 0 ? void 0 : _item$children$label.call(_item$children) : _itemProps$label;
  31. var children = getSlot(item);
  32. var className = getClass(item);
  33. var style = getStyle(item);
  34. var key = item.key;
  35. if (typeof component === 'string') {
  36. return _createVNode(Cell, {
  37. "key": "".concat(type, "-").concat(String(key) || index),
  38. "class": className,
  39. "style": style,
  40. "labelStyle": _objectSpread(_objectSpread({}, rootLabelStyle), labelStyle),
  41. "contentStyle": _objectSpread(_objectSpread({}, rootContentStyle), contentStyle),
  42. "span": span,
  43. "colon": colon,
  44. "component": component,
  45. "itemPrefixCls": itemPrefixCls,
  46. "bordered": bordered,
  47. "label": showLabel ? label : null,
  48. "content": showContent ? children : null
  49. }, null);
  50. }
  51. return [_createVNode(Cell, {
  52. "key": "label-".concat(String(key) || index),
  53. "class": className,
  54. "style": _objectSpread(_objectSpread(_objectSpread({}, rootLabelStyle), style), labelStyle),
  55. "span": 1,
  56. "colon": colon,
  57. "component": component[0],
  58. "itemPrefixCls": itemPrefixCls,
  59. "bordered": bordered,
  60. "label": label
  61. }, null), _createVNode(Cell, {
  62. "key": "content-".concat(String(key) || index),
  63. "class": className,
  64. "style": _objectSpread(_objectSpread(_objectSpread({}, rootContentStyle), style), contentStyle),
  65. "span": span * 2 - 1,
  66. "component": component[1],
  67. "itemPrefixCls": itemPrefixCls,
  68. "bordered": bordered,
  69. "content": children
  70. }, null)];
  71. });
  72. };
  73. var prefixCls = props.prefixCls,
  74. vertical = props.vertical,
  75. row = props.row,
  76. index = props.index,
  77. bordered = props.bordered;
  78. var _inject = inject(descriptionsContext, {
  79. labelStyle: ref({}),
  80. contentStyle: ref({})
  81. }),
  82. labelStyle = _inject.labelStyle,
  83. contentStyle = _inject.contentStyle;
  84. if (vertical) {
  85. return _createVNode(_Fragment, null, [_createVNode("tr", {
  86. "key": "label-".concat(index),
  87. "class": "".concat(prefixCls, "-row")
  88. }, [renderCells(row, props, {
  89. component: 'th',
  90. type: 'label',
  91. showLabel: true,
  92. labelStyle: labelStyle.value,
  93. contentStyle: contentStyle.value
  94. })]), _createVNode("tr", {
  95. "key": "content-".concat(index),
  96. "class": "".concat(prefixCls, "-row")
  97. }, [renderCells(row, props, {
  98. component: 'td',
  99. type: 'content',
  100. showContent: true,
  101. labelStyle: labelStyle.value,
  102. contentStyle: contentStyle.value
  103. })])]);
  104. }
  105. return _createVNode("tr", {
  106. "key": index,
  107. "class": "".concat(prefixCls, "-row")
  108. }, [renderCells(row, props, {
  109. component: bordered ? ['th', 'td'] : 'td',
  110. type: 'item',
  111. showLabel: true,
  112. showContent: true,
  113. labelStyle: labelStyle.value,
  114. contentStyle: contentStyle.value
  115. })]);
  116. };
  117. export default Row;