Cell.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. cellSharedProps: () => cellSharedProps,
  21. default: () => stdin_default
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_vue2 = 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. icon: String,
  32. size: String,
  33. title: import_utils.numericProp,
  34. value: import_utils.numericProp,
  35. label: import_utils.numericProp,
  36. center: Boolean,
  37. isLink: Boolean,
  38. border: import_utils.truthProp,
  39. required: Boolean,
  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. clickable: {
  47. type: Boolean,
  48. default: null
  49. }
  50. };
  51. const cellProps = (0, import_utils.extend)({}, cellSharedProps, import_use_route.routeProps);
  52. var stdin_default = (0, import_vue2.defineComponent)({
  53. name,
  54. props: cellProps,
  55. setup(props, {
  56. slots
  57. }) {
  58. const route = (0, import_use_route.useRoute)();
  59. const renderLabel = () => {
  60. const showLabel = slots.label || (0, import_utils.isDef)(props.label);
  61. if (showLabel) {
  62. return (0, import_vue.createVNode)("div", {
  63. "class": [bem("label"), props.labelClass]
  64. }, [slots.label ? slots.label() : props.label]);
  65. }
  66. };
  67. const renderTitle = () => {
  68. if (slots.title || (0, import_utils.isDef)(props.title)) {
  69. return (0, import_vue.createVNode)("div", {
  70. "class": [bem("title"), props.titleClass],
  71. "style": props.titleStyle
  72. }, [slots.title ? slots.title() : (0, import_vue.createVNode)("span", null, [props.title]), renderLabel()]);
  73. }
  74. };
  75. const renderValue = () => {
  76. const slot = slots.value || slots.default;
  77. const hasValue = slot || (0, import_utils.isDef)(props.value);
  78. if (hasValue) {
  79. const hasTitle = slots.title || (0, import_utils.isDef)(props.title);
  80. return (0, import_vue.createVNode)("div", {
  81. "class": [bem("value", {
  82. alone: !hasTitle
  83. }), props.valueClass]
  84. }, [slot ? slot() : (0, import_vue.createVNode)("span", null, [props.value])]);
  85. }
  86. };
  87. const renderLeftIcon = () => {
  88. if (slots.icon) {
  89. return slots.icon();
  90. }
  91. if (props.icon) {
  92. return (0, import_vue.createVNode)(import_icon.Icon, {
  93. "name": props.icon,
  94. "class": bem("left-icon"),
  95. "classPrefix": props.iconPrefix
  96. }, null);
  97. }
  98. };
  99. const renderRightIcon = () => {
  100. if (slots["right-icon"]) {
  101. return slots["right-icon"]();
  102. }
  103. if (props.isLink) {
  104. const name2 = props.arrowDirection && props.arrowDirection !== "right" ? `arrow-${props.arrowDirection}` : "arrow";
  105. return (0, import_vue.createVNode)(import_icon.Icon, {
  106. "name": name2,
  107. "class": bem("right-icon")
  108. }, null);
  109. }
  110. };
  111. return () => {
  112. var _a, _b;
  113. const {
  114. size,
  115. center,
  116. border,
  117. isLink,
  118. required
  119. } = props;
  120. const clickable = (_a = props.clickable) != null ? _a : isLink;
  121. const classes = {
  122. center,
  123. required,
  124. clickable,
  125. borderless: !border
  126. };
  127. if (size) {
  128. classes[size] = !!size;
  129. }
  130. return (0, import_vue.createVNode)("div", {
  131. "class": bem(classes),
  132. "role": clickable ? "button" : void 0,
  133. "tabindex": clickable ? 0 : void 0,
  134. "onClick": route
  135. }, [renderLeftIcon(), renderTitle(), renderValue(), renderRightIcon(), (_b = slots.extra) == null ? void 0 : _b.call(slots)]);
  136. };
  137. }
  138. });