Key rules
chatty-ratingkhai báo 7 attribute, 0 property không có attribute, 2 event, 0 slot, 2 part và 4 CSS custom property.- Import 1 module
@avada/chatty-ui/elements/rating.jslà definechatty-rating; 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 single-choice star rating: a radio group with one tab stop, or a read-only image. Form-associated; the form value is the chosen number. Class ChattyRating.
Attributes
| Name | Property | Type | Default | Description |
|---|---|---|---|---|
value |
value |
number |
0 |
Chosen number; read- |
max |
max |
number |
5 |
Number of stars. |
name |
name |
string |
'' |
Form field name. |
label |
label |
string |
'' |
Group name; in read- |
item- |
itemLabel |
string |
'Rate { |
Star name; { and { are replaced. |
disabled |
disabled |
boolean |
false |
Blocks choosing; stars stay visible and are skipped by Tab. |
readonly |
readonly |
boolean |
false |
Shows the value as one image (role img) instead of a radio group. |
Properties
Attributes also expose the properties listed in the Property column above.
Not declared in the manifest.
Events
| Name | Detail type | Description |
|---|---|---|
change |
Event |
The value changed by click or keyboard. |
click |
MouseEvent |
Native activation of a star. |
Slots
Not declared in the manifest.
Parts
| Name | Description |
|---|---|
base |
Radio group, or the image when read- |
star |
Each star button or read- |
CSS custom properties
| Name | Default | Description |
|---|---|---|
- |
– | Star glyph size. |
- |
– | Star hit target size. |
- |
– | Filled star colour. |
- |
– | Empty star outline colour. |
Usage
import '@avada/chatty-ui/tokens/tokens.css';
import '@avada/chatty-ui/elements/rating.js';
<chatty-rating label="Rate your experience"></chatty-rating>
<chatty-rating label="Rate your experience" value="4"></chatty-rating>
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
<chatty-rating label="Rate your experience"></chatty-rating>
<chatty-rating label="Rate your experience" value="4"></chatty-rating>Các variant hoặc state chính đặt cạnh nhau trong cùng ví dụ.
Show code
<chatty-rating label="Rate your experience" value="3" disabled></chatty-rating>
<chatty-rating readonly value="5" label="Submitted rating 5 out of 5"></chatty-rating>
<chatty-rating
readonly
value="4"
label="Rated 4 out of 5"
style="--chatty-rating-size: 16px"
></chatty-rating>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
<chatty-rating label="Rate your experience"></chatty-rating>
<chatty-rating label="Rate your experience" value="4"></chatty-rating>| Part | Element | Source |
|---|---|---|
| 1 | CSS part base |
chatty- |
| 2 | CSS part star |
chatty- |
Keyboard
| Key | Action |
|---|---|
| Arrow keys | Change the rating when editable. |
| Enter / Space | Choose the focused rating. |
Source
- chatty-ui/custom-elements.json