On this page

chatty-icon-button

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

Copy page as MarkdownRead Markdown ↗

Key rules

  • chatty-icon-button khai báo 5 attribute, 0 property không có attribute, 1 event, 1 slot, 1 part và 3 CSS custom property.
  • Import 1 module @avada/chatty-ui/elements/icon-button.js là define chatty-icon-button; 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 square action or link whose only content is an icon; the label is its accessible name. Class ChattyIconButton.

Attributes

Name Property Type Default Description
tone tone 'neutral' | 'critical' | 'success' | 'caution' 'neutral' Icon colour by meaning; unknown values fall back to neutral.
size size 'sm' | 'md' | 'lg' 'md' Square size: 32, 40 or 48px; touch adds a 44px hit area.
disabled disabled boolean false Blocks activation but stays focusable and reports aria-disabled.
href href string '' http, https, mailto or tel URL renders a link; other schemes are dropped.
label label string '' Accessible name; required because the content is only an icon.

Properties

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

Not declared in the manifest.

Events

Name Detail type Description
click MouseEvent Native activation; blocked while disabled.

Slots

Name Description
default The icon (an SVG or chatty-icon).

Parts

Name Description
base Native interactive control.

CSS custom properties

Name Default Description
--chatty-icon-button-size – Square size; overrides size.
--chatty-icon-button-color – Icon colour scoped by tone.
--chatty-icon-button-radius – Corner radius.

Usage

import '@avada/chatty-ui/tokens/tokens.css';
import {
  ArrowUpIcon,
  IconClose,
  IconExternalLink,
  IconTrash
} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-icon-button prototype chatty-ui ports from (chatty-ui/src/elements/icon-button.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/icon-button.js';

export function Standard() {
  return html`
    <chatty-icon-button size="sm" label="Close chat">${IconClose({size: 20})}</chatty-icon-button>
    <chatty-icon-button label="Close chat">${IconClose({size: 20})}</chatty-icon-button>
    <chatty-icon-button size="lg" label="Send message"
      >${ArrowUpIcon({size: 20})}</chatty-icon-button
    >
    <chatty-icon-button tone="critical" label="Delete message"
      >${IconTrash({size: 20})}</chatty-icon-button
    >
  `;
}

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-icon-button.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/tokens.css';
import {
  ArrowUpIcon,
  IconClose,
  IconExternalLink,
  IconTrash
} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-icon-button prototype chatty-ui ports from (chatty-ui/src/elements/icon-button.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/icon-button.js';

export function Standard() {
  return html`
    <chatty-icon-button size="sm" label="Close chat">${IconClose({size: 20})}</chatty-icon-button>
    <chatty-icon-button label="Close chat">${IconClose({size: 20})}</chatty-icon-button>
    <chatty-icon-button size="lg" label="Send message"
      >${ArrowUpIcon({size: 20})}</chatty-icon-button
    >
    <chatty-icon-button tone="critical" label="Delete message"
      >${IconTrash({size: 20})}</chatty-icon-button
    >
  `;
}
Standard
LightDarkDesktopMobile

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

Show code
chatty-icon-button.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/tokens.css';
import {
  ArrowUpIcon,
  IconClose,
  IconExternalLink,
  IconTrash
} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-icon-button prototype chatty-ui ports from (chatty-ui/src/elements/icon-button.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/icon-button.js';

export function States() {
  return html`
    <chatty-icon-button label="Close chat" disabled>${IconClose({size: 20})}</chatty-icon-button>
    <chatty-icon-button href="https://example.com/help" label="Open help"
      >${IconExternalLink({size: 20})}</chatty-icon-button
    >
  `;
}

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-icon-button.element.jsWrap code linesCopy
import '@avada/chatty-ui/tokens/tokens.css';
import {
  ArrowUpIcon,
  IconClose,
  IconExternalLink,
  IconTrash
} from '@avada/chatty-ui/elements/icon-glyphs.js';
// Standard: the chatty-icon-button prototype chatty-ui ports from (chatty-ui/src/elements/icon-button.js).
import {html} from 'lit';
import '@avada/chatty-ui/elements/icon-button.js';

export function Standard() {
  return html`
    <chatty-icon-button size="sm" label="Close chat">${IconClose({size: 20})}</chatty-icon-button>
    <chatty-icon-button label="Close chat">${IconClose({size: 20})}</chatty-icon-button>
    <chatty-icon-button size="lg" label="Send message"
      >${ArrowUpIcon({size: 20})}</chatty-icon-button
    >
    <chatty-icon-button tone="critical" label="Delete message"
      >${IconTrash({size: 20})}</chatty-icon-button
    >
  `;
}
Part Element Source
1 CSS part base chatty-ui/custom-elements.json

Keyboard

Key Action
Enter / Space Activate the action or link.

Source

  • chatty-ui/custom-elements.json