Row.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. "use client";
  2. import * as React from 'react';
  3. import Cell from './Cell';
  4. import DescriptionsContext from './DescriptionsContext';
  5. function renderCells(items, {
  6. colon,
  7. prefixCls,
  8. bordered
  9. }, {
  10. component,
  11. type,
  12. showLabel,
  13. showContent,
  14. labelStyle: rootLabelStyle,
  15. contentStyle: rootContentStyle,
  16. styles: rootStyles
  17. }) {
  18. return items.map(({
  19. label,
  20. children,
  21. prefixCls: itemPrefixCls = prefixCls,
  22. className,
  23. style,
  24. labelStyle,
  25. contentStyle,
  26. span = 1,
  27. key,
  28. styles
  29. }, index) => {
  30. if (typeof component === 'string') {
  31. return /*#__PURE__*/React.createElement(Cell, {
  32. key: `${type}-${key || index}`,
  33. className: className,
  34. style: style,
  35. styles: {
  36. label: Object.assign(Object.assign(Object.assign(Object.assign({}, rootLabelStyle), rootStyles === null || rootStyles === void 0 ? void 0 : rootStyles.label), labelStyle), styles === null || styles === void 0 ? void 0 : styles.label),
  37. content: Object.assign(Object.assign(Object.assign(Object.assign({}, rootContentStyle), rootStyles === null || rootStyles === void 0 ? void 0 : rootStyles.content), contentStyle), styles === null || styles === void 0 ? void 0 : styles.content)
  38. },
  39. span: span,
  40. colon: colon,
  41. component: component,
  42. itemPrefixCls: itemPrefixCls,
  43. bordered: bordered,
  44. label: showLabel ? label : null,
  45. content: showContent ? children : null,
  46. type: type
  47. });
  48. }
  49. return [/*#__PURE__*/React.createElement(Cell, {
  50. key: `label-${key || index}`,
  51. className: className,
  52. style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, rootLabelStyle), rootStyles === null || rootStyles === void 0 ? void 0 : rootStyles.label), style), labelStyle), styles === null || styles === void 0 ? void 0 : styles.label),
  53. span: 1,
  54. colon: colon,
  55. component: component[0],
  56. itemPrefixCls: itemPrefixCls,
  57. bordered: bordered,
  58. label: label,
  59. type: "label"
  60. }), /*#__PURE__*/React.createElement(Cell, {
  61. key: `content-${key || index}`,
  62. className: className,
  63. style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, rootContentStyle), rootStyles === null || rootStyles === void 0 ? void 0 : rootStyles.content), style), contentStyle), styles === null || styles === void 0 ? void 0 : styles.content),
  64. span: span * 2 - 1,
  65. component: component[1],
  66. itemPrefixCls: itemPrefixCls,
  67. bordered: bordered,
  68. content: children,
  69. type: "content"
  70. })];
  71. });
  72. }
  73. const Row = props => {
  74. const descContext = React.useContext(DescriptionsContext);
  75. const {
  76. prefixCls,
  77. vertical,
  78. row,
  79. index,
  80. bordered
  81. } = props;
  82. if (vertical) {
  83. return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("tr", {
  84. key: `label-${index}`,
  85. className: `${prefixCls}-row`
  86. }, renderCells(row, props, Object.assign({
  87. component: 'th',
  88. type: 'label',
  89. showLabel: true
  90. }, descContext))), /*#__PURE__*/React.createElement("tr", {
  91. key: `content-${index}`,
  92. className: `${prefixCls}-row`
  93. }, renderCells(row, props, Object.assign({
  94. component: 'td',
  95. type: 'content',
  96. showContent: true
  97. }, descContext))));
  98. }
  99. return /*#__PURE__*/React.createElement("tr", {
  100. key: index,
  101. className: `${prefixCls}-row`
  102. }, renderCells(row, props, Object.assign({
  103. component: bordered ? ['th', 'td'] : 'td',
  104. type: 'item',
  105. showLabel: true,
  106. showContent: true
  107. }, descContext)));
  108. };
  109. export default Row;