import { computed, inject, ref, unref } from 'vue' import { formContextKey, formItemContextKey } from '@element-plus/tokens' import { buildProp } from '@element-plus/utils' import { componentSizes } from '@element-plus/constants' import { useProp } from '../use-prop' import { useGlobalConfig } from '../use-global-config' import type { ComponentSize } from '@element-plus/constants' import type { MaybeRef } from '@vueuse/core' export const useSizeProp = buildProp({ type: String, values: componentSizes, required: false, } as const) export const useSize = ( fallback?: MaybeRef, ignore: Partial> = {} ) => { const emptyRef = ref(undefined) const size = ignore.prop ? emptyRef : useProp('size') const globalConfig = ignore.global ? emptyRef : useGlobalConfig('size') const form = ignore.form ? { size: undefined } : inject(formContextKey, undefined) const formItem = ignore.formItem ? { size: undefined } : inject(formItemContextKey, undefined) return computed( (): ComponentSize => size.value || unref(fallback) || formItem?.size || form?.size || globalConfig.value || '' ) } export const useDisabled = (fallback?: MaybeRef) => { const disabled = useProp('disabled') const form = inject(formContextKey, undefined) return computed( () => disabled.value || unref(fallback) || form?.disabled || false ) }