Cell.mjs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { defineComponent, createVNode as _createVNode } from "vue";
  2. import { isDef, extend, truthProp, unknownProp, numericProp, makeStringProp, createNamespace } from "../utils/index.mjs";
  3. import { useRoute, routeProps } from "../composables/use-route.mjs";
  4. import { Icon } from "../icon/index.mjs";
  5. const [name, bem] = createNamespace("cell");
  6. const cellSharedProps = {
  7. tag: makeStringProp("div"),
  8. icon: String,
  9. size: String,
  10. title: numericProp,
  11. value: numericProp,
  12. label: numericProp,
  13. center: Boolean,
  14. isLink: Boolean,
  15. border: truthProp,
  16. iconPrefix: String,
  17. valueClass: unknownProp,
  18. labelClass: unknownProp,
  19. titleClass: unknownProp,
  20. titleStyle: null,
  21. arrowDirection: String,
  22. required: {
  23. type: [Boolean, String],
  24. default: null
  25. },
  26. clickable: {
  27. type: Boolean,
  28. default: null
  29. }
  30. };
  31. const cellProps = extend({}, cellSharedProps, routeProps);
  32. var stdin_default = defineComponent({
  33. name,
  34. props: cellProps,
  35. setup(props, {
  36. slots
  37. }) {
  38. const route = useRoute();
  39. const renderLabel = () => {
  40. const showLabel = slots.label || isDef(props.label);
  41. if (showLabel) {
  42. return _createVNode("div", {
  43. "class": [bem("label"), props.labelClass]
  44. }, [slots.label ? slots.label() : props.label]);
  45. }
  46. };
  47. const renderTitle = () => {
  48. var _a;
  49. if (slots.title || isDef(props.title)) {
  50. const titleSlot = (_a = slots.title) == null ? void 0 : _a.call(slots);
  51. if (Array.isArray(titleSlot) && titleSlot.length === 0) {
  52. return;
  53. }
  54. return _createVNode("div", {
  55. "class": [bem("title"), props.titleClass],
  56. "style": props.titleStyle
  57. }, [titleSlot || _createVNode("span", null, [props.title]), renderLabel()]);
  58. }
  59. };
  60. const renderValue = () => {
  61. const slot = slots.value || slots.default;
  62. const hasValue = slot || isDef(props.value);
  63. if (hasValue) {
  64. return _createVNode("div", {
  65. "class": [bem("value"), props.valueClass]
  66. }, [slot ? slot() : _createVNode("span", null, [props.value])]);
  67. }
  68. };
  69. const renderLeftIcon = () => {
  70. if (slots.icon) {
  71. return slots.icon();
  72. }
  73. if (props.icon) {
  74. return _createVNode(Icon, {
  75. "name": props.icon,
  76. "class": bem("left-icon"),
  77. "classPrefix": props.iconPrefix
  78. }, null);
  79. }
  80. };
  81. const renderRightIcon = () => {
  82. if (slots["right-icon"]) {
  83. return slots["right-icon"]();
  84. }
  85. if (props.isLink) {
  86. const name2 = props.arrowDirection && props.arrowDirection !== "right" ? `arrow-${props.arrowDirection}` : "arrow";
  87. return _createVNode(Icon, {
  88. "name": name2,
  89. "class": bem("right-icon")
  90. }, null);
  91. }
  92. };
  93. return () => {
  94. var _a;
  95. const {
  96. tag,
  97. size,
  98. center,
  99. border,
  100. isLink,
  101. required
  102. } = props;
  103. const clickable = (_a = props.clickable) != null ? _a : isLink;
  104. const classes = {
  105. center,
  106. required: !!required,
  107. clickable,
  108. borderless: !border
  109. };
  110. if (size) {
  111. classes[size] = !!size;
  112. }
  113. return _createVNode(tag, {
  114. "class": bem(classes),
  115. "role": clickable ? "button" : void 0,
  116. "tabindex": clickable ? 0 : void 0,
  117. "onClick": route
  118. }, {
  119. default: () => {
  120. var _a2;
  121. return [renderLeftIcon(), renderTitle(), renderValue(), renderRightIcon(), (_a2 = slots.extra) == null ? void 0 : _a2.call(slots)];
  122. }
  123. });
  124. };
  125. }
  126. });
  127. export {
  128. cellProps,
  129. cellSharedProps,
  130. stdin_default as default
  131. };