use-button.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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(() => props.type || (buttonGroupContext == null ? void 0 : buttonGroupContext.type) || "");
  25. const autoInsertSpace = vue.computed(() => {
  26. var _a, _b, _c;
  27. return (_c = (_b = props.autoInsertSpace) != null ? _b : (_a = globalConfig.value) == null ? void 0 : _a.autoInsertSpace) != null ? _c : false;
  28. });
  29. const _props = vue.computed(() => {
  30. if (props.tag === "button") {
  31. return {
  32. ariaDisabled: _disabled.value || props.loading,
  33. disabled: _disabled.value || props.loading,
  34. autofocus: props.autofocus,
  35. type: props.nativeType
  36. };
  37. }
  38. return {};
  39. });
  40. const shouldAddSpace = vue.computed(() => {
  41. var _a;
  42. const defaultSlot = (_a = slots.default) == null ? void 0 : _a.call(slots);
  43. if (autoInsertSpace.value && (defaultSlot == null ? void 0 : defaultSlot.length) === 1) {
  44. const slot = defaultSlot[0];
  45. if ((slot == null ? void 0 : slot.type) === vue.Text) {
  46. const text = slot.children;
  47. return /^\p{Unified_Ideograph}{2}$/u.test(text.trim());
  48. }
  49. }
  50. return false;
  51. });
  52. const handleClick = (evt) => {
  53. if (_disabled.value || props.loading) {
  54. evt.stopPropagation();
  55. return;
  56. }
  57. if (props.nativeType === "reset") {
  58. form == null ? void 0 : form.resetFields();
  59. }
  60. emit("click", evt);
  61. };
  62. return {
  63. _disabled,
  64. _size,
  65. _type,
  66. _ref,
  67. _props,
  68. shouldAddSpace,
  69. handleClick
  70. };
  71. };
  72. exports.useButton = useButton;
  73. //# sourceMappingURL=use-button.js.map