Avatar
Avatar is a visual representation of a user's profile and identity.
Anatomy
- Background: A randomly selected fill color for the initial-based variant.
- Initials: The first letters of a user’s first and last names in a darker gradient of fill color.
- Stroke: The outer circle for the initial-based variant.
- Image: A user-uploaded image of themselves.
Usage Guidance
When to Use
- Use Avatars to provide a user with a stronger identity or when an access point into their profile provides reasonable benefit.
Behaviors
Pressed States
Pressed states pertain to Avatars in standalone instances only. Avatars that are part of a larger selection item do not have individual pressed behaviors.
Disabled States
Disabled states apply only for non-standalone Avatars, which are a sub-component in a larger composite component such as an Avatar in a list item.
Loading States
The Avatar should not default to a generic user icon when loading. The Avatar has a skeleton that accommodates different background colors when loading.
Examples
Avatars vary on the basis of version, sizing, background, and default color.
Version
Avatars default to their initial-based version unless a user manually uploads a profile photo. The lettering inside the Avatar is based on the two letter English initials of the Western equivalent of a user name.
Sizing
Avatars should feel appropriately sized based on their importance and nearby content. They vary on a scale from XXS to XXL to accommodate an array of different possible use cases:
- XXS: 24 x 24. Please note that it is recommended to use a larger size than XXS for all uses outside of pills.
- XS: 32 x 32
- S: 40 x 40
- M: 48 x 48
- L: 72 x 72
- XL: 96 x 96
- XXL: 120 x 120
Regardless of Avatar sizing, all tap targets are 48x48 or larger.
Background
Against darker gradients, white strokes are used to increase contrast. The initial-based variant stroke becomes white and a white stroke is added around the image-based variant.
Color
Initial-based avatars are randomly assigned a gender neutral and contrast friendly color on a per-user basis.
API Guidelines
Methods
Class name: Avatar
Module name: UIComponentsPlugin
public init(featureData: FeatureMetricsData,context: SemanticContext = .default,imageType: ImageType,avatarSize: AvatarSize,avatarColor: AvatarColor = .chiliMango,isOnDarkBackground: Bool = false,isEnabled: Bool = true,isLoading: Bool = false,onClick: @escaping (() -> Void) = {})
Parameters
| Name | Description | Default values |
|---|---|---|
| featureData | the feature name/context and the screen ID in which the component appears. | |
| context | the SemanticContext. | SemanticContext.default |
| imageType | Type of image for the Avatar to use. | |
| avatarSize | Size of the Avatar UI Component. | |
| avatarColor | Background color of the Avatar UI Component. | chiliMango |
| isOnDarkBackground | Bool indicating if the avatar is being used on a dark background. | false |
| isEnabled | Bool indicating if the avatar is enabled. | true |
| isLoading | Bool indicating if the avatar should show the loading state. | false |
| onClick | Closure that represents an action associated with the avatar tap. | {} |
Accessibility Guidelines
Coming soon...
Anatomy
- Background: A randomly selected fill color for the initial-based variant.
- Initials: The first letters of a user’s first and last names in a darker gradient of fill color.
- Stroke: The outer circle for the initial-based variant.
- Image: A user-uploaded image of themselves.
Usage Guidance
When to Use
- Use Avatars to provide a user with a stronger identity or when an access point into their profile provides reasonable benefit.
Behaviors
Pressed States
Pressed states pertain to Avatars in standalone instances only. Avatars that are part of a larger selection item do not have individual pressed behaviors.
Disabled States
Disabled states apply only for non-standalone Avatars, which are a sub-component in a larger composite component such as an Avatar in a list item.
Loading States
The Avatar should not default to a generic user icon when loading. The Avatar has a skeleton that accommodates different background colors when loading.
Examples
Avatars vary on the basis of version, sizing, background, and default color.
Version
Avatars default to their initial-based version unless a user manually uploads a profile photo. The lettering inside the Avatar is based on the two letter English initials of the Western equivalent of a user name.
Sizing
Avatars should feel appropriately sized based on their importance and nearby content. They vary on a scale from XXS to XXL to accommodate an array of different possible use cases:
- XXS: 24 x 24. Please note that it is recommended to use a larger size than XXS for all uses outside of pills.
- XS: 32 x 32
- S: 40 x 40
- M: 48 x 48
- L: 72 x 72
- XL: 96 x 96
- XXL: 120 x 120
Regardless of Avatar sizing, all tap targets are 48x48 or larger.
Background
Against darker gradients, white strokes are used to increase contrast. The initial-based variant stroke becomes white and a white stroke is added around the image-based variant.
Color
Initial-based avatars are randomly assigned a gender neutral and contrast friendly color on a per-user basis.
API Guidelines
Methods
fun AvatarUiComponent(modifier: Modifier = Modifier,avatarSizeConfig: AvatarSizeConfig = AvatarSizeConfig.S,avatarColorConfig: AvatarColorConfig = AvatarColorConfig.ChiliMango,interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },onColorBackground: Boolean = false,enabled: Boolean = true,isLoading: Boolean = false,initials: String,imageResourceId: Int? = null,bitmap: Bitmap? = null,role: Role? = null,onClick: (() -> Unit)? = null,)
Parameters
| Name | Description | Default values |
|---|---|---|
| avatarSizeConfig | Enum that determines the size of the Avatar. Options: XXS, XS, S, M, L, XL, XXL. | S |
| avatarColorConfig | Enum that determines the color of the Avatar. Options: ChiliMango, FruitPunch, IslandPunch, Plum, Toothpaste, Jewel, Watermelon, GreenApple, Kiwi | ChiliMango |
| interactionSource | The [MutableInteractionSource] representing the stream of Interactions for this [AvatarUiComponent]. You can create and pass in your own remembered [MutableInteractionSource] if you want to observe Interactions and customize the appearance / behavior of this [AvatarUiComponent] in different Interactions. | remember { MutableInteractionSource() } |
| onColorBackground | Boolean to let the component know whether it is being rendered on a dark or light background. The Avatar will change the border color to account for the dark/light background. | false |
| enabled | Controls the enabled state of the button. When false, this button will not be clickable | true |
| isLoading | Boolean that puts the Avatar into a loading state using the skeleton loader ui component when true | false |
| initials | String to be displayed in the Avatar if no image is provided. Will only take the first two characters in the string or the entire string if its less than two characters | true |
| imageResourceId | resource ID of image to be shown in the avatar | null |
| bitmap | alternative option to provide image to be shown in the avatar | null |
| role | Role to be passed in for a11y readout | null |
| onClick | Lambda to be called when the Avatar is clicked | null |
Accessibility Guidelines
Coming soon...
Can't Find What You Need?
Check out our FAQ section which may help you find the information you're looking for. For further information, contact the #canvas or #canvas-kitchannels on Slack.
FAQ Section