button2.mjs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { defineComponent, computed, openBlock, createBlock, resolveDynamicComponent, mergeProps, unref, withCtx, createElementBlock, Fragment, renderSlot, normalizeClass, createCommentVNode } from 'vue';
  2. import { ElIcon } from '../../icon/index.mjs';
  3. import { useButton } from './use-button.mjs';
  4. import { buttonProps, buttonEmits } from './button.mjs';
  5. import { useButtonCustomStyle } from './button-custom.mjs';
  6. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  7. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  8. const __default__ = defineComponent({
  9. name: "ElButton"
  10. });
  11. const _sfc_main = /* @__PURE__ */ defineComponent({
  12. ...__default__,
  13. props: buttonProps,
  14. emits: buttonEmits,
  15. setup(__props, { expose, emit }) {
  16. const props = __props;
  17. const buttonStyle = useButtonCustomStyle(props);
  18. const ns = useNamespace("button");
  19. const { _ref, _size, _type, _disabled, _props, shouldAddSpace, handleClick } = useButton(props, emit);
  20. const buttonKls = computed(() => [
  21. ns.b(),
  22. ns.m(_type.value),
  23. ns.m(_size.value),
  24. ns.is("disabled", _disabled.value),
  25. ns.is("loading", props.loading),
  26. ns.is("plain", props.plain),
  27. ns.is("round", props.round),
  28. ns.is("circle", props.circle),
  29. ns.is("text", props.text),
  30. ns.is("link", props.link),
  31. ns.is("has-bg", props.bg)
  32. ]);
  33. expose({
  34. ref: _ref,
  35. size: _size,
  36. type: _type,
  37. disabled: _disabled,
  38. shouldAddSpace
  39. });
  40. return (_ctx, _cache) => {
  41. return openBlock(), createBlock(resolveDynamicComponent(_ctx.tag), mergeProps({
  42. ref_key: "_ref",
  43. ref: _ref
  44. }, unref(_props), {
  45. class: unref(buttonKls),
  46. style: unref(buttonStyle),
  47. onClick: unref(handleClick)
  48. }), {
  49. default: withCtx(() => [
  50. _ctx.loading ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
  51. _ctx.$slots.loading ? renderSlot(_ctx.$slots, "loading", { key: 0 }) : (openBlock(), createBlock(unref(ElIcon), {
  52. key: 1,
  53. class: normalizeClass(unref(ns).is("loading"))
  54. }, {
  55. default: withCtx(() => [
  56. (openBlock(), createBlock(resolveDynamicComponent(_ctx.loadingIcon)))
  57. ]),
  58. _: 1
  59. }, 8, ["class"]))
  60. ], 64)) : _ctx.icon || _ctx.$slots.icon ? (openBlock(), createBlock(unref(ElIcon), { key: 1 }, {
  61. default: withCtx(() => [
  62. _ctx.icon ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.icon), { key: 0 })) : renderSlot(_ctx.$slots, "icon", { key: 1 })
  63. ]),
  64. _: 3
  65. })) : createCommentVNode("v-if", true),
  66. _ctx.$slots.default ? (openBlock(), createElementBlock("span", {
  67. key: 2,
  68. class: normalizeClass({ [unref(ns).em("text", "expand")]: unref(shouldAddSpace) })
  69. }, [
  70. renderSlot(_ctx.$slots, "default")
  71. ], 2)) : createCommentVNode("v-if", true)
  72. ]),
  73. _: 3
  74. }, 16, ["class", "style", "onClick"]);
  75. };
  76. }
  77. });
  78. var Button = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "button.vue"]]);
  79. export { Button as default };
  80. //# sourceMappingURL=button2.mjs.map