The Placer Toolkit alpha has
arrived! 🎉
Plenty of changes are coming your
way—some big, some breaking, some
even nuclear! Beware the changelog…
Avatar
<pc-avatar> Avatars are used to represent a person or object.
By default, a generic icon will be shown. You can personalise avatars by adding custom icons, initials and images. You should always provide a label for assistive devices.
Demos#
Images#
To use an image for the avatar, set the image and label attributes. This will take priority and be shown over initials and icons. Avatar images can be lazy‐loaded by setting the loading attribute to lazy.
Initials#
When you don’t have an image to use, you can set the initials attribute to show something more personalised than an icon.
Custom icons#
When no image or initials are set, an icon will be shown. The default avatar shows the Font Awesome user icon, but you can customise this with the icon slot.
Shapes#
Avatar shapes can be changed with the shape attribute.
Avatar groups#
You can group avatars into an avatar group with a few lines of CSS.
Properties#
| Name | Description | Reflects | Default |
|---|---|---|---|
image | The image source to use for the avatar. Type: string |
| "" |
label | A label to use to describe the avatar to assistive devices. Type: string |
| "" |
initials | Initials to use as a fallback when no image is available (1–2 characters recommended). Type: string |
| "" |
loading | Indicates how the browser should load the image. Type: "eager" | "lazy" |
| "eager" |
shape | The shape of the avatar. Type: "circle" | "rounded" | "square" |
| "circle" |
updateComplete | A read‐only promise that resolves when the component has finished updating. | ‐ |
Learn more about attributes and properties.
Slots#
| Name | Description |
|---|---|
icon | The default icon to use when no image or initials are present. Works best with <pc-icon>. |
Learn more about using slots.
Events#
| Name | Description | Event detail |
|---|---|---|
pc-error | Emitted when the image couldn’t be loaded. This may be because of an invalid URL, a temporary network error or some other unknown cause. | ‐ |
Learn more about events.
Custom properties#
| Name | Description | Default |
|---|---|---|
--size | The size of the avatar. | 3rem |
Learn more about customising custom properties.
Parts#
| Name | Description |
|---|---|
base | The component’s base wrapper. |
icon | The container that wraps the avatar’s icon. |
initials | The container that wraps the avatar’s initials. |
image | The avatar image. Only shown when the image attribute is set. |
Learn more about customising CSS parts.
Importing#
If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.
To manually import this component from the CDN, copy this code snippet and paste it in your HTML.
<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/avatar/avatar.js"></script> To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.
import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.1/cdn/components/avatar/avatar.js"; To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.
import "placer-toolkit/dist/components/avatar/avatar.js"; Dependencies#
This component automatically imports these components: