Cell.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. cellProps: () => cellProps,
  21. cellSharedProps: () => cellSharedProps,
  22. default: () => stdin_default
  23. });
  24. module.exports = __toCommonJS(stdin_exports);
  25. var import_vue = require("vue");
  26. var import_utils = require("../utils");
  27. var import_use_route = require("../composables/use-route");
  28. var import_icon = require("../icon");
  29. const [name, bem] = (0, import_utils.createNamespace)("cell");
  30. const cellSharedProps = {
  31. tag: (0, import_utils.makeStringProp)("div"),
  32. icon: String,
  33. size: String,
  34. title: import_utils.numericProp,
  35. value: import_utils.numericProp,
  36. label: import_utils.numericProp,
  37. center: Boolean,
  38. isLink: Boolean,
  39. border: import_utils.truthProp,
  40. iconPrefix: String,
  41. valueClass: import_utils.unknownProp,
  42. labelClass: import_utils.unknownProp,
  43. titleClass: import_utils.unknownProp,
  44. titleStyle: null,
  45. arrowDirection: String,
  46. required: {
  47. type: [Boolean, String],
  48. default: null
  49. },
  50. clickable: {
  51. type: Boolean,
  52. default: null
  53. }
  54. };
  55. const cellProps = (0, import_utils.extend)({}, cellSharedProps, import_use_route.routeProps);
  56. var stdin_default = (0, import_vue.defineComponent)({
  57. name,
  58. props: cellProps,
  59. setup(props, {
  60. slots
  61. }) {
  62. const route = (0, import_use_route.useRoute)();
  63. const renderLabel = () => {
  64. const showLabel = slots.label || (0, import_utils.isDef)(props.label);
  65. if (showLabel) {
  66. return (0, import_vue.createVNode)("div", {
  67. "class": [bem("label"), props.labelClass]
  68. }, [slots.label ? slots.label() : props.label]);
  69. }
  70. };
  71. const renderTitle = () => {
  72. var _a;
  73. if (slots.title || (0, import_utils.isDef)(props.title)) {
  74. const titleSlot = (_a = slots.title) == null ? void 0 : _a.call(slots);
  75. if (Array.isArray(titleSlot) && titleSlot.length === 0) {
  76. return;
  77. }
  78. return (0, import_vue.createVNode)("div", {
  79. "class": [bem("title"), props.titleClass],
  80. "style": props.titleStyle
  81. }, [titleSlot || (0, import_vue.createVNode)("span", null, [props.title]), renderLabel()]);
  82. }
  83. };
  84. const renderValue = () => {
  85. const slot = slots.value || slots.default;
  86. const hasValue = slot || (0, import_utils.isDef)(props.value);
  87. if (hasValue) {
  88. return (0, import_vue.createVNode)("div", {
  89. "class": [bem("value"), props.valueClass]
  90. }, [slot ? slot() : (0, import_vue.createVNode)("span", null, [props.value])]);
  91. }
  92. };
  93. const renderLeftIcon = () => {
  94. if (slots.icon) {
  95. return slots.icon();
  96. }
  97. if (props.icon) {
  98. return (0, import_vue.createVNode)(import_icon.Icon, {
  99. "name": props.icon,
  100. "class": bem("left-icon"),
  101. "classPrefix": props.iconPrefix
  102. }, null);
  103. }
  104. };
  105. const renderRightIcon = () => {
  106. if (slots["right-icon"]) {
  107. return slots["right-icon"]();
  108. }
  109. if (props.isLink) {
  110. const name2 = props.arrowDirection && props.arrowDirection !== "right" ? `arrow-${props.arrowDirection}` : "arrow";
  111. return (0, import_vue.createVNode)(import_icon.Icon, {
  112. "name": name2,
  113. "class": bem("right-icon")
  114. }, null);
  115. }
  116. };
  117. return () => {
  118. var _a;
  119. const {
  120. tag,
  121. size,
  122. center,
  123. border,
  124. isLink,
  125. required
  126. } = props;
  127. const clickable = (_a = props.clickable) != null ? _a : isLink;
  128. const classes = {
  129. center,
  130. required: !!required,
  131. clickable,
  132. borderless: !border
  133. };
  134. if (size) {
  135. classes[size] = !!size;
  136. }
  137. return (0, import_vue.createVNode)(tag, {
  138. "class": bem(classes),
  139. "role": clickable ? "button" : void 0,
  140. "tabindex": clickable ? 0 : void 0,
  141. "onClick": route
  142. }, {
  143. default: () => {
  144. var _a2;
  145. return [renderLeftIcon(), renderTitle(), renderValue(), renderRightIcon(), (_a2 = slots.extra) == null ? void 0 : _a2.call(slots)];
  146. }
  147. });
  148. };
  149. }
  150. });