Avatar
Use the Avatar component to display the user's profile photo or some default placeholder.
Usage
Import the Avatar component from @avocado-ui/react and render with the required name prop.
The
Avatarcomponent throws an error when thenameprop is not specified. It is required because it will be used for thetitleandaltof the image.
Multiple Avatars
To render multiple Avatar components, wrap them in an AvatarGroup component from @avocado-ui/react. There might be inconsistencies in rendering if you don't put multiple Avatars in the AvatarGroup
Size
Avatar comes in the following sizes - xs, sm, md, lg and xl. Use the size prop to specify the preferred size
Shape
The default Avatar comes in a round shape. You might want to customize it by setting the shape prop to either round, curve, or square.
Image Source
Most avatars show profile images. If you pass a URI to an image to the src prop, Avatar will render an the image. The src can also be a link to an image on the internet.
Accessibility
The Avatar component shows the value of name prop when you hover on it. If the alt prop is not specified, the value of the name prop is used instead. In cases where the icon prop is provided, the role="img" is provided so screen readers can callout the element as an image.
Background Color
The default primary color looks cool as the background for avatars. But you can change it by specifying a valid color value to the color prop.
Icon
You can render an Icon instead of an actual profile image. Provide an icon element to the icon prop and the Avatar component will handle the rest. I make use of Icons from react-feather in this example.
Props Table
| property | description | type | default |
|---|---|---|---|
| size | size of button | xs, sm, md,lg, number | md |
| shape | shape of button | round, square,curve | round |
| alt | Text to read out to screen readers. If not available, the value of the name is used | string | |
| name | Name to show if image is not available | string | |
| src | Source for avatar image | string | |
| color | color of avatar background when src is not specified | string | |
| icon | icon to show when the src prop is not provided | React.ReactNode |