descriptions-cell.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var lodashUnified = require('lodash-unified');
  5. var token = require('./token.js');
  6. var vnode = require('../../../utils/vue/vnode.js');
  7. var style = require('../../../utils/dom/style.js');
  8. var index = require('../../../hooks/use-namespace/index.js');
  9. var ElDescriptionsCell = vue.defineComponent({
  10. name: "ElDescriptionsCell",
  11. props: {
  12. cell: {
  13. type: Object
  14. },
  15. tag: {
  16. type: String,
  17. default: "td"
  18. },
  19. type: {
  20. type: String
  21. }
  22. },
  23. setup() {
  24. const descriptions = vue.inject(token.descriptionsKey, {});
  25. return {
  26. descriptions
  27. };
  28. },
  29. render() {
  30. var _a;
  31. const item = vnode.getNormalizedProps(this.cell);
  32. const directives = (((_a = this.cell) == null ? void 0 : _a.dirs) || []).map((dire) => {
  33. const { dir, arg, modifiers, value } = dire;
  34. return [dir, value, arg, modifiers];
  35. });
  36. const { border, direction } = this.descriptions;
  37. const isVertical = direction === "vertical";
  38. const renderLabel = () => {
  39. var _a2, _b, _c;
  40. return ((_c = (_b = (_a2 = this.cell) == null ? void 0 : _a2.children) == null ? void 0 : _b.label) == null ? void 0 : _c.call(_b)) || item.label;
  41. };
  42. const renderContent = () => {
  43. var _a2, _b, _c;
  44. return (_c = (_b = (_a2 = this.cell) == null ? void 0 : _a2.children) == null ? void 0 : _b.default) == null ? void 0 : _c.call(_b);
  45. };
  46. const span = item.span;
  47. const rowspan = item.rowspan;
  48. const align = item.align ? `is-${item.align}` : "";
  49. const labelAlign = item.labelAlign ? `is-${item.labelAlign}` : align;
  50. const className = item.className;
  51. const labelClassName = item.labelClassName;
  52. const width = this.type === "label" ? item.labelWidth || this.descriptions.labelWidth || item.width : item.width;
  53. const style$1 = {
  54. width: style.addUnit(width),
  55. minWidth: style.addUnit(item.minWidth)
  56. };
  57. const ns = index.useNamespace("descriptions");
  58. switch (this.type) {
  59. case "label":
  60. return vue.withDirectives(vue.h(this.tag, {
  61. style: style$1,
  62. class: [
  63. ns.e("cell"),
  64. ns.e("label"),
  65. ns.is("bordered-label", border),
  66. ns.is("vertical-label", isVertical),
  67. labelAlign,
  68. labelClassName
  69. ],
  70. colSpan: isVertical ? span : 1,
  71. rowspan: isVertical ? 1 : rowspan
  72. }, renderLabel()), directives);
  73. case "content":
  74. return vue.withDirectives(vue.h(this.tag, {
  75. style: style$1,
  76. class: [
  77. ns.e("cell"),
  78. ns.e("content"),
  79. ns.is("bordered-content", border),
  80. ns.is("vertical-content", isVertical),
  81. align,
  82. className
  83. ],
  84. colSpan: isVertical ? span : span * 2 - 1,
  85. rowspan: isVertical ? rowspan * 2 - 1 : rowspan
  86. }, renderContent()), directives);
  87. default: {
  88. const label = renderLabel();
  89. const labelStyle = {};
  90. const width2 = style.addUnit(item.labelWidth || this.descriptions.labelWidth);
  91. if (width2) {
  92. labelStyle.width = width2;
  93. labelStyle.display = "inline-block";
  94. }
  95. return vue.withDirectives(vue.h("td", {
  96. style: style$1,
  97. class: [ns.e("cell"), align],
  98. colSpan: span,
  99. rowspan
  100. }, [
  101. !lodashUnified.isNil(label) ? vue.h("span", {
  102. style: labelStyle,
  103. class: [ns.e("label"), labelClassName]
  104. }, label) : void 0,
  105. vue.h("span", {
  106. class: [ns.e("content"), className]
  107. }, renderContent())
  108. ]), directives);
  109. }
  110. }
  111. }
  112. });
  113. exports["default"] = ElDescriptionsCell;
  114. //# sourceMappingURL=descriptions-cell.js.map