Row.js 4.0 KB

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