|
| 1 | +import { expectType } from '#test-utils'; |
| 2 | +import { |
| 3 | + Avatar, |
| 4 | + type AvatarFallbackProps, |
| 5 | + type AvatarFallbackState, |
| 6 | + type AvatarImageProps, |
| 7 | + type AvatarImageState, |
| 8 | + type AvatarRootProps, |
| 9 | + type AvatarRootState, |
| 10 | + type ImageLoadingStatus, |
| 11 | +} from '@base-ui/react/avatar'; |
| 12 | + |
| 13 | +const rootProps: Avatar.Root.Props = {}; |
| 14 | +expectType<AvatarRootProps, typeof rootProps>(rootProps); |
| 15 | + |
| 16 | +const imageProps: Avatar.Image.Props = { |
| 17 | + crossOrigin: 'anonymous', |
| 18 | + referrerPolicy: 'no-referrer', |
| 19 | + sizes: '48px', |
| 20 | + srcSet: 'avatar.png 1x, avatar@2x.png 2x', |
| 21 | +}; |
| 22 | +expectType<AvatarImageProps, typeof imageProps>(imageProps); |
| 23 | + |
| 24 | +const fallbackProps: Avatar.Fallback.Props = { |
| 25 | + delay: 100, |
| 26 | +}; |
| 27 | +expectType<AvatarFallbackProps, typeof fallbackProps>(fallbackProps); |
| 28 | + |
| 29 | +function expectRootState(state: Avatar.Root.State) { |
| 30 | + expectType<AvatarRootState, typeof state>(state); |
| 31 | + expectType<ImageLoadingStatus, typeof state.imageLoadingStatus>(state.imageLoadingStatus); |
| 32 | +} |
| 33 | + |
| 34 | +function expectImageState(state: Avatar.Image.State) { |
| 35 | + expectType<AvatarImageState, typeof state>(state); |
| 36 | + expectType<ImageLoadingStatus, typeof state.imageLoadingStatus>(state.imageLoadingStatus); |
| 37 | +} |
| 38 | + |
| 39 | +function expectFallbackState(state: Avatar.Fallback.State) { |
| 40 | + expectType<AvatarFallbackState, typeof state>(state); |
| 41 | + expectType<ImageLoadingStatus, typeof state.imageLoadingStatus>(state.imageLoadingStatus); |
| 42 | +} |
| 43 | + |
| 44 | +function expectLoadingStatus(status: ImageLoadingStatus) { |
| 45 | + expectType<ImageLoadingStatus, typeof status>(status); |
| 46 | +} |
| 47 | + |
| 48 | +<Avatar.Root |
| 49 | + {...rootProps} |
| 50 | + render={(props, state) => { |
| 51 | + expectRootState(state); |
| 52 | + return <span {...props} />; |
| 53 | + }} |
| 54 | +> |
| 55 | + <Avatar.Image |
| 56 | + {...imageProps} |
| 57 | + onLoadingStatusChange={(status) => { |
| 58 | + expectLoadingStatus(status); |
| 59 | + }} |
| 60 | + render={(props, state) => { |
| 61 | + expectImageState(state); |
| 62 | + return <img alt="" {...props} />; |
| 63 | + }} |
| 64 | + /> |
| 65 | + <Avatar.Fallback |
| 66 | + {...fallbackProps} |
| 67 | + render={(props, state) => { |
| 68 | + expectFallbackState(state); |
| 69 | + return <span {...props} />; |
| 70 | + }} |
| 71 | + /> |
| 72 | +</Avatar.Root>; |
0 commit comments