index-b1054607.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { r as routeProps, u as useRoute } from "./use-route-726f0d0b.js";
  2. import { c as createNamespace, e as extend, z as makeStringProp, n as numericProp, a2 as BORDER_SURROUND, I as Icon, p as preventDefault, w as withInstall } from "./index-487cde8c.js";
  3. import { L as Loading } from "./index-217c49a0.js";
  4. import { d as defineComponent, c as createVNode } from "./index-5e4623ce.js";
  5. const [name, bem] = createNamespace("button");
  6. const buttonProps = extend({}, routeProps, {
  7. tag: makeStringProp("button"),
  8. text: String,
  9. icon: String,
  10. type: makeStringProp("default"),
  11. size: makeStringProp("normal"),
  12. color: String,
  13. block: Boolean,
  14. plain: Boolean,
  15. round: Boolean,
  16. square: Boolean,
  17. loading: Boolean,
  18. hairline: Boolean,
  19. disabled: Boolean,
  20. iconPrefix: String,
  21. nativeType: makeStringProp("button"),
  22. loadingSize: numericProp,
  23. loadingText: String,
  24. loadingType: String,
  25. iconPosition: makeStringProp("left")
  26. });
  27. var stdin_default = defineComponent({
  28. name,
  29. props: buttonProps,
  30. emits: ["click"],
  31. setup(props, {
  32. emit,
  33. slots
  34. }) {
  35. const route = useRoute();
  36. const renderLoadingIcon = () => {
  37. if (slots.loading) {
  38. return slots.loading();
  39. }
  40. return createVNode(Loading, {
  41. "size": props.loadingSize,
  42. "type": props.loadingType,
  43. "class": bem("loading")
  44. }, null);
  45. };
  46. const renderIcon = () => {
  47. if (props.loading) {
  48. return renderLoadingIcon();
  49. }
  50. if (slots.icon) {
  51. return createVNode("div", {
  52. "class": bem("icon")
  53. }, [slots.icon()]);
  54. }
  55. if (props.icon) {
  56. return createVNode(Icon, {
  57. "name": props.icon,
  58. "class": bem("icon"),
  59. "classPrefix": props.iconPrefix
  60. }, null);
  61. }
  62. };
  63. const renderText = () => {
  64. let text;
  65. if (props.loading) {
  66. text = props.loadingText;
  67. } else {
  68. text = slots.default ? slots.default() : props.text;
  69. }
  70. if (text) {
  71. return createVNode("span", {
  72. "class": bem("text")
  73. }, [text]);
  74. }
  75. };
  76. const getStyle = () => {
  77. const {
  78. color,
  79. plain
  80. } = props;
  81. if (color) {
  82. const style = {
  83. color: plain ? color : "white"
  84. };
  85. if (!plain) {
  86. style.background = color;
  87. }
  88. if (color.includes("gradient")) {
  89. style.border = 0;
  90. } else {
  91. style.borderColor = color;
  92. }
  93. return style;
  94. }
  95. };
  96. const onClick = (event) => {
  97. if (props.loading) {
  98. preventDefault(event);
  99. } else if (!props.disabled) {
  100. emit("click", event);
  101. route();
  102. }
  103. };
  104. return () => {
  105. const {
  106. tag,
  107. type,
  108. size,
  109. block,
  110. round,
  111. plain,
  112. square,
  113. loading,
  114. disabled,
  115. hairline,
  116. nativeType,
  117. iconPosition
  118. } = props;
  119. const classes = [bem([type, size, {
  120. plain,
  121. block,
  122. round,
  123. square,
  124. loading,
  125. disabled,
  126. hairline
  127. }]), {
  128. [BORDER_SURROUND]: hairline
  129. }];
  130. return createVNode(tag, {
  131. "type": nativeType,
  132. "class": classes,
  133. "style": getStyle(),
  134. "disabled": disabled,
  135. "onClick": onClick
  136. }, {
  137. default: () => [createVNode("div", {
  138. "class": bem("content")
  139. }, [iconPosition === "left" && renderIcon(), renderText(), iconPosition === "right" && renderIcon()])]
  140. });
  141. };
  142. }
  143. });
  144. const Button = withInstall(stdin_default);
  145. const index = "";
  146. export {
  147. Button as B
  148. };