AvatarButton
HkAvatarButton is the avatar trigger: the round account button at the top of every application face. It owns the shared avatar grammar — the image, the graceful letter fallback when there is no image or it failed to load, and the 28px round footprint — so every face renders it the same way.
- It is a trigger, not a menu: what opens on a press is the host's. For the standard console header that already contains one, see the admin header.
- To show who a piece of content belongs to, without an action, use the avatar rather than a button.
Import
import { HkAvatarButton } from "@celestia-island/hikari";
use hikari_components::theme::AvatarButton;
In the Vue form the component is the named export HkAvatarButton; in the Rust form the function is hikari_components::theme::AvatarButton, so a fence begins with a block-scoped use for it.
Image, letter and empty name
avatarUrl is the picture; username is the letter shown when the picture is missing — the first character, upper-cased — and the image's alt text. With neither, the button shows ?. label is the accessible name of the trigger and should say what it opens, not who the user is.
import { HkAvatarButton } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const row: CSSProperties = { display: "flex", gap: "16px", alignItems: "center" };
const indigo = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%236366f1'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
export default () => (
<div style={row}>
<HkAvatarButton avatarUrl={indigo} username="Hikari" label="Account menu" />
<HkAvatarButton username="Hikari" label="Account menu" />
<HkAvatarButton label="Sign in" />
</div>
);
use hikari_components::theme::AvatarButton;
let indigo = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%236366f1'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
rsx! {
div { style: "display:flex;gap:16px;align-items:center",
AvatarButton {
avatar_url: indigo.to_string(),
username: "Hikari".to_string(),
label: Some("Account menu".to_string()),
}
AvatarButton { username: "Hikari".to_string(), label: Some("Account menu".to_string()) }
AvatarButton { label: Some("Sign in".to_string()) }
}
}
import { HkAvatarButton } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const row: CSSProperties = { display: "flex", gap: "16px", alignItems: "center" };
const indigo = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%236366f1'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
export default () => (
<div style={row}>
<HkAvatarButton avatarUrl={indigo} username="Hikari" label="Account menu" />
<HkAvatarButton username="Hikari" label="Account menu" />
<HkAvatarButton label="Sign in" />
</div>
);use hikari_components::theme::AvatarButton;
let indigo = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%236366f1'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
rsx! {
div { style: "display:flex;gap:16px;align-items:center",
AvatarButton {
avatar_url: indigo.to_string(),
username: "Hikari".to_string(),
label: Some("Account menu".to_string()),
}
AvatarButton { username: "Hikari".to_string(), label: Some("Account menu".to_string()) }
AvatarButton { label: Some("Sign in".to_string()) }
}
}What it opens
popup is the aria-haspopup value — "menu" for a dropdown, "dialog" for a drawer — and expanded is aria-expanded, which says whether that menu is open. A drawer-mode trigger carries no expanded state, since it has none to announce.
import { HkAvatarButton } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const row: CSSProperties = { display: "flex", gap: "16px", alignItems: "center" };
const teal = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%230d9488'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
export default () => (
<div style={row}>
<HkAvatarButton avatarUrl={teal} username="Nadiya" label="Account menu" popup="menu" expanded />
<HkAvatarButton avatarUrl={teal} username="Nadiya" label="Account menu" popup="menu" expanded={false} />
<HkAvatarButton avatarUrl={teal} username="Nadiya" label="Profile drawer" popup="dialog" />
</div>
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use hikari_components::theme::{AvatarButton, AvatarButtonPopup};
let teal = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%230d9488'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
rsx! {
div { style: "display:flex;gap:16px;align-items:center",
AvatarButton {
avatar_url: teal.to_string(),
username: "Nadiya".to_string(),
label: Some("Account menu".to_string()),
popup: Some(AvatarButtonPopup::Menu),
expanded: Some(true),
}
AvatarButton {
avatar_url: teal.to_string(),
username: "Nadiya".to_string(),
label: Some("Account menu".to_string()),
popup: Some(AvatarButtonPopup::Menu),
expanded: Some(false),
}
AvatarButton {
avatar_url: teal.to_string(),
username: "Nadiya".to_string(),
label: Some("Profile drawer".to_string()),
popup: Some(AvatarButtonPopup::Dialog),
}
}
}
import { HkAvatarButton } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const row: CSSProperties = { display: "flex", gap: "16px", alignItems: "center" };
const teal = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%230d9488'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
export default () => (
<div style={row}>
<HkAvatarButton avatarUrl={teal} username="Nadiya" label="Account menu" popup="menu" expanded />
<HkAvatarButton avatarUrl={teal} username="Nadiya" label="Account menu" popup="menu" expanded={false} />
<HkAvatarButton avatarUrl={teal} username="Nadiya" label="Profile drawer" popup="dialog" />
</div>
);use hikari_components::theme::{AvatarButton, AvatarButtonPopup};
let teal = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%230d9488'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
rsx! {
div { style: "display:flex;gap:16px;align-items:center",
AvatarButton {
avatar_url: teal.to_string(),
username: "Nadiya".to_string(),
label: Some("Account menu".to_string()),
popup: Some(AvatarButtonPopup::Menu),
expanded: Some(true),
}
AvatarButton {
avatar_url: teal.to_string(),
username: "Nadiya".to_string(),
label: Some("Account menu".to_string()),
popup: Some(AvatarButtonPopup::Menu),
expanded: Some(false),
}
AvatarButton {
avatar_url: teal.to_string(),
username: "Nadiya".to_string(),
label: Some("Profile drawer".to_string()),
popup: Some(AvatarButtonPopup::Dialog),
}
}
}Interaction
click carries the native MouseEvent. The example is an account switcher: each press advances to the next user, and a new avatarUrl gets a fresh load attempt. A small menu opens alongside and expanded follows it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { ref } from "vue";
import { HkAvatarButton } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const indigo = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%236366f1'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
const teal = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%230d9488'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
const users = [
{ name: "Hikari", avatar: indigo },
{ name: "Nadiya", avatar: teal },
{ name: "Guest", avatar: "" },
];
const box: CSSProperties = { position: "relative", width: "fit-content" };
const menu: CSSProperties = {
position: "absolute",
top: "36px",
left: 0,
minWidth: "160px",
padding: "4px",
border: "1px solid #e4e4e7",
borderRadius: "8px",
background: "#ffffff",
boxShadow: "0 4px 16px rgba(0, 0, 0, 0.12)",
};
export default () => {
const index = ref(0);
const open = ref(false);
const user = () => users[index.value] ?? users[0];
return (
<div style={box}>
<HkAvatarButton
avatarUrl={user().avatar}
username={user().name}
label="Account menu"
popup="menu"
expanded={open.value}
onClick={() => {
index.value = (index.value + 1) % users.length;
open.value = !open.value;
}}
/>
{open.value ? <div style={menu}>Signed in as {user().name}</div> : null}
</div>
);
};
import { ref } from "vue";
import { HkAvatarButton } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const indigo = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%236366f1'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
const teal = "data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2064%2064'%3E%3Crect%20width='64'%20height='64'%20rx='32'%20fill='%230d9488'/%3E%3Ccircle%20cx='32'%20cy='25'%20r='11'%20fill='%23ffffff'/%3E%3Cpath%20d='M12%2058a20%2015%200%200%201%2040%200z'%20fill='%23ffffff'/%3E%3C/svg%3E";
const users = [
{ name: "Hikari", avatar: indigo },
{ name: "Nadiya", avatar: teal },
{ name: "Guest", avatar: "" },
];
const box: CSSProperties = { position: "relative", width: "fit-content" };
const menu: CSSProperties = {
position: "absolute",
top: "36px",
left: 0,
minWidth: "160px",
padding: "4px",
border: "1px solid #e4e4e7",
borderRadius: "8px",
background: "#ffffff",
boxShadow: "0 4px 16px rgba(0, 0, 0, 0.12)",
};
export default () => {
const index = ref(0);
const open = ref(false);
const user = () => users[index.value] ?? users[0];
return (
<div style={box}>
<HkAvatarButton
avatarUrl={user().avatar}
username={user().name}
label="Account menu"
popup="menu"
expanded={open.value}
onClick={() => {
index.value = (index.value + 1) % users.length;
open.value = !open.value;
}}
/>
{open.value ? <div style={menu}>Signed in as {user().name}</div> : null}
</div>
);
};
API
Vue
Props
Emits
Rust
Props — AvatarButton
Notes
- The Rust mirror keeps no state: a failed image load is reported through on_error and remembered only when the host sets the failed prop; clearing it on a new avatar_url is the host's job too.
- Extra attributes fall through to the button element in the Vue form; the Rust form has typed props only.
- The button has no hover veil on purpose: what it opens is a menu, not an avatar editor.
Accessibility
- Always pass label: it is the button's accessible name (aria-label), and it should name the destination — "Account menu", not the user's name.
- Set popup and expanded to match what actually opens; they are what assistive technology announces.
- The image's alt text is the username; the letter fallback carries no text for assistive technology beyond the label.
Related components