Row.js 3.7 KB

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