config.mjs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import { isBoolean, isFunction, isNumber } from "../../../utils/types.mjs";
  2. import { getProp } from "../../../utils/objects.mjs";
  3. import { ElIcon } from "../../icon/index.mjs";
  4. import { ElCheckbox } from "../../checkbox/index.mjs";
  5. import { ArrowRight, Loading } from "@element-plus/icons-vue";
  6. import { h } from "vue";
  7. //#region ../../packages/components/table/src/config.ts
  8. const defaultClassNames = {
  9. selection: "table-column--selection",
  10. expand: "table__expand-column"
  11. };
  12. const cellStarts = {
  13. default: { order: "" },
  14. selection: {
  15. width: 48,
  16. minWidth: 48,
  17. realWidth: 48,
  18. order: ""
  19. },
  20. expand: {
  21. width: 48,
  22. minWidth: 48,
  23. realWidth: 48,
  24. order: ""
  25. },
  26. index: {
  27. width: 48,
  28. minWidth: 48,
  29. realWidth: 48,
  30. order: ""
  31. }
  32. };
  33. const getDefaultClassName = (type) => {
  34. return defaultClassNames[type] || "";
  35. };
  36. const cellForced = {
  37. selection: {
  38. renderHeader({ store }) {
  39. function isDisabled() {
  40. return store.states.data.value && store.states.data.value.length === 0;
  41. }
  42. return h(ElCheckbox, {
  43. disabled: isDisabled(),
  44. size: store.states.tableSize.value,
  45. indeterminate: store.states.selection.value.length > 0 && !store.states.isAllSelected.value,
  46. "onUpdate:modelValue": store.toggleAllSelection ?? void 0,
  47. modelValue: store.states.isAllSelected.value,
  48. ariaLabel: store.t("el.table.selectAllLabel")
  49. });
  50. },
  51. renderCell({ row, column, store, $index }) {
  52. return h(ElCheckbox, {
  53. disabled: column.selectable ? !column.selectable.call(null, row, $index) : false,
  54. size: store.states.tableSize.value,
  55. onChange: () => {
  56. store.commit("rowSelectedChanged", row);
  57. },
  58. onClick: (event) => event.stopPropagation(),
  59. modelValue: store.isSelected(row),
  60. indeterminate: store.getRowIndeterminate(row),
  61. ariaLabel: store.t("el.table.selectRowLabel")
  62. });
  63. },
  64. sortable: false,
  65. resizable: false
  66. },
  67. index: {
  68. renderHeader({ column }) {
  69. return column.label || "#";
  70. },
  71. renderCell({ column, $index }) {
  72. let i = $index + 1;
  73. const index = column.index;
  74. if (isNumber(index)) i = $index + index;
  75. else if (isFunction(index)) i = index($index);
  76. return h("div", {}, [i]);
  77. },
  78. sortable: false
  79. },
  80. expand: {
  81. renderHeader({ column }) {
  82. return column.label || "";
  83. },
  84. renderCell({ column, row, store, expanded, $index }) {
  85. const { ns } = store;
  86. const classes = [ns.e("expand-icon")];
  87. if (!column.renderExpand && expanded) classes.push(ns.em("expand-icon", "expanded"));
  88. const callback = function(e) {
  89. e.stopPropagation();
  90. store.toggleRowExpansion(row);
  91. };
  92. const isRowExpandable = store.states.rowExpandable.value?.(row, $index) ?? true;
  93. if (!isRowExpandable) classes.push(ns.is("disabled"));
  94. return h("button", {
  95. type: "button",
  96. disabled: !isRowExpandable,
  97. "aria-label": store.t(expanded ? "el.table.collapseRowLabel" : "el.table.expandRowLabel"),
  98. "aria-expanded": expanded,
  99. class: classes,
  100. onClick: callback
  101. }, { default: () => {
  102. if (column.renderExpand) return [column.renderExpand({
  103. expanded,
  104. expandable: isRowExpandable
  105. })];
  106. return [h(ElIcon, null, { default: () => {
  107. return [h(ArrowRight)];
  108. } })];
  109. } });
  110. },
  111. sortable: false,
  112. resizable: false
  113. }
  114. };
  115. function defaultRenderCell({ row, column, $index }) {
  116. const property = column.property;
  117. const value = property && getProp(row, property).value;
  118. if (column && column.formatter) return column.formatter(row, column, value, $index);
  119. return value?.toString?.() || "";
  120. }
  121. function treeCellPrefix({ row, treeNode, store }, createPlaceholder = false) {
  122. const { ns } = store;
  123. if (!treeNode) {
  124. if (createPlaceholder) return [h("span", { class: ns.e("placeholder") })];
  125. return null;
  126. }
  127. const ele = [];
  128. const callback = function(e) {
  129. e.stopPropagation();
  130. if (treeNode.loading) return;
  131. store.loadOrToggle(row);
  132. };
  133. if (treeNode.indent) ele.push(h("span", {
  134. class: ns.e("indent"),
  135. style: { "padding-left": `${treeNode.indent}px` }
  136. }));
  137. if (isBoolean(treeNode.expanded) && !treeNode.noLazyChildren) {
  138. const expandClasses = [ns.e("expand-icon"), treeNode.expanded ? ns.em("expand-icon", "expanded") : ""];
  139. let icon = ArrowRight;
  140. if (treeNode.loading) icon = Loading;
  141. ele.push(h("button", {
  142. type: "button",
  143. "aria-label": store.t(treeNode.expanded ? "el.table.collapseRowLabel" : "el.table.expandRowLabel"),
  144. "aria-expanded": treeNode.expanded,
  145. class: expandClasses,
  146. onClick: callback
  147. }, { default: () => {
  148. return [h(ElIcon, { class: ns.is("loading", treeNode.loading) }, { default: () => [h(icon)] })];
  149. } }));
  150. } else ele.push(h("span", { class: ns.e("placeholder") }));
  151. return ele;
  152. }
  153. //#endregion
  154. export { cellForced, cellStarts, defaultRenderCell, getDefaultClassName, treeCellPrefix };
  155. //# sourceMappingURL=config.mjs.map