chore: use InjectionKey to type and define injected properties (#90)

This commit is contained in:
Romain Hamel
2024-05-06 10:45:36 +02:00
committed by GitHub
parent 63822c3cf6
commit a9a1746486
7 changed files with 70 additions and 58 deletions

View File

@@ -1,9 +1,12 @@
import { inject, provide, computed, type ComputedRef } from 'vue'
import { inject, provide, computed, type ComputedRef, type InjectionKey } from 'vue'
import type { AvatarGroupProps } from '#ui/types'
export const avatarGroupInjectionKey: InjectionKey<ComputedRef<{ size: AvatarGroupProps['size'] }>> = Symbol('nuxt-ui.avatar-group')
export function useAvatarGroup(props: { size: AvatarGroupProps['size'] }) {
const injectedSize = inject<ComputedRef<AvatarGroupProps['size']> | undefined>('avatar-size', undefined)
const size = computed(() => props.size ?? injectedSize?.value)
const injectedSize = inject(avatarGroupInjectionKey, undefined)
const size = computed(() => props.size ?? injectedSize?.value.size)
provide('avatar-size', size)
return {