# Avatar URL: https://ark-ui.com/docs/components/avatar Source: https://raw.githubusercontent.com/chakra-ui/ark/refs/heads/main/website/src/content/pages/components/avatar.mdx A graphical representation of the user, often used in profile sections. --- ## Anatomy ```tsx ``` ## Examples ### Basic Display a user's profile image with a fallback. **Example: basic** ```ripple import { Avatar } from 'ark-ripple/avatar'; import styles from 'styles/avatar.module.css'; export component Basic() { {'PA'} } ``` ### Events Use `onStatusChange` to listen for loading state changes. **Example: events** ```ripple import { Avatar } from 'ark-ripple/avatar'; import { track } from 'ripple'; import styles from 'styles/avatar.module.css'; export component Events() { let status = track('loading...');
{'Status: '} {@status} { @status = e.status; }} > {'PA'}
} ``` ### Root Provider An alternative way to control the avatar is to use the `RootProvider` component and the `useAvatar` hook. This way you can access the state and methods from outside the component. **Example: root-provider** ```ripple import { Avatar } from 'ark-ripple/avatar'; import { useAvatar } from 'ark-ripple/avatar'; import { track } from 'ripple'; import button from 'styles/button.module.css'; import styles from 'styles/avatar.module.css'; export component RootProvider() { let count = track(0); const avatar = useAvatar();
{'PA'}
} ``` ## API Reference ### Props **Component API Reference** **Root Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | | `ids` | `Partial<{ root: string; image: string; fallback: string }>` | No | The ids of the elements in the avatar. Useful for composition. | | `onStatusChange` | `(details: StatusChangeDetails) => void` | No | Functional called when the image loading status changes. | **Fallback Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Fallback Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | avatar | | `[data-part]` | fallback | | `[data-state]` | "hidden" | "visible" | **Image Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | **Image Data Attributes:** | Attribute | Value | |-----------|-------| | `[data-scope]` | avatar | | `[data-part]` | image | | `[data-state]` | "visible" | "hidden" | **RootProvider Props:** | Prop | Type | Required | Description | |------|------|----------|-------------| | `value` | `UseAvatarReturn` | Yes | | | `asChild` | `boolean` | No | Use the provided child element as the default rendered element, combining their props and behavior. | ### Context **API:** | Property | Type | Description | |----------|------|-------------| | `loaded` | `boolean` | Whether the image is loaded. | | `setSrc` | `(src: string) => void` | Function to set new src. | | `setLoaded` | `VoidFunction` | Function to set loaded state. | | `setError` | `VoidFunction` | Function to set error state. |