11import type { ComponentPublicInstance , PropType } from 'vue'
22import { computed , defineComponent , h , onMounted , onUnmounted , ref , watch , watchEffect } from 'vue'
3- import type { ComponentPropsWithoutRef } from '@oku-ui/primitive'
3+ import type { ElementRef , MergeProps , PrimitiveProps } from '@oku-ui/primitive'
44import { Primitive } from '@oku-ui/primitive'
55import type { Scope } from '@oku-ui/provide'
66import { createProvideScope } from '@oku-ui/provide'
77import { useCallbackRef } from '@oku-ui/use-callback-ref'
8- import type { MergeProps } from '@oku-ui/utils'
98
109function useImageLoadingStatus ( src ?: string ) {
1110 const loadingStatus = ref < ImageLoadingStatus > ( 'idle' )
@@ -54,9 +53,11 @@ type AvatarProvideValue = {
5453
5554const [ AvatarProvider , useAvatarInject ] = createAvatarProvide < AvatarProvideValue > ( AVATAR_NAME )
5655
57- type AvatarElement = ComponentPropsWithoutRef < typeof Primitive . span >
58- type PrimitiveSpanProps = ComponentPropsWithoutRef < typeof Primitive . span >
59- type AvatarProps = MergeProps < typeof Avatar , PrimitiveSpanProps >
56+ type AvatarElement = ElementRef < 'span' >
57+
58+ interface AvatarProps extends PrimitiveProps {
59+ scopeAvatar ?: Scope
60+ }
6061
6162const Avatar = defineComponent ( {
6263 name : AVATAR_NAME ,
@@ -68,7 +69,7 @@ const Avatar = defineComponent({
6869 } ,
6970 } ,
7071 setup ( props , { attrs, slots, expose } ) {
71- const { ...avatarProps } = attrs as AvatarProps
72+ const { ...avatarProps } = attrs as AvatarElement
7273 const innerRef = ref ( )
7374 const imageLoadingStatus = ref < ImageLoadingStatus > ( 'idle' )
7475
@@ -103,9 +104,12 @@ const Avatar = defineComponent({
103104
104105const IMAGE_NAME = 'AvatarImage'
105106
106- type AvatarImageElement = ComponentPropsWithoutRef < typeof Primitive . img >
107- type PrimitiveImgProps = ComponentPropsWithoutRef < typeof Primitive . img >
108- type AvatarImageProps = MergeProps < typeof AvatarImage , PrimitiveImgProps >
107+ type AvatarImageElement = ElementRef < 'img' >
108+
109+ interface AvatarImageProps extends PrimitiveProps {
110+ onLoadingStatusChange ?: ( status : ImageLoadingStatus ) => void
111+ scopeAvatar ?: Scope
112+ }
109113
110114const AvatarImage = defineComponent ( {
111115 name : IMAGE_NAME ,
@@ -122,7 +126,7 @@ const AvatarImage = defineComponent({
122126 } ,
123127 } ,
124128 setup ( props , { attrs, slots, expose } ) {
125- const { src, ...imageProps } = attrs as AvatarImageProps
129+ const { src, ...imageProps } = attrs as AvatarImageElement
126130 const inject = useAvatarInject ( IMAGE_NAME , props . scopeAvatar )
127131 const innerRef = ref < ComponentPublicInstance > ( )
128132 const imageLoadingStatus = useImageLoadingStatus ( src )
@@ -169,10 +173,11 @@ const AvatarImage = defineComponent({
169173
170174const FALLBACK_NAME = 'AvatarFallback'
171175
172- type PrimitiveAvatarFallbackProps = ComponentPropsWithoutRef < typeof Primitive . span >
173- type PrimitiveSpanElement = ComponentPropsWithoutRef < typeof Primitive . span >
176+ type AvatarFallbackElement = ElementRef < 'span' >
174177
175- type AvatarFallbackProps = MergeProps < typeof AvatarFallback , PrimitiveAvatarFallbackProps >
178+ interface AvatarFallbackProps extends PrimitiveProps {
179+ delayMs ?: number
180+ }
176181
177182const AvatarFallback = defineComponent ( {
178183 name : FALLBACK_NAME ,
@@ -228,20 +233,21 @@ const AvatarFallback = defineComponent({
228233 }
229234
230235 return originalReturn as unknown as {
231- innerRef : PrimitiveSpanElement
236+ innerRef : AvatarFallbackElement
232237 }
233238 } ,
234239} )
235240
236241/* ----------------------------------------------------------------------------------------------- */
237242
238- const OkuAvatar = Avatar as typeof Avatar & ( new ( ) => { $props : AvatarProps } )
239- const OkuAvatarImage = AvatarImage as typeof AvatarImage & ( new ( ) => { $props : AvatarImageProps } )
240- const OkuAvatarFallback = AvatarFallback as typeof AvatarFallback & ( new ( ) => { $props : AvatarFallbackProps } )
243+ // TODO: https://github.com/vuejs/core/pull/7444 after delete
244+ type _OkuAvatarProps = MergeProps < AvatarProps , AvatarElement >
245+ type _OkuAvatarImageProps = MergeProps < AvatarImageProps , AvatarImageElement >
246+ type _OkuAvatarFallbackProps = MergeProps < AvatarFallbackProps , AvatarFallbackElement >
241247
242- type OkuAvatarElement = Omit < InstanceType < typeof Avatar > , keyof ComponentPublicInstance >
243- type OkuAvatarImageElement = Omit < InstanceType < typeof AvatarImage > , keyof ComponentPublicInstance >
244- type OkuAvatarFallbackElement = Omit < InstanceType < typeof AvatarFallback > , keyof ComponentPublicInstance >
248+ const OkuAvatar = Avatar as typeof Avatar & ( new ( ) => { $props : _OkuAvatarProps } )
249+ const OkuAvatarImage = AvatarImage as typeof AvatarImage & ( new ( ) => { $props : _OkuAvatarImageProps } )
250+ const OkuAvatarFallback = AvatarFallback as typeof AvatarFallback & ( new ( ) => { $props : _OkuAvatarFallbackProps } )
245251
246252export {
247253 OkuAvatar ,
@@ -254,7 +260,7 @@ export type {
254260 AvatarProps ,
255261 AvatarImageProps ,
256262 AvatarFallbackProps ,
257- OkuAvatarElement ,
258- OkuAvatarImageElement ,
259- OkuAvatarFallbackElement ,
263+ AvatarElement ,
264+ AvatarImageElement ,
265+ AvatarFallbackElement ,
260266}
0 commit comments