On this page

chatty-avatar

API chuẩn của element chatty-avatar, sinh từ custom-elements.json của prototype trong guide.

Copy page as MarkdownRead Markdown ↗

Key rules

  • chatty-avatar khai báo 3 attribute, 0 property không có attribute, 0 event, 1 slot, 2 part và 3 CSS custom property.
  • Import 1 module @avada/chatty-ui/elements/avatar.js là define chatty-avatar; chunk chỉ import element nó dùng. Prototype chuẩn: trong guide.
  • Đổi tên attribute, event, slot, part hay CSS custom property là đổi API: diff của custom-elements.json phải có trong 1 MR.
On this page

Overview

A fixed round frame for an image, initials or a small icon passed through the slot. Class ChattyAvatar.

Attributes

Name Property Type Default Description
size size 'sm' | 'md' | 'lg' 'md' Frame size: 24, 36 or 48px; md matches the React default.
label label string '' Accessible name for initials (role img); for an image use the img alt instead.
status status 'online' | 'offline' | 'break' | 'holiday' | null null Availability resolved by the host; null hides the presence mark.

Properties

Attributes also expose the properties listed in the Property column above.

Not declared in the manifest.

Events

Not declared in the manifest.

Slots

Name Description
default An img (cover-fitted) or fallback initials/icon.

Parts

Name Description
base Round frame.
status Availability dot; absent when status is null.

CSS custom properties

Name Default Description
--chatty-avatar-size – Frame width and height; overrides size.
--chatty-avatar-radius – Corner radius; round by default.
--chatty-avatar-background – Fallback background behind initials.

Usage

import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/avatar.js';
<chatty-avatar size="sm" label="Anna Lee">AL</chatty-avatar>
<chatty-avatar label="Anna Lee">AL</chatty-avatar>
<chatty-avatar size="lg" label="Anna Lee">AL</chatty-avatar>
<chatty-avatar
  ><img
    alt="Blue mug"
    src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 36 36'%3E%3Crect width='36' height='36' fill='gainsboro'/%3E%3Crect x='10' y='12' width='14' height='14' rx='2' fill='slategray'/%3E%3C/svg%3E"
/></chatty-avatar>

Live preview

Component thật dùng cùng story với trang component; dữ liệu mẫu nằm trong frame cục bộ.

Standard
LightDarkDesktopMobile

Default: trạng thái mặc định và nội dung mẫu của element.

Show code
chatty-avatar.element.jsWrap code linesCopy
<chatty-avatar size="sm" label="Anna Lee">AL</chatty-avatar>
<chatty-avatar label="Anna Lee">AL</chatty-avatar>
<chatty-avatar size="lg" label="Anna Lee">AL</chatty-avatar>
<chatty-avatar
  ><img
    alt="Blue mug"
    src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 36 36'%3E%3Crect width='36' height='36' fill='gainsboro'/%3E%3Crect x='10' y='12' width='14' height='14' rx='2' fill='slategray'/%3E%3C/svg%3E"
/></chatty-avatar>
Standard
LightDarkDesktopMobile

Các variant hoặc state chính đặt cạnh nhau trong cùng ví dụ.

Show code
chatty-avatar.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/tokens.css';
// Standard: the chatty-avatar prototype chatty-ui ports from (chatty-ui/src/elements/avatar.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/avatar.js';

export function Status() {
  return html`${['online', 'offline', 'break', 'holiday', null].map(status => html`<chatty-avatar .status=${status} label=${status ?? 'No availability'}>S</chatty-avatar>`)}`;
}

Anatomy

Số trong hình khớp bảng bên dưới. Phần chỉ hiện ở state khác được ghi Not shown; ví dụ không thêm phần tử giả.

Standard
LightDarkDesktopMobile

Anatomy: một instance mặc định riêng, có khoảng trống quanh các phần được đánh số.

Show code
chatty-avatar.element.jsWrap code linesCopy
<chatty-avatar size="sm" label="Anna Lee">AL</chatty-avatar>
<chatty-avatar label="Anna Lee">AL</chatty-avatar>
<chatty-avatar size="lg" label="Anna Lee">AL</chatty-avatar>
<chatty-avatar
  ><img
    alt="Blue mug"
    src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 36 36'%3E%3Crect width='36' height='36' fill='gainsboro'/%3E%3Crect x='10' y='12' width='14' height='14' rx='2' fill='slategray'/%3E%3C/svg%3E"
/></chatty-avatar>
Part Element Source
1 CSS part base chatty-ui/custom-elements.json
2 CSS part status chatty-ui/custom-elements.json

Keyboard

No element-specific keys.

Source

  • chatty-ui/custom-elements.json