Rating
Поле для выбора оценки из ряда звёзд.
- Браузеры
- Chrome 123+, Firefox 121+, Safari 17.5+
- Уровень
- 0
- Сжатый размер
- 1.22 kB
- Лимит принудительной компоновки
- 0 ms
- Лимит axe
- 0
- Совместим с SSR
- Да
- На основе
- elements/choice
- Публичный контракт
- Тестовый стенд
Песочница
Rating
По умолчанию
- 1
- 2
- 3
- 4
- 5
import { Rating } from "@gunkin/uiify";
export default function Example() {
return <Rating className="" defaultValue={3} id="movie-rating" />;
}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
/* Rating — a native radio group of stars. Inputs are visually hidden;
flex-direction: row-reverse restores left-to-right visual order over
reversed DOM order. Each input+label pair sits in its own [data-part="item"]
wrapper (ChoiceGroup's shape), so `~` alone can't reach across pairs —
`:has()` promotes a checked/hovered item onto its later (= more-preferred,
thanks to row-reverse) sibling wrappers. This keeps the uncontrolled rating functional without
JavaScript. */
@layer components {
[data-uiify-rating] {
display: inline-flex;
flex-direction: row-reverse;
gap: var(--space-xs);
}
[data-uiify-rating] > [data-part="item"] > input {
position: absolute;
inline-size: 1px;
block-size: 1px;
margin: -1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
[data-uiify-rating] > [data-part="item"] > label {
display: inline-flex;
align-items: center;
justify-content: center;
color: var(--input);
font-size: 1.5rem;
line-height: 1;
cursor: pointer;
transition: var(--transition-colors);
}
[data-uiify-rating] > [data-part="item"]:has(> input:checked) > label,
[data-uiify-rating] > [data-part="item"]:has(> input:checked) ~ [data-part="item"] > label {
color: var(--primary);
}
[data-uiify-rating]:not([data-disabled], [data-readonly])
> [data-part="item"]:has(> label:hover)
> label,
[data-uiify-rating]:not([data-disabled], [data-readonly])
> [data-part="item"]:has(> label:hover)
~ [data-part="item"]
> label {
color: var(--primary);
}
[data-uiify-rating] > [data-part="item"] > input:focus-visible ~ label {
outline: none;
box-shadow: 0 0 0 var(--ring-width) color-mix(in oklch, var(--ring) 16%, transparent);
border-radius: var(--radius-xs);
corner-shape: squircle;
}
[data-uiify-rating][data-readonly] > [data-part="item"] > label {
cursor: default;
}
[data-uiify-rating][data-disabled] > [data-part="item"] > label {
cursor: default;
opacity: 0.5;
}
}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
import { Rating } from "@gunkin/uiify";
export default function Example() {
return (
<Rating
className={
"inline-flex [flex-direction:row-reverse] gap-xs [&>[data-part=item]>input]:absolute [&>[data-part=item]>inp" +
"ut]:[inline-size:1px] [&>[data-part=item]>input]:[block-size:1px] [&>[data-part=item]>input]:[margin:-1px] " +
"[&>[data-part=item]>input]:overflow-hidden [&>[data-part=item]>input]:[clip-path:inset(50%)] [&>[data-part=" +
"item]>input]:whitespace-nowrap [&>[data-part=item]>label]:inline-flex [&>[data-part=item]>label]:items-cent" +
"er [&>[data-part=item]>label]:justify-center [&>[data-part=item]>label]:text-input [&>[data-part=item]>labe" +
"l]:[font-size:1.5rem] [&>[data-part=item]>label]:leading-none [&>[data-part=item]>label]:cursor-pointer [&>" +
"[data-part=item]>label]:[transition:var(--transition-colors)] [&>[data-part=item]:has(>input:checked)>label" +
"]:text-primary [&>[data-part=item]:has(>input:checked)~[data-part=item]>label]:text-primary [&:not([data-di" +
"sabled],[data-readonly])>[data-part=item]:has(>label:hover)>label]:text-primary [&:not([data-disabled],[dat" +
"a-readonly])>[data-part=item]:has(>label:hover)~[data-part=item]>label]:text-primary [&>[data-part=item]>in" +
"put:focus-visible~label]:[outline:none] [&>[data-part=item]>input:focus-visible~label]:[box-shadow:0_0_0_va" +
"r(--ring-width)_color-mix(in_oklch,_var(--ring)_16%,_transparent)] [&>[data-part=item]>input:focus-visible~" +
"label]:rounded-xs [&>[data-part=item]>input:focus-visible~label]:[corner-shape:squircle] [&[data-readonly]>" +
"[data-part=item]>label]:cursor-default [&[data-disabled]>[data-part=item]>label]:cursor-default [&[data-dis" +
"abled]>[data-part=item]>label]:opacity-50"
}
defaultValue={3}
id="movie-rating"
/>
);
}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
/* app.css */
@layer reset, ui, app, tokens, base, demo, components, utilities, theme;
@import "@gunkin/uiify/styles/reset";
@import "@gunkin/uiify/components/behavior.css";
@import "@gunkin/uiify/styles/tokens";
@import "@gunkin/uiify/styles/tailwind";
@import "tailwindcss/utilities.css";
@theme { --spacing: 0.25rem; --font-weight-normal: 400; --font-weight-medium: 500; --font-weight-semibold: 600; --font-weight-bold: 700; }
@source inline('inline-flex [flex-direction:row-reverse] gap-xs [&>[data-part=item]>input]:absolute [&>[data-part=item]>input]:[inline-size:1px] [&>[data-part=item]>input]:[block-size:1px] [&>[data-part=item]>input]:[margin:-1px] [&>[data-part=item]>input]:overflow-hidden [&>[data-part=item]>input]:[clip-path:inset(50%)] [&>[data-part=item]>input]:whitespace-nowrap [&>[data-part=item]>label]:inline-flex [&>[data-part=item]>label]:items-center [&>[data-part=item]>label]:justify-center [&>[data-part=item]>label]:text-input [&>[data-part=item]>label]:[font-size:1.5rem] [&>[data-part=item]>label]:leading-none [&>[data-part=item]>label]:cursor-pointer [&>[data-part=item]>label]:[transition:var(--transition-colors)] [&>[data-part=item]:has(>input:checked)>label]:text-primary [&>[data-part=item]:has(>input:checked)~[data-part=item]>label]:text-primary [&:not([data-disabled],[data-readonly])>[data-part=item]:has(>label:hover)>label]:text-primary [&:not([data-disabled],[data-readonly])>[data-part=item]:has(>label:hover)~[data-part=item]>label]:text-primary [&>[data-part=item]>input:focus-visible~label]:[outline:none] [&>[data-part=item]>input:focus-visible~label]:[box-shadow:0_0_0_var(--ring-width)_color-mix(in_oklch,_var(--ring)_16%,_transparent)] [&>[data-part=item]>input:focus-visible~label]:rounded-xs [&>[data-part=item]>input:focus-visible~label]:[corner-shape:squircle] [&[data-readonly]>[data-part=item]>label]:cursor-default [&[data-disabled]>[data-part=item]>label]:cursor-default [&[data-disabled]>[data-part=item]>label]:opacity-50');
@layer base { :root { --uiify-control-text: var(--text-sm); } @media (pointer: coarse) { :root { --uiify-control-text: var(--text-base); } } }
/* Authored animation and registered properties used by the Tailwind skin.
* Visual rules belong in utility recipes; only at-rule definitions live here. */
@layer components {
@keyframes uiify-presence-in {
from {
opacity: 0;
scale: var(--presence-scale);
}
}
}
@layer components {
@keyframes uiify-presence-out {
to {
opacity: 0;
scale: var(--presence-scale);
}
}
}
@property --uiify-spinner-tail {
syntax: "<angle>";
inherits: false;
initial-value: 0deg;
}
@property --uiify-spinner-length {
syntax: "<angle>";
inherits: false;
initial-value: 36deg;
}
@layer components {
@keyframes uiify-spinner-rotate {
to {
transform: rotate(360deg);
}
}
}
@layer components {
@keyframes uiify-spinner-orbit {
0% {
--uiify-spinner-tail: 0deg;
--uiify-spinner-length: 36deg;
}
50% {
--uiify-spinner-tail: 90deg;
--uiify-spinner-length: 324deg;
}
100% {
--uiify-spinner-tail: 360deg;
--uiify-spinner-length: 36deg;
}
}
}
@layer components {
@keyframes uiify-skeleton-pulse {
50% {
opacity: 0.45;
}
}
}
@layer components {
@keyframes uiify-skeleton-shimmer {
to {
background-position: -200% 0;
}
}
}
@layer components {
@keyframes uiify-skeleton-reveal {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
}
@property --candle-body-height {
syntax: "<percentage>";
inherits: true;
initial-value: 0%;
}
@property --candle-body-top {
syntax: "<percentage>";
inherits: true;
initial-value: 50%;
}
@property --candle-slot {
syntax: "<percentage>";
inherits: true;
initial-value: 100%;
}
@property --candle-wick-height {
syntax: "<percentage>";
inherits: true;
initial-value: 0%;
}
@property --candle-wick-top {
syntax: "<percentage>";
inherits: true;
initial-value: 50%;
}
@property --candle-x {
syntax: "<percentage>";
inherits: true;
initial-value: 0%;
}
@property --candle-scale {
syntax: "<number>";
inherits: true;
initial-value: 1;
}
@property --line-y {
syntax: "<percentage>";
inherits: true;
initial-value: 50%;
}
@property --line-prev-y {
syntax: "<percentage>";
inherits: true;
initial-value: 50%;
}
@property --line-count {
syntax: "<integer>";
inherits: false;
initial-value: 1;
}
@property --line-scale {
syntax: "<number>";
inherits: true;
initial-value: 1;
}
@layer components {
@keyframes uiify-otp-input-caret-blink {
50% {
opacity: 0;
}
}
}API
Rating
| Свойство | Тип | По умолчанию | Описание |
|---|---|---|---|
id* | string | — | Префикс идентификатора группы и каждого создаваемого поля radio. |
defaultValue | number | 0 | Оценка, выбранная при первом рендеринге; выбор и предпросмотр при наведении работают на нативных радиокнопках и CSS, поэтому доступны без JavaScript. |
max | number | 5 | Число отображаемых пунктов оценки. |
readOnly | boolean | false | Показывает оценку без возможности изменения пользователем. |
disabled | boolean | false | Отключает все радиокнопки оценки. |
className | string | — | Класс элемента оценки. |
aria-label | string | — | Доступное название группы оценки. |
Клавиатура
| Клавиша | Действие |
|---|---|
| Tab | Перевести фокус на элемент управления или с него |
| Enter / Space | Активировать при наличии фокуса (для элементов управления типа кнопки) |
Доступность
По возможности используется семантический HTML. Изучите разметку в песочнице: ARIA добавляется только там, где нативных элементов недостаточно.
Привязка стилей
data-disabled