On this page

Icon button

Nút chỉ có biểu tượng của Classic: ba size vuông, năm màu, tên truy cập do caller cấp.

Copy page as MarkdownRead Markdown ↗

Key rules

  • Classic: dùng IconButton với size small, medium hoặc large; kích thước vuông lấy từ chatty:h-8 chatty:w-8, chatty:h-10 chatty:w-10, chatty:h-12 chatty:w-12.
  • Classic: luôn truyền aria-label; component không có copy mặc định.
  • Classic: caller muốn vùng bấm lớn hơn thì ghi đè bằng className như chatty:h-11 chatty:w-11 (emoji trong ChatPage).
  • Classic: inline style đặt outline: none nên focus chỉ còn chatty:focus-visible:ring-2.
  • Element chatty-icon-button ở mục Standard là chuẩn chatty-ui port theo; các mục theo surface mô tả component React đang chạy.
On this page

Use when / Avoid

Dùng khi hành động có biểu tượng quen thuộc như đóng hoặc emoji. Dùng Button khi biểu tượng chưa tự giải thích kết quả. Không dùng cho điều hướng nội dung trong câu trả lời; đó là việc của link.

Use instead

Component Use when
IconButton Thao tác chỉ có biểu tượng, cần tên truy cập.
Button Hành động có nhãn chữ hoặc cần variant fill của kit.

Live preview

Standard

Standard
LightDarkDesktopMobile

Element chatty-icon-button: size sm, md, lg và tone; nhãn truy cập qua label.

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
    >
  `;
}

Prototype (cùng icon-button.styles.js và ) là chuẩn: chatty-ui port 1:1 các file này, và chatty-ui/custom-elements.json sinh từ chính prototype. Chưa surface nào dùng element thật; các mục theo surface bên dưới mô tả React đang chạy.

Element

Element Module
chatty-icon-button @avada/chatty-ui/elements/icon-button.js

API

Kind Name Type Default Description
attribute tone neutral, critical, success, caution 'neutral' Màu icon theo ý nghĩa; giá trị lạ quay về neutral.
attribute size sm, md, lg 'md' Kích thước ô vuông, cùng ba bậc của React.
attribute disabled boolean false Chặn kích hoạt, vẫn nhận focus và báo aria-disabled.
attribute href string '' URL http, https, mailto hoặc tel thì render link; URL khác bị bỏ.
attribute label string '' Tên truy cập; bắt buộc vì nội dung chỉ là icon.
event click MouseEvent – Kích hoạt native; bị chặn khi disabled.
slot default – – Icon (SVG hoặc chatty-icon).
part base – – Control native (button hoặc a).
css-property --chatty-icon-button-size – – Kích thước ô vuông; thắng size.
css-property --chatty-icon-button-color – – Màu icon theo tone.
css-property --chatty-icon-button-radius – – Bo góc.

Classic

Standard
LightDarkDesktopMobile

Element chatty-icon-button: size sm, md, lg và tone; nhãn truy cập qua label.

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

Disabled và link 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 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
    >
  `;
}
Current (React), being replaced
LightDarkDesktopMobile

Ba size và năm màu của API `IconButton`.

Show code
icon-button.jsxWrap code linesCopy
import React from 'react';
import {IconButton} from '@avada/chatty-ui/components/icon-button.js';
import {CloseIcon} from '@avada/chatty-ui/icons/CloseIcon.js';
export function Catalogue() {
  return <div className="specimen-grid">
    <section>
      <h4>Sizes</h4>
      <div className="button-list">
        {['small', 'medium', 'large'].map(size => (
          <IconButton key={size} size={size} aria-label={'Close ' + size}><CloseIcon size={20} /></IconButton>
        ))}
      </div>
    </section>
    <section>
      <h4>Colors</h4>
      <div className="button-list">
        {['default', 'primary', 'secondary', 'error', 'inherit'].map(color => (
          <IconButton key={color} color={color} aria-label={'Close ' + color}><CloseIcon size={20} /></IconButton>
        ))}
      </div>
    </section>
  </div>;
}
Current (React), being replaced
LightDarkDesktopMobile

Idle và disabled của `IconButton` small.

Show code
icon-button.jsxWrap code linesCopy
import React from 'react';
import {IconButton} from '@avada/chatty-ui/components/icon-button.js';
import {CloseIcon} from '@avada/chatty-ui/icons/CloseIcon.js';
export function States() {
  return <div className="button-list">
    <IconButton size="small" aria-label="Close"><CloseIcon size={20} /></IconButton>
    <IconButton size="small" aria-label="Close unavailable" disabled><CloseIcon size={20} /></IconButton>
  </div>;
}

Import / element

Component / element Import / file Scope root
IconButton @avada/chatty-ui .chatty-widget > #Avada-FAQ_Widget > .Avada-Faqs_Popup

Anatomy

Part Element
1 Tag native a hoặc button, chọn bằng href.
2 children là biểu tượng do caller cấp.

Placement / order

Context Order
Emoji trong chat Caller đặt IconButton emoji trước vùng gửi; id Insert-Emoji-button, chatty:h-11 chatty:w-11.
Primitive Component nhận children, không tự tạo hàng nhiều nút.

Props

Prop Type Values Default Notes
size string small, medium, large medium Chọn width và height vuông.
color string default, primary, secondary, error, inherit default Chọn màu chữ và nền hover.
disabled boolean true, false undefined Chỉ chuyển cho native button; nhánh href bỏ qua.
href string URL undefined Truthy đổi Tag thành a và thêm chatty:no-underline.
className string CSS classes undefined Gộp cuối, ghi đè size qua tailwind-merge.
style object CSS declarations undefined Merge sau background: 'none', border: 'none', outline: 'none'.
children ReactNode Biểu tượng undefined Không có glyph mặc định.
props attributes Native attrs, handlers, ARIA attributes Caller Spread vào Tag; tên truy cập do caller đặt.

Sizes

Size Height Padding Gap Radius Font role (px/rem) Hit target Breakpoint / mechanism
small 32pxDerived(32px = h-8 × 4px) Không khai báo Không khai báo 8px (chatty:rounded-md) Không có chữ Native box Không override theo viewport
medium 40pxDerived(40px = h-10 × 4px) Không khai báo Không khai báo 8px (chatty:rounded-md) Không có chữ Native box Không override theo viewport
large 48pxDerived(48px = h-12 × 4px) Không khai báo Không khai báo 8px (chatty:rounded-md) Không có chữ Native box Không override theo viewport
Emoji caller 44pxDerived(44px = h-11 × 4px) Không khai báo Không khai báo 8px (chatty:rounded-md) Không có chữ Native box className ghi đè size small

Tokens

Part Token Light Dark
Text default --chatty-foreground #0f172a Merchant --faqsTextColor
Text secondary --chatty-muted-foreground #64748b Merchant --faqsTextColorSecondary
Text primary --chatty-primary #6366f1 #6366f1
Text error --chatty-destructive #ef4444 #ef4444
Hover fill --chatty-muted #f1f5f9 #f1f5f9
Focus ring --chatty-ring Merchant --faqsTextColor, fallback #303030 Merchant --faqsTextColor, fallback #eee
Radius --chatty-radius-md 8px 8px

States

State Trigger Visual change (values) ARIA/attribute
Hover default pointer hover:chatty:bg-muted Không thêm ARIA
Hover primary pointer hover:chatty:bg-primary/10 Không thêm ARIA
Hover error pointer hover:chatty:bg-destructive/10 Không thêm ARIA
Focus-visible keyboard chatty:focus-visible:ring-2; inline outline: 'none' che outline Native focus
Disabled disabled chatty:disabled:opacity-50, chatty:disabled:pointer-events-none Native disabled chỉ trên button
Loading caller Not available built-in Caller aria-busy

Behaviour

Interaction Result
Keyboard Native button nhận Enter/Space; anchor nhận Enter.
Link href đổi sang anchor; disabled không áp lên anchor.

Copy

String i18n key Where
Emoji Emoji aria-label của emoji caller
Caller label Caller-owned Tên truy cập do caller đặt

Source

File Evidence
API và element
Caller emoji
Classic token override

Do / Don't

Accessibility

Surface Role / name Keyboard / focus Live region Contrast pair / ratio
Classic Native button hoặc anchor; tên từ aria-label Button Enter/Space; anchor Enter; focus ring khi focus-visible Caller-owned Default 17.85:1Measured(#0f172a / #ffffff = 17.85:1); secondary 4.76:1Measured(#64748b / #ffffff = 4.76:1)

Target