Avatar
Displays user or entity images with a fallback option for failed loading, ensuring consistent visual representation.
<script lang="ts">
import * as Avatar from "@/components//ui/avatar";
</script>
<Avatar.Root>
<Avatar.Image
src="https://github.com/huntabyte.png"
alt="@huntabyte"
/>
<Avatar.Fallback>HB</Avatar.Fallback>
</Avatar.Root>
<script lang="ts">
import * as Avatar from "@/components//ui/avatar";
</script>
<Avatar.Root>
<Avatar.Image
src="https://github.com/huntabyte.png"
alt="@huntabyte"
/>
<Avatar.Fallback>HB</Avatar.Fallback>
</Avatar.Root>
Structure
<script lang="ts">
import { Avatar } from "bits-ui";
</script>
<Avatar.Root>
<Avatar.Image />
<Avatar.Fallback />
</Avatar.Root>
<script lang="ts">
import { Avatar } from "bits-ui";
</script>
<Avatar.Root>
<Avatar.Image />
<Avatar.Fallback />
</Avatar.Root>
Component API
The root component used to set and manage the state of the avatar.
Property | Type | Description |
---|---|---|
delayMs | number | How long to wait before showing the image after it has loaded. This can be useful to prevent a harsh flickering effect when the image loads quickly. Default:
0 |
loadingStatus | 'loading' | 'loaded' | 'error' | The loading status of the avatars source image. You can bind a variable to track the status outside of the component and use it to show a loading indicator or error message. Default:
—— undefined |
onLoadingStatusChange | (status: 'loading' | 'loaded' | 'error') => void | A callback function called when the loading status of the image changes. Default:
—— undefined |
The avatar image displayed once it has loaded.
Property | Type | Description |
---|---|---|
src | string | The source of the image. This is typed the same as the native Default:
—— undefined |
alt | string | The alt text of the image. This is typed the same as the native Default:
—— undefined |
asChild | boolean | Whether to use render delegation with this component or not. Default:
false |
The fallback displayed while the avatar image is loading or if it fails to load
Property | Type | Description |
---|---|---|
asChild | boolean | Whether to use render delegation with this component or not. Default:
false |
🚧 UNDER CONSTRUCTION 🚧