62c1defdfad96c67b608baed6c8cfd96403cfe8fc86428782d42b2a41883e916afdf7eab53d58b2ed389fdae767a8beae7f8580780d0cbeaa672f2f3a4ca99 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var constants = require('./constants.js');
  5. var index = require('../../../hooks/use-deprecated/index.js');
  6. var useGlobalConfig = require('../../config-provider/src/hooks/use-global-config.js');
  7. var useFormItem = require('../../form/src/hooks/use-form-item.js');
  8. var useFormCommonProps = require('../../form/src/hooks/use-form-common-props.js');
  9. const useButton = (props, emit) => {
  10. index.useDeprecated({
  11. from: "type.text",
  12. replacement: "link",
  13. version: "3.0.0",
  14. scope: "props",
  15. ref: "https://element-plus.org/en-US/component/button.html#button-attributes"
  16. }, vue.computed(() => props.type === "text"));
  17. const buttonGroupContext = vue.inject(constants.buttonGroupContextKey, void 0);
  18. const globalConfig = useGlobalConfig.useGlobalConfig("button");
  19. const { form } = useFormItem.useFormItem();
  20. const _size = useFormCommonProps.useFormSize(vue.computed(() => buttonGroupContext == null ? void 0 : buttonGroupContext.size));
  21. const _disabled = useFormCommonProps.useFormDisabled();
  22. const _ref = vue.ref();
  23. const slots = vue.useSlots();
  24. const _type = vue.computed(() => {
  25. var _a;
  26. return props.type || (buttonGroupContext == null ? void 0 : buttonGroupContext.type) || ((_a = globalConfig.value) == null ? void 0 : _a.type) || "";
  27. });
  28. const autoInsertSpace = vue.computed(() => {
  29. var _a, _b, _c;
  30. return (_c = (_b = props.autoInsertSpace) != null ? _b : (_a = globalConfig.value) == null ? void 0 : _a.autoInsertSpace) != null ? _c : false;
  31. });
  32. const _plain = vue.computed(() => {
  33. var _a, _b, _c;
  34. return (_c = (_b = props.plain) != null ? _b : (_a = globalConfig.value) == null ? void 0 : _a.plain) != null ? _c : false;
  35. });
  36. const _round = vue.computed(() => {
  37. var _a, _b, _c;
  38. return (_c = (_b = props.round) != null ? _b : (_a = globalConfig.value) == null ? void 0 : _a.round) != null ? _c : false;
  39. });
  40. const _text = vue.computed(() => {
  41. var _a, _b, _c;
  42. return (_c = (_b = props.text) != null ? _b : (_a = globalConfig.value) == null ? void 0 : _a.text) != null ? _c : false;
  43. });
  44. const _props = vue.computed(() => {
  45. if (props.tag === "button") {
  46. return {
  47. ariaDisabled: _disabled.value || props.loading,
  48. disabled: _disabled.value || props.loading,
  49. autofocus: props.autofocus,
  50. type: props.nativeType
  51. };
  52. }
  53. return {};
  54. });
  55. const shouldAddSpace = vue.computed(() => {
  56. var _a;
  57. const defaultSlot = (_a = slots.default) == null ? void 0 : _a.call(slots);
  58. if (autoInsertSpace.value && (defaultSlot == null ? void 0 : defaultSlot.length) === 1) {
  59. const slot = defaultSlot[0];
  60. if ((slot == null ? void 0 : slot.type) === vue.Text) {
  61. const text = slot.children;
  62. return /^\p{Unified_Ideograph}{2}$/u.test(text.trim());
  63. }
  64. }
  65. return false;
  66. });
  67. const handleClick = (evt) => {
  68. if (_disabled.value || props.loading) {
  69. evt.stopPropagation();
  70. return;
  71. }
  72. if (props.nativeType === "reset") {
  73. form == null ? void 0 : form.resetFields();
  74. }
  75. emit("click", evt);
  76. };
  77. return {
  78. _disabled,
  79. _size,
  80. _type,
  81. _ref,
  82. _props,
  83. _plain,
  84. _round,
  85. _text,
  86. shouldAddSpace,
  87. handleClick
  88. };
  89. };
  90. exports.useButton = useButton;
  91. //# sourceMappingURL=use-button.js.map