Cell.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_vue2 = require("vue");
  27. var import_utils = require("../utils");
  28. var import_use_route = require("../composables/use-route");
  29. var import_icon = require("../icon");
  30. const [name, bem] = (0, import_utils.createNamespace)("cell");
  31. const cellSharedProps = {
  32. tag: (0, import_utils.makeStringProp)("div"),
  33. icon: String,
  34. size: String,
  35. title: import_utils.numericProp,
  36. value: import_utils.numericProp,
  37. label: import_utils.numericProp,
  38. center: Boolean,
  39. isLink: Boolean,
  40. border: import_utils.truthProp,
  41. required: Boolean,
  42. iconPrefix: String,
  43. valueClass: import_utils.unknownProp,
  44. labelClass: import_utils.unknownProp,
  45. titleClass: import_utils.unknownProp,
  46. titleStyle: null,
  47. arrowDirection: String,
  48. clickable: {
  49. type: Boolean,
  50. default: null
  51. }
  52. };
  53. const cellProps = (0, import_utils.extend)({}, cellSharedProps, import_use_route.routeProps);
  54. var stdin_default = (0, import_vue2.defineComponent)({
  55. name,
  56. props: cellProps,
  57. setup(props, {
  58. slots
  59. }) {
  60. const route = (0, import_use_route.useRoute)();
  61. const renderLabel = () => {
  62. const showLabel = slots.label || (0, import_utils.isDef)(props.label);
  63. if (showLabel) {
  64. return (0, import_vue.createVNode)("div", {
  65. "class": [bem("label"), props.labelClass]
  66. }, [slots.label ? slots.label() : props.label]);
  67. }
  68. };
  69. const renderTitle = () => {
  70. var _a;
  71. if (slots.title || (0, import_utils.isDef)(props.title)) {
  72. const titleSlot = (_a = slots.title) == null ? void 0 : _a.call(slots);
  73. if (Array.isArray(titleSlot) && titleSlot.length === 0) {
  74. return;
  75. }
  76. return (0, import_vue.createVNode)("div", {
  77. "class": [bem("title"), props.titleClass],
  78. "style": props.titleStyle
  79. }, [titleSlot || (0, import_vue.createVNode)("span", null, [props.title]), renderLabel()]);
  80. }
  81. };
  82. const renderValue = () => {
  83. const slot = slots.value || slots.default;
  84. const hasValue = slot || (0, import_utils.isDef)(props.value);
  85. if (hasValue) {
  86. return (0, import_vue.createVNode)("div", {
  87. "class": [bem("value"), props.valueClass]
  88. }, [slot ? slot() : (0, import_vue.createVNode)("span", null, [props.value])]);
  89. }
  90. };
  91. const renderLeftIcon = () => {
  92. if (slots.icon) {
  93. return slots.icon();
  94. }
  95. if (props.icon) {
  96. return (0, import_vue.createVNode)(import_icon.Icon, {
  97. "name": props.icon,
  98. "class": bem("left-icon"),
  99. "classPrefix": props.iconPrefix
  100. }, null);
  101. }
  102. };
  103. const renderRightIcon = () => {
  104. if (slots["right-icon"]) {
  105. return slots["right-icon"]();
  106. }
  107. if (props.isLink) {
  108. const name2 = props.arrowDirection && props.arrowDirection !== "right" ? `arrow-${props.arrowDirection}` : "arrow";
  109. return (0, import_vue.createVNode)(import_icon.Icon, {
  110. "name": name2,
  111. "class": bem("right-icon")
  112. }, null);
  113. }
  114. };
  115. return () => {
  116. var _a;
  117. const {
  118. tag,
  119. size,
  120. center,
  121. border,
  122. isLink,
  123. required
  124. } = props;
  125. const clickable = (_a = props.clickable) != null ? _a : isLink;
  126. const classes = {
  127. center,
  128. required,
  129. clickable,
  130. borderless: !border
  131. };
  132. if (size) {
  133. classes[size] = !!size;
  134. }
  135. return (0, import_vue.createVNode)(tag, {
  136. "class": bem(classes),
  137. "role": clickable ? "button" : void 0,
  138. "tabindex": clickable ? 0 : void 0,
  139. "onClick": route
  140. }, {
  141. default: () => {
  142. var _a2;
  143. return [renderLeftIcon(), renderTitle(), renderValue(), renderRightIcon(), (_a2 = slots.extra) == null ? void 0 : _a2.call(slots)];
  144. }
  145. });
  146. };
  147. }
  148. });