import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; type $RestProps = SvelteHTMLElements["span"] & SvelteHTMLElements["button"] & SvelteHTMLElements["a"]; type $Props = { /** * Specify the size of the avatar. * Defaults to `"md"`, or to the `size` of a parent `UserAvatarGroup`. */ size?: "sm" | "md" | "lg" | "xl" | undefined; /** * Specify the background color rendered behind the initials or icon. * Set to `"auto"` to pick a stable color from `name` (or `initials`). * @default "gray" */ backgroundColor?: "auto" | "red" | "magenta" | "purple" | "blue" | "cyan" | "teal" | "green" | "gray" | "cool-gray" | "warm-gray"; /** * Set to `"strong"` for a fill that stands further from the page: the 80 * step in light themes and the 30 step in dark themes, as in Carbon's * `order-7` to `order-12` colors. Applies to every `backgroundColor`, * including `"auto"`. * @default "default" */ shade?: "default" | "strong"; /** * Specify the user's full name. Initials are derived from the name when `initials` is not set. * Also the default alt text for `image`. Set `imageDescription=""` to mark the * image decorative when the name is already visible next to the avatar. */ name?: string | undefined; /** * Specify the initials to display. Takes priority over initials derived from `name`. */ initials?: string | undefined; /** * Specify an image source to render a photo. * Takes priority over the icon and initials. * If the image fails to load, the avatar falls back to the icon or initials * and dispatches `image:error`. */ image?: string | undefined; /** * Specify alternative text for the image. * Falls back to `imageAttributes.alt`, then `name`. Without either, the * image is marked decorative (`alt=""`). * Set to `""` to mark the image decorative when the name is already visible * next to the avatar, which avoids announcing it twice. */ imageDescription?: string | undefined; /** * Pass additional attributes through to the image element * (for example `loading`, `srcset`, or `referrerPolicy`). * Does not replace `image` or `imageDescription`. Rest props stay on the host. */ imageAttributes?: Record | undefined; /** * Specify the icon to render. Falls back to a default user icon. */ icon?: Icon | undefined; /** * Specify a presence status. Renders a status indicator as the default * `badge` slot content. A custom `badge` slot overrides this. */ status?: "online" | "away" | "busy" | "offline" | undefined; /** * Specify the tooltip text. When set, the avatar is wrapped in a tooltip. * Do not combine with `interactive` or `href` — the tooltip trigger is already * focusable, and nesting an interactive avatar inside it is invalid. */ tooltipText?: string | undefined; /** * Set an id for the avatar element. * With `tooltipText`, the tooltip id derives from it as `{id}-tooltip`. */ id?: string | undefined; /** * Set the alignment of the tooltip relative to the avatar. * @default "center" */ align?: "start" | "center" | "end"; /** * Set the direction of the tooltip relative to the avatar. * @default "bottom" */ direction?: "top" | "bottom"; /** * Set to `false` to render the tooltip inline instead of in a floating portal. * The portal prevents the tooltip from being clipped by the avatar's `overflow: hidden` * frame or an `overflow: hidden` container such as a `Modal`. * @default true */ portalTooltip?: boolean; /** * Set to `true` to render a `button` element instead of a `span`. * Use when the avatar is a clickable control (for example, a custom profile menu * trigger). Prefer this over attaching `on:click` to a non-interactive `span`. * Ignored when `href` is set. * @default false */ interactive?: boolean; /** * Set an `href` to render an anchor element instead of a `span`. * Takes priority over `interactive`. */ href?: string | undefined; /** * Obtain a reference to the avatar HTML element. * @default null */ ref?: null | HTMLElement; /** Overlay content at the bottom-right of the avatar (for example a status dot or `BadgeIndicator`). */ badge?: (this: void) => void; children?: (this: void) => void; [key: `data-${string}`]: unknown; }; export type UserAvatarProps = Omit<$RestProps, keyof $Props> & $Props; export default class UserAvatar extends SvelteComponentTyped< UserAvatarProps, { blur: WindowEventMap["blur"]; click: WindowEventMap["click"]; focus: WindowEventMap["focus"]; /** Dispatched when the `image` URL fails to load. The avatar then falls back to the icon or initials. */ "image:error": CustomEvent; keydown: WindowEventMap["keydown"]; mouseenter: WindowEventMap["mouseenter"]; mouseleave: WindowEventMap["mouseleave"]; mouseover: WindowEventMap["mouseover"]; }, { default: Record; /** Overlay content at the bottom-right of the avatar (for example a status dot or `BadgeIndicator`). */ badge: Record; } > {}