Avatar
Show a user’s profile image or initials in a compact, visual element.
Anchor to propertiesProperties
- string
An alternative text that describes the avatar for the reader to understand what it is about or identify the user the avatar belongs to.
- Anchor to initialsinitialsstring
Initials to display in the avatar.
- Anchor to sizesize"small" | "small-200" | "base" | "large" | "large-200"
Size of the avatar.
- string
The URL or path to the image.
Initials will be rendered as a fallback if
src
is not provided, fails to load or does not load quickly
Avatar
- adoptedCallback
() => void
- alt
An alternative text that describes the avatar for the reader to understand what it is about or identify the user the avatar belongs to.
string
- attributeChangedCallback
(name: string) => void
- click
Like the standard `element.click()`, but you can influence the behavior with a `sourceEvent`. For example, if the `sourceEvent` was a middle click, or has particular keys held down, components will attempt to produce the desired behavior on links, such as opening the page in the background tab.
({ sourceEvent }?: ClickOptions) => void
- connectedCallback
() => void
- disconnectedCallback
() => void
- initials
Initials to display in the avatar.
string
- queueRender
Queue a run of the render function. You shouldn't need to call this manually - it should be handled by changes to @property values.
() => void
- setAttribute
(name: string, value: string) => void
- size
Size of the avatar.
"small" | "small-200" | "base" | "large" | "large-200"
- src
The URL or path to the image. Initials will be rendered as a fallback if `src` is not provided, fails to load or does not load quickly
string
declare class Avatar extends PreactCustomElement implements AvatarProps {
accessor initials: AvatarProps['initials'];
accessor src: AvatarProps['src'];
accessor size: AvatarProps['size'];
accessor alt: AvatarProps['alt'];
constructor();
}
ClickOptions
- sourceEvent
The event you want to influence the synthetic click.
ActivationEventEsque
export interface ClickOptions {
/**
* The event you want to influence the synthetic click.
*/
sourceEvent?: ActivationEventEsque;
}
ActivationEventEsque
- button
number
- ctrlKey
boolean
- metaKey
boolean
- shiftKey
boolean
export interface ActivationEventEsque {
shiftKey: boolean;
metaKey: boolean;
ctrlKey: boolean;
button: number;
}
Anchor to eventsEvents
Learn more about registering events.
- Anchor to errorerrorOnErrorEventHandler
- Anchor to loadloadCallbackEventListener<typeof tagName> | null
AvatarEvents
- error
OnErrorEventHandler
- load
CallbackEventListener<typeof tagName> | null
export interface AvatarEvents {
load: CallbackEventListener<typeof tagName> | null = null;
error: OnErrorEventHandler = null;
}
CallbackEventListener
(EventListener & {
(event: CallbackEvent<T>): void;
}) | null
CallbackEvent
Event & {
currentTarget: HTMLElementTagNameMap[T];
}
Code
examples
Code
<s-avatar alt="John Doe" initials="JD" ></s-avatar>
<!DOCTYPE html><html><head><style>html, body {height:100%} body {box-sizing: border-box; margin: 0; padding:0.5rem; display: flex; justify-content: center; align-items: center; gap: 0.5rem;}</style><script src="https://cdn.shopify.com/shopifycloud/app-bridge-ui-experimental.js"></script></head><body><s-avatar alt="John Doe" initials="JD" ></s-avatar> </body></html>