Key rules
chatty-contact-formkhai báo 5 attribute, 4 property không có attribute, 3 event, 1 slot, 3 part và 0 CSS custom property.- Import 1 module
@avada/chatty-ui/elements/contact-form.jslà definechatty-contact-form; 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
Validates contact details locally; the host owns persistence and pending state. Class ChattyContactForm.
Attributes
| Name | Property | Type | Default | Description |
|---|---|---|---|---|
fields |
fields |
array |
['email'] |
Ordered field names or descriptors; payloadKey defaults to key. Descriptors have key, label, optional type (text/ |
description |
description |
string |
'Where can we reply?' |
Form purpose shown before the fields. |
loading |
loading |
boolean |
false |
Keeps fields focusable and read- |
skippable |
skippable |
boolean |
false |
Shows the anonymous option. |
error |
error |
string |
'' |
Host request error. |
Properties
Attributes also expose the properties listed in the Property column above.
| Name | Type | Default | Description |
|---|---|---|---|
values |
object |
{ |
Contact values keyed by each field’s payloadKey. |
required |
object |
{ |
Per- |
strings |
object |
{ |
Translated field, action and validation labels. |
skipping |
boolean |
false |
Host- |
Events
| Name | Detail type | Description |
|---|---|---|
chatty- |
CustomEvent<{ |
Valid contact values. |
chatty- |
CustomEvent<{ |
Anonymous chat requested. |
click |
MouseEvent |
Native contact action click. |
Slots
| Name | Description |
|---|---|
privacy |
Privacy explanation under contact fields. |
Parts
| Name | Description |
|---|---|
base |
Contact form. |
error |
Inline field or host error. |
submit |
Submit button. |
CSS custom properties
Not declared in the manifest.
Usage
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/contact-form.js';
export function Standard() {
return html`<div
@chatty-submit=${(event) => {
event.currentTarget.querySelector('[role=status]').textContent =
`Received: ${event.detail.values.email}`;
}}
>
<chatty-contact-form
.fields=${[
{key: 'email', label: 'Email address', type: 'email', required: true},
{
key: 'description',
payloadKey: 'issue',
label: 'Describe your issue',
type: 'textarea',
required: true,
},
{key: 'order', label: 'Order number', type: 'text'},
]}
>
<small slot="privacy">Your email is used to reply to this conversation.</small>
</chatty-contact-form>
<p role="status"></p>
</div>`;
}
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ộ.
Default: trạng thái mặc định và nội dung mẫu của element.
Show code
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/contact-form.js';
export function Standard() {
return html`<div
@chatty-submit=${(event) => {
event.currentTarget.querySelector('[role=status]').textContent =
`Received: ${event.detail.values.email}`;
}}
>
<chatty-contact-form
.fields=${[
{key: 'email', label: 'Email address', type: 'email', required: true},
{
key: 'description',
payloadKey: 'issue',
label: 'Describe your issue',
type: 'textarea',
required: true,
},
{key: 'order', label: 'Order number', type: 'text'},
]}
>
<small slot="privacy">Your email is used to reply to this conversation.</small>
</chatty-contact-form>
<p role="status"></p>
</div>`;
}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ả.
Anatomy: một instance mặc định riêng, có khoảng trống quanh các phần được đánh số.
Show code
import '@avada/chatty-ui/tokens/tokens.css';
import {html} from 'lit';
import '@avada/chatty-ui/elements/contact-form.js';
export function Standard() {
return html`<div
@chatty-submit=${(event) => {
event.currentTarget.querySelector('[role=status]').textContent =
`Received: ${event.detail.values.email}`;
}}
>
<chatty-contact-form
.fields=${[
{key: 'email', label: 'Email address', type: 'email', required: true},
{
key: 'description',
payloadKey: 'issue',
label: 'Describe your issue',
type: 'textarea',
required: true,
},
{key: 'order', label: 'Order number', type: 'text'},
]}
>
<small slot="privacy">Your email is used to reply to this conversation.</small>
</chatty-contact-form>
<p role="status"></p>
</div>`;
}| Part | Element | Source |
|---|---|---|
| 1 | CSS part base |
chatty- |
| 2 | CSS part error |
chatty- |
| 3 | CSS part submit |
chatty- |
Keyboard
| Key | Action |
|---|---|
| Enter | Validate and submit the contact fields; IME composition does not submit. |
Source
- chatty-ui/custom-elements.json