{"version":3,"file":"use-button.mjs","sources":["../../../../../../packages/components/button/src/use-button.ts"],"sourcesContent":["import { computed, inject, ref } from 'vue'\nimport { useConsistentProp } from '@hongluan-ui/hooks'\nimport { formContextKey } from '@hongluan-ui/tokens'\n\nimport type { SetupContext } from 'vue'\nimport type { ButtonEmits, ButtonProps } from './button'\n\nexport const useButton = (\n  props: ButtonProps,\n  emit: SetupContext<ButtonEmits>['emit'],\n) => {\n\n  const _ref = ref<HTMLButtonElement>()\n  const { size: buttonSize, disabled: buttonDisabled } = useConsistentProp()\n  const form = inject(formContextKey, undefined)\n\n  const _props = computed(() => {\n    if (props.tag === 'button') {\n      return {\n        ariaDisabled: buttonDisabled.value || props.loading,\n        disabled: buttonDisabled.value || props.loading,\n        autofocus: props.autofocus,\n        type: props.nativeType,\n      }\n    }\n    return {}\n  })\n\n  const handleClick = (evt: MouseEvent) => {\n    if (props.nativeType === 'reset') {\n      form?.resetFields()\n    }\n    emit('click', evt)\n  }\n\n  return {\n    _ref,\n    _props,\n    buttonDisabled,\n    buttonSize,\n    handleClick,\n  }\n}\n"],"names":[],"mappings":";;;;;;AAGY,MAAC,SAAS,GAAG,CAAC,KAAK,EAAE,IAAI,KAAK;AAC1C,EAAE,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC;AACrB,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,iBAAiB,EAAE,CAAC;AAC7E,EAAE,MAAM,IAAI,GAAG,MAAM,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC,CAAC;AAC9C,EAAE,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM;AAChC,IAAI,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE;AAChC,MAAM,OAAO;AACb,QAAQ,YAAY,EAAE,cAAc,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO;AAC3D,QAAQ,QAAQ,EAAE,cAAc,CAAC,KAAK,IAAI,KAAK,CAAC,OA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