Skip to content
Likable Aurora @likable-hair/svelte 5

DescriptiveAvatar

Avatar with a title and a subtitle, for example a person with their role in a list, a sidebar or a user menu. The avatar takes its initials and color from title (or name) and is decorative, since the title is written next to it. With onclick the whole thing is a <button>, with href a link: it gets the focus, a hover background and the pointer cursor; otherwise it is a plain <div>. direction="column" stacks the avatar over the centered texts, reverse puts the avatar at the end. With compact only the avatar is shown and the title goes in a Tooltip, for a collapsed sidebar. Everything else works as in Avatar, including its props and --avatar-* variables. Its state is exposed as data-direction, data-reverse, data-compact and data-interactive for app CSS.

import { DescriptiveAvatar } from '@likable-hair/svelte';

src/lib/components/simple/media/DescriptiveAvatar.svelte · Markdown for LLMs

Title and subtitle

The avatar takes its initials and color from the title. direction="column" stacks the avatar over the centered texts; reverse puts it at the end. Long texts are cut with an ellipsis.

GM Giulia Marini Senior Colorist
Sara Bianchi Stylist
Mario Rossi mario.rossi@example.com
Alessandra Bartolomei Montecchi Head of the northern region stores
Code
<script lang="ts">
	import { DescriptiveAvatar } from '@likable-hair/svelte';
</script>

<div class="demo">
	<DescriptiveAvatar title="Giulia Marini" subtitle="Senior Colorist" status="online" />
	<DescriptiveAvatar title="Sara Bianchi" subtitle="Stylist" direction="column" size="lg" />
	<DescriptiveAvatar title="Mario Rossi" subtitle="mario.rossi@example.com" reverse />
	<div class="narrow">
		<DescriptiveAvatar title="Alessandra Bartolomei Montecchi" subtitle="Head of the northern region stores" />
	</div>
</div>

<style>
	.demo {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 32px;
	}

	.narrow {
		width: 200px;
	}
</style>

Clickable

With onclick it is a <button>, with href a link: both get the focus, a hover background and the pointer cursor. disabled turns them off. Without either it is plain content, with no pointer.

Sara Bianchi Link to the profile Anna Greco Card
Code
<script lang="ts">
	import { DescriptiveAvatar } from '@likable-hair/svelte';

	let clicks = $state(0);
</script>

<div class="demo">
	<DescriptiveAvatar title="Giulia Marini" subtitle="Open profile ({clicks})" onclick={() => clicks++} />
	<DescriptiveAvatar title="Sara Bianchi" subtitle="Link to the profile" href="#profile" />
	<DescriptiveAvatar title="Luca Ferri" subtitle="Disabled" onclick={() => clicks++} disabled />
	<DescriptiveAvatar title="Anna Greco" subtitle="Card" direction="column" size="lg" href="#profile" />
</div>

<style>
	.demo {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 16px;
	}
</style>

Compact

compact shows only the avatar and moves the title and subtitle to a Tooltip, for a sidebar that collapses. The accessible name stays the title.

Code
<script lang="ts">
	import { DescriptiveAvatar, Switch } from '@likable-hair/svelte';

	let compact = $state(true);
</script>

<Switch bind:checked={compact} label="Compact" />
<div class="sidebar" class:compact>
	<DescriptiveAvatar title="Giulia Marini" subtitle="Senior Colorist" {compact} onclick={() => {}} />
	<DescriptiveAvatar title="Mario Rossi" subtitle="Manager" {compact} onclick={() => {}} />
</div>

<style>
	.sidebar {
		display: flex;
		flex-direction: column;
		gap: 4px;
		width: 240px;
		margin-top: 16px;
		padding: 8px;
		border: 1px solid var(--global-color-border);
		border-radius: var(--global-radius-lg);
	}

	.sidebar.compact {
		width: fit-content;
	}
</style>

Custom texts

children replaces the title and subtitle, for example to add a badge; avatarSnippet replaces the avatar. The --descriptive-avatar-* variables change gaps, text sizes and colors, and the --avatar-* ones reach the avatar inside.

Giulia Marini Admin Last seen 5 minutes ago
Mario Rossi Manager
Code
<script lang="ts">
	import { Chip, DescriptiveAvatar } from '@likable-hair/svelte';
</script>

<div class="demo">
	<DescriptiveAvatar title="Giulia Marini">
		<span class="name">Giulia Marini <Chip>Admin</Chip></span>
		<span class="meta">Last seen 5 minutes ago</span>
	</DescriptiveAvatar>
	<DescriptiveAvatar
		title="Mario Rossi"
		subtitle="Manager"
		--descriptive-avatar-title-font-size="18px"
		--descriptive-avatar-image-gap="16px"
		--avatar-size="56px"
	/>
</div>

<style>
	.demo {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 32px;
	}

	.name {
		display: flex;
		align-items: center;
		gap: 8px;
		font-weight: 600;
	}

	.meta {
		color: var(--global-color-text-3);
		font-size: 12.5px;
	}
</style>

Props

NameTypeDefaultDescription
title stringMain line, usually a name. It also gives the initials and the color of the avatar, unless name is set.
subtitle stringSecond line, smaller and dimmer, for example a role or an email.
avatarText stringText of the avatar instead of the initials of title.
color 'auto' | 'primary' | 'neutral' | 1 | 2 | 3 | 4 | 5 | 6Background of the avatar: auto one of six gradients picked from colorKey or the title, 1 to 6 a fixed one, primary the brand gradient, neutral grey.
direction 'row' | 'column''row'row: avatar beside the texts; column: avatar above the centered texts.
reverse booleanfalsePuts the avatar after the texts (on the right in a row, below in a column).
compact booleanfalseShows only the avatar, with the title and subtitle in a Tooltip, for example in a collapsed sidebar.
href stringMakes the whole thing a link to this URL.
target '_self' | '_blank' | '_parent' | '_top' | (string & {})Native target of the link (with href). With _blank, rel defaults to noopener noreferrer.
rel stringNative rel of the link (with href).
onclick MouseEventHandler<HTMLElement>Makes the whole thing a <button> that calls this function.
disabled booleanfalseDisables the button, or the link (which loses its href and gets aria-disabled).
descriptiveAvatarElement bindable HTMLElementThe root element: <button> with onclick, <a> with href, else <div>.
class string''Extra classes on the root element.

From Avatar

It accepts the props, snippets and events of Avatar, listed in the tables "From Avatar". Except text, alt, avatarElement.

NameTypeDefaultDescription
src string | BlobImage: a URL, or a Blob/File (for images downloaded with authentication), turned into an object URL that is revoked when it changes or the avatar goes away. An empty string counts as no image.
name stringFull name of the person or thing. It gives the initials, the color and the accessible name.
colorKey string | numberValue that picks the color instead of name, for example the id of the person, so the color does not change when the name does.
size 'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Size: xs 24px, sm 32px, md 40px, lg 56px, xl 80px. Any other size with --avatar-size.
shape 'circle' | 'square''circle'circle or square with rounded corners.
ring booleanfalseDraws a ring around the avatar, for example for the current user or a selected person.
status 'online' | 'away' | 'busy' | 'offline'Shows a status dot in the bottom-right corner; its meaning is added to the accessible name.
statusLabel stringAccessible text of the status. Defaults to "Online", "Away", "Busy" or "Offline", in the language of locale.
icon stringSVG path of the icon shown when there is no image, name or text, for example from @mdi/js. Defaults to a person.
referrerpolicy ReferrerPolicy'no-referrer'Native referrerpolicy of the image. no-referrer lets profile pictures from Google load.
imageLoadingStatus bindable 'loading' | 'success' | 'error'State of the image: loading until it arrives, then success or error; undefined without src. Bind it to react to a broken image.
locale stringBCP 47 locale of the texts (it and en are built in, other languages fall back to English). Defaults to the one set with setDefaultLocale, else en.

It also accepts the native attributes and events of <div> (for example id, title, aria-label, onkeydown), which are forwarded to the element.

Snippets

NameParametersDescription
childrenReplaces the title and subtitle, for example to add a badge or a second line.
avatarSnippetReplaces the avatar.

From Avatar

NameParametersDescription
badgeSnippetReplaces the status dot in the bottom-right corner, for example with a count or a small icon.

CSS variables

For a single instance, pass them as style props: <DescriptiveAvatar --descriptive-avatar-background="tomato">. The --descriptive-avatar-default-* defaults apply to the whole app: override them in :root or in a theme.

It also takes the variables of Avatar.

Per-instance variableDefault
--descriptive-avatar-image-gap
--descriptive-avatar-default-image-gap 12px
--descriptive-avatar-padding
--descriptive-avatar-default-interactive-padding 8px 14px 8px 8px
--descriptive-avatar-default-interactive-reverse-padding 8px 8px 8px 14px
--descriptive-avatar-default-interactive-column-padding 16px
--descriptive-avatar-default-interactive-compact-padding 4px
--descriptive-avatar-border-radius
--descriptive-avatar-default-interactive-border-radius var(--global-radius-full)
--descriptive-avatar-default-interactive-column-border-radius var(--global-radius-lg)
--descriptive-avatar-backgroundtransparent
--descriptive-avatar-color
--descriptive-avatar-default-color var(--global-color-text)
--descriptive-avatar-cursorauto
--descriptive-avatar-hover-background
--descriptive-avatar-default-hover-background var(--global-color-surface-2)
--descriptive-avatar-disabled-opacity
--descriptive-avatar-default-disabled-opacity 0.5
--descriptive-avatar-text-gap
--descriptive-avatar-default-text-gap 2px
--descriptive-avatar-title-color
--descriptive-avatar-default-title-color var(--global-color-text)
--descriptive-avatar-title-font-size
--descriptive-avatar-default-title-font-size 14px
--descriptive-avatar-title-font-weight
--descriptive-avatar-default-title-font-weight 600
--descriptive-avatar-subtitle-color
--descriptive-avatar-default-subtitle-color var(--global-color-text-3)
--descriptive-avatar-subtitle-font-size
--descriptive-avatar-default-subtitle-font-size 12.5px