On this page

chatty-image

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

Copy page as MarkdownRead Markdown ↗

Key rules

  • chatty-image khai báo 8 attribute, 0 property không có attribute, 2 event, 0 slot, 1 part và 2 CSS custom property.
  • Import 1 module @avada/chatty-ui/elements/image.js là define chatty-image; 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

An image that reserves its box before loading and falls back to a neutral placeholder. Class ChattyImage.

Attributes

Name Property Type Default Description
src src string '' Image URL; empty or failing shows the neutral placeholder.
alt alt string '' Alternative text; empty marks the image decorative.
ratio ratio string '' CSS aspect-ratio, e.g. 4 / 5; empty uses width/height or the intrinsic ratio.
fit fit 'cover' | 'contain' 'cover' How the image fills a box set by ratio or size.
loading loading 'lazy' | 'eager' 'lazy' Native lazy loading; eager for an image above the fold.
width width number undefined Intrinsic width in pixels; with height it reserves the box before loading.
height height number undefined Intrinsic height in pixels.
failed failed boolean false Set when the source is empty or failed to load; the placeholder is shown.

Properties

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

Not declared in the manifest.

Events

Name Detail type Description
load Event The image (not the placeholder) finished loading.
error Event The source failed; the placeholder is shown and failed is set.

Slots

Not declared in the manifest.

Parts

Name Description
base Native img element.

CSS custom properties

Name Default Description
--chatty-image-radius – Corner radius.
--chatty-image-background – Canvas behind a contained or loading image.

Usage

import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/image.js';
<chatty-image
  src="/fixtures/tote.svg"
  alt="Canvas tote bag"
  ratio="4 / 5"
  fit="contain"
  style="width: 120px"
></chatty-image>
<chatty-image
  src="/fixtures/mug.svg"
  alt="Ceramic mug"
  ratio="1 / 1"
  style="width: 120px; --chatty-image-radius: 14px"
></chatty-image>
<chatty-image
  src="/fixtures/cap.svg"
  alt="Wool cap"
  width="160"
  height="100"
  style="width: 160px"
></chatty-image>

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-image.element.jsWrap code linesCopy
<chatty-image
  src="/fixtures/tote.svg"
  alt="Canvas tote bag"
  ratio="4 / 5"
  fit="contain"
  style="width: 120px"
></chatty-image>
<chatty-image
  src="/fixtures/mug.svg"
  alt="Ceramic mug"
  ratio="1 / 1"
  style="width: 120px; --chatty-image-radius: 14px"
></chatty-image>
<chatty-image
  src="/fixtures/cap.svg"
  alt="Wool cap"
  width="160"
  height="100"
  style="width: 160px"
></chatty-image>
Standard
LightDarkDesktopMobile

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

Show code
chatty-image.element.jsWrap code linesCopy
<chatty-image alt="Missing product image" ratio="4 / 5" style="width: 120px"></chatty-image>
<chatty-image
  src="/fixtures/tote.svg"
  alt="Canvas tote bag"
  ratio="4 / 5"
  fit="contain"
  loading="eager"
  style="width: 120px"
></chatty-image>

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-image.element.jsWrap code linesCopy
<chatty-image
  src="/fixtures/tote.svg"
  alt="Canvas tote bag"
  ratio="4 / 5"
  fit="contain"
  style="width: 120px"
></chatty-image>
<chatty-image
  src="/fixtures/mug.svg"
  alt="Ceramic mug"
  ratio="1 / 1"
  style="width: 120px; --chatty-image-radius: 14px"
></chatty-image>
<chatty-image
  src="/fixtures/cap.svg"
  alt="Wool cap"
  width="160"
  height="100"
  style="width: 160px"
></chatty-image>
Part Element Source
1 CSS part base chatty-ui/custom-elements.json

Keyboard

No element-specific keys.

Source

  • chatty-ui/custom-elements.json