index.ts 761 B

123456789101112131415161718192021222324252627282930
  1. import { computed, inject, unref } from 'vue'
  2. import { buildProp } from '@element-plus/utils'
  3. import { componentSizes } from '@element-plus/constants'
  4. import type { InjectionKey, Ref } from 'vue'
  5. import type { ComponentSize } from '@element-plus/constants'
  6. export const useSizeProp = buildProp({
  7. type: String,
  8. values: componentSizes,
  9. required: false,
  10. } as const)
  11. export const useSizeProps = {
  12. size: useSizeProp,
  13. }
  14. export interface SizeContext {
  15. size: Ref<ComponentSize>
  16. }
  17. export const SIZE_INJECTION_KEY: InjectionKey<SizeContext> = Symbol('size')
  18. export const useGlobalSize = () => {
  19. const injectedSize = inject(SIZE_INJECTION_KEY, {} as SizeContext)
  20. return computed<ComponentSize>(() => {
  21. return unref(injectedSize.size) || ''
  22. })
  23. }