Data display

Avatar

A person shown as a photo, with their initials or an icon when there is no photo. Use it wherever a user is mentioned: a list of members, a comment, the account menu. It also comes as a group of overlapping avatars, as a profile row with the name beside the avatar, and as a menu opened by the avatar.

AL
Blade

A round avatar with the initials "AL". With no photo to show, the initials come from the name.

The signed-in user #

With no name, email, username or user, the avatar shows the authenticated user: their image when the model has one, otherwise their initials. guard picks the auth guard to read the user from. With nobody signed in it shows a generic user icon.

Blade

Photo, initials and icon #

The first shows the photo, and falls back to "AL" if the image fails to load. The second shows "A" on a background color picked from the name, always the same for the same name. The third is not a person: :user="false" keeps the signed-in user out of it, leaving a square blue tile with a bell.

A
Blade

Group #

The avatars overlap in a row. Each item is a user object, a name, or an array of avatar props (['name' => 'Ada', 'src' => '/ada.jpg']). With more items than max, the first four show and a last avatar reads "+3", with "3 more" as its tooltip.

AL BR CS DL +3
Blade

Profile #

Each row has the avatar, the name with the email under it, and the button at the end. Pass name, email and description instead of user when there is no object to read them from.

Blade

Account menu #

The signed-in user's avatar, as a button. Clicking it opens a menu that starts with their profile (avatar, name and email), followed by a separator and the items. With profile, the button itself shows the profile row and the menu has only the items.

Default icon #

icon with no name shows a generic user icon.

Blade

Sizes #

size goes from xs to 3xl; square gives a rounded square.

MS MS MS MS MS MS MS MS
Blade

Colors #

auto picks a stable color from the name; a color name uses its pastel; accent, inverse, filled, outline, ghost and subtle are neutral variants.

AC RC BC EC AC AC IC FC OC GC SC
Blade

Auto colors #

With color='auto' each name always gets the same background.

AL BR CS DL ER FM
Blade

tooltip (true shows the name) and href make the avatar a link.

AL GH AT
Blade

Group sizes and items #

size and square on the group apply to every avatar; an item can be an array of avatar props.

AL BR CS
AL BR CS
Blade

Profile slots #

description replaces the email under the name; prepend, append and actions add content around the profile.

Owner

Maria Silva

Admin Member since 2020
Blade

Profile button #

With profile, the menu button shows the profile row and the menu has only the items. name and email replace the signed-in user.

Reference

tk:avatar
tk:avatar.group
└── tk:avatar ...
tk:avatar.profile
tk:avatar.menu

tk:avatar

Prop Type Default Description
user object | array | bool | null the authenticated user Where name, email, username and image are read from. Only leaving the attribute out falls back to the authenticated user: null (a missing $post->author) or false shows nobody.
guard string the default guard The auth guard the authenticated user comes from.
name string from the user The person's name: gives the initials and the accessible name.
email string from the user Gives the initials when there is no name. With tallkit.avatar.unavatar on, it is what the photo is looked up by.
username string from the user Used like email, when there is none.
src string from the user The URL of the photo. Without it, the user's image, then, with tallkit.avatar.unavatar on, a photo looked up by email or username.
initials string from the name Text shown in place of the derived initials.
icon string | bool false An icon in place of the initials. true uses the mdi:user icon, which is also what shows when there is nothing to derive initials from.
size string md xs, sm, md, lg, xl, 2xl or 3xl.
square bool false A rounded square instead of a circle.
color string neutral gray The background. auto picks a color from the name; a color name (red, blue, emerald...) uses its pastel; accent, inverse, filled, outline, ghost and subtle are neutral variants.
alt string from the name The accessible name. An empty string hides the avatar from screen readers.
tooltip string | bool false A tooltip. true shows the name.
ttl int 30 days With tallkit.avatar.unavatar on, how long a looked-up photo URL is cached, in seconds.

size and square are inherited from tk:avatar.group. With href, route or action the avatar is a link or a button, as in tk:link and tk:button.

Slots

Slot Description
default Content in place of the initials.

Prefixes

Prefix Goes to
image: The <img>.
initials: The element with the initials. initials:single shows one letter instead of two.
icon: The icon.
color:seed With color="auto", the text the color is picked from, in place of the name.
tooltip: The options of the tooltip (tooltip:position, tooltip:delay...).

tk:avatar.group

Prop Type Default Description
items array | Collection none The avatars: each item is a user object, a name, or an array of tk:avatar props.
max int all How many avatars to show. The rest are counted in a last "+N" avatar.
size string md The size of every avatar, and how much they overlap.
square bool false Rounded squares instead of circles.

Slots

Slot Description
default Avatars written by hand, after the ones from items.

tk:avatar.profile

Prop Type Default Description
description string | array | slot the user's description, else the email The text under the name. An array renders a list.
showEmail bool true false leaves the email out when there is no description.
image string from the user The URL of the photo.
size string md The size of the avatar and of the texts.
prepend slot none Content above the name.
append slot none Content under the description.
actions slot none Content at the end of the row, such as buttons.

Takes user, guard, name, email and username as tk:avatar does. Every other attribute goes to the avatar (color, square, icon...).

Slots

Slot Description
default Text under the description.
prepend, append, actions As the props of the same name.

Prefixes

Prefix Goes to
content: The row.
container: The element wrapping the name and the description.
name: The name.
description: The description.
list: The list, when description is an array.
actions: The element wrapping the actions.

tk:avatar.menu

Prop Type Default Description
items array none The menu items, as in tk:menu.
profile bool false Shows the profile row in the button, instead of the avatar alone, and leaves it out of the menu.
size string md The size of the avatar, the profile and the menu.
keepOpen bool false Keeps the menu open after an item is chosen.
animation string | bool the menu's The animation of the menu, as in tk:menu.

Every other attribute goes to the avatar and to the profile (name, email, src, color...).

Slots

Slot Description
default Menu items written by hand, after the ones from items.
prepend Content between the profile and the items.

Prefixes

Prefix Goes to
dropdown: The dropdown: dropdown:position, dropdown:align.
trigger: The button.
avatar: The avatar in the button.
profile: The profile, in the button or in the menu.
menu: The menu.
menu-separator: The separator under the profile.

Customization

Classes and attributes on tk:avatar and tk:avatar.group go to the root element. On tk:avatar.profile they go to the avatar, and on tk:avatar.menu to the avatar and to the profile. To reach another element, prefix the attribute (listed in the Reference above).

blade

Accessibility

An avatar with a name is exposed as an image: role="img" with the name in aria-label, taken from alt, then name, the tooltip text, email or username. The <img> inside is decorative. alt="" hides the whole avatar from screen readers, which is what tk:avatar.profile does, since the name is written beside it. As a link or a button the avatar keeps its own role and takes the name as its label.

tk:avatar.group has role="group"; give it an aria-label saying what the people are. The button of tk:avatar.menu is labelled "Account menu", translated, unless it shows the profile, and it carries aria-haspopup and aria-expanded.

Key Action
Enter, Space On the menu button, opens the menu and moves focus to its first item.
Escape Closes the menu and returns focus to the button.

Inside the menu the keys are those of tk:menu.

Behavior notes

  • Who is shown: an avatar given a name, email or username shows only that person. Given none of them and no user attribute it shows the authenticated user, and initials or slot content alone do not change that: they become the fallback under the signed-in user's photo. Pass :user="false" for an avatar that is not a person; a :user that is null shows nobody too.
  • The photo is the first of src, the user's image, and, with tallkit.avatar.unavatar on, a lookup by email or username. The initials or the icon are rendered under it and show if the image fails to load; that state is kept across Livewire updates.
  • The lookup is off by default (opt-in): set tallkit.avatar.unavatar to true to ask unavatar.io for a photo, which sends it the email or username. It runs after the response is sent, so the first render shows the initials and the photo appears on a later one. The answer is cached for ttl, including "no photo"; a failed request is tried again after an hour.
  • Initials are the first letters of the first and last words of the name ("Ana Maria da Silva" gives "AS"). A single word gives its first two letters ("Maria" gives "Ma"). An email uses the part before the @, split on dots, dashes and underscores.
  • icon wins over the initials, and slot content takes the place of derived initials.
  • In tk:avatar.group, a size or square set on an item wins over the group's.