bf8b84043999f9dac284b28f8a54fde4f8a76e5d9cf72b5ce50c3f6e82c147fc60d38fc8a3f1fbd95629a4c7ede59115e9df011549ba561c14bbc6b61ddda5 3.2 KB

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