@ui-sdk/react 0.0.0-stage → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -2
  3. package/dist/accordion.d.ts +331 -0
  4. package/dist/accordion.js +25 -0
  5. package/dist/agent.d.ts +2 -0
  6. package/dist/agent.js +8 -0
  7. package/dist/alert-dialog.d.ts +56 -0
  8. package/dist/alert-dialog.js +45 -0
  9. package/dist/async-options.d.ts +22 -0
  10. package/dist/async-options.js +56 -0
  11. package/dist/autocomplete.d.ts +102 -0
  12. package/dist/autocomplete.js +195 -0
  13. package/dist/avatar.d.ts +301 -0
  14. package/dist/avatar.js +17 -0
  15. package/dist/button.d.ts +21 -0
  16. package/dist/button.js +45 -0
  17. package/dist/calendar-context.d.ts +10 -0
  18. package/dist/calendar-context.js +9 -0
  19. package/dist/calendar.d.ts +80 -0
  20. package/dist/calendar.js +257 -0
  21. package/dist/carousel.d.ts +52 -0
  22. package/dist/carousel.js +151 -0
  23. package/dist/checkbox.d.ts +24 -0
  24. package/dist/checkbox.js +98 -0
  25. package/dist/children.d.ts +38 -0
  26. package/dist/children.js +63 -0
  27. package/dist/collapsible.d.ts +302 -0
  28. package/dist/collapsible.js +19 -0
  29. package/dist/color-picker.d.ts +72 -0
  30. package/dist/color-picker.js +133 -0
  31. package/dist/color.d.ts +2 -0
  32. package/dist/color.js +22 -0
  33. package/dist/combobox.d.ts +152 -0
  34. package/dist/combobox.js +338 -0
  35. package/dist/command.d.ts +88 -0
  36. package/dist/command.js +233 -0
  37. package/dist/controller-target.d.ts +3 -0
  38. package/dist/controller-target.js +59 -0
  39. package/dist/date-input.d.ts +19 -0
  40. package/dist/date-input.js +58 -0
  41. package/dist/date-picker.d.ts +47 -0
  42. package/dist/date-picker.js +310 -0
  43. package/dist/date.d.ts +2 -0
  44. package/dist/date.js +60 -0
  45. package/dist/dialog-parts.d.ts +23 -0
  46. package/dist/dialog-parts.js +142 -0
  47. package/dist/dialog.d.ts +57 -0
  48. package/dist/dialog.js +32 -0
  49. package/dist/drawer.d.ts +70 -0
  50. package/dist/drawer.js +158 -0
  51. package/dist/editor-context.d.ts +4 -0
  52. package/dist/editor-context.js +9 -0
  53. package/dist/field-context.d.ts +47 -0
  54. package/dist/field-context.js +87 -0
  55. package/dist/field.d.ts +49 -0
  56. package/dist/field.js +169 -0
  57. package/dist/file-input.d.ts +46 -0
  58. package/dist/file-input.js +170 -0
  59. package/dist/form-inputs.d.ts +5 -0
  60. package/dist/form-inputs.js +22 -0
  61. package/dist/gesture.d.ts +1 -0
  62. package/dist/gesture.js +16 -0
  63. package/dist/history.d.ts +2 -0
  64. package/dist/history.js +12 -0
  65. package/dist/hover-card.d.ts +33 -0
  66. package/dist/hover-card.js +84 -0
  67. package/dist/image-cropper.d.ts +333 -0
  68. package/dist/image-cropper.js +37 -0
  69. package/dist/image.d.ts +2 -0
  70. package/dist/image.js +6 -0
  71. package/dist/input.d.ts +22 -0
  72. package/dist/input.js +51 -0
  73. package/dist/label.d.ts +294 -0
  74. package/dist/label.js +9 -0
  75. package/dist/list-items.d.ts +15 -0
  76. package/dist/list-items.js +39 -0
  77. package/dist/list-text.d.ts +4 -0
  78. package/dist/list-text.js +15 -0
  79. package/dist/listbox.d.ts +56 -0
  80. package/dist/listbox.js +122 -0
  81. package/dist/menu.d.ts +116 -0
  82. package/dist/menu.js +426 -0
  83. package/dist/menubar-context.d.ts +4 -0
  84. package/dist/menubar-context.js +7 -0
  85. package/dist/menubar.d.ts +11 -0
  86. package/dist/menubar.js +32 -0
  87. package/dist/meter.d.ts +312 -0
  88. package/dist/meter.js +30 -0
  89. package/dist/navigation-menu.d.ts +61 -0
  90. package/dist/navigation-menu.js +169 -0
  91. package/dist/number-input.d.ts +44 -0
  92. package/dist/number-input.js +185 -0
  93. package/dist/number.d.ts +2 -0
  94. package/dist/number.js +40 -0
  95. package/dist/observe.d.ts +2 -0
  96. package/dist/observe.js +8 -0
  97. package/dist/otp-input.d.ts +29 -0
  98. package/dist/otp-input.js +94 -0
  99. package/dist/overlays.d.ts +26 -0
  100. package/dist/overlays.js +82 -0
  101. package/dist/pagination.d.ts +336 -0
  102. package/dist/pagination.js +71 -0
  103. package/dist/password-input.d.ts +23 -0
  104. package/dist/password-input.js +65 -0
  105. package/dist/popover.d.ts +54 -0
  106. package/dist/popover.js +151 -0
  107. package/dist/popup.d.ts +41 -0
  108. package/dist/popup.js +180 -0
  109. package/dist/preferences.d.ts +35 -0
  110. package/dist/preferences.js +93 -0
  111. package/dist/primitive.d.ts +2 -0
  112. package/dist/primitive.js +14 -0
  113. package/dist/progress.d.ts +312 -0
  114. package/dist/progress.js +30 -0
  115. package/dist/radio.d.ts +22 -0
  116. package/dist/radio.js +86 -0
  117. package/dist/rating.d.ts +20 -0
  118. package/dist/rating.js +94 -0
  119. package/dist/render-element.d.ts +35 -0
  120. package/dist/render-element.js +103 -0
  121. package/dist/resizable.d.ts +302 -0
  122. package/dist/resizable.js +23 -0
  123. package/dist/scroll-area.d.ts +324 -0
  124. package/dist/scroll-area.js +49 -0
  125. package/dist/segmented-control.d.ts +24 -0
  126. package/dist/segmented-control.js +78 -0
  127. package/dist/segmented-input.d.ts +15 -0
  128. package/dist/segmented-input.js +48 -0
  129. package/dist/select.d.ts +125 -0
  130. package/dist/select.js +330 -0
  131. package/dist/separator.d.ts +290 -0
  132. package/dist/separator.js +9 -0
  133. package/dist/shortcuts.d.ts +32 -0
  134. package/dist/shortcuts.js +61 -0
  135. package/dist/slider.d.ts +38 -0
  136. package/dist/slider.js +163 -0
  137. package/dist/switch.d.ts +15 -0
  138. package/dist/switch.js +39 -0
  139. package/dist/tabs.d.ts +331 -0
  140. package/dist/tabs.js +28 -0
  141. package/dist/text-control.d.ts +22 -0
  142. package/dist/text-control.js +24 -0
  143. package/dist/text-match.d.ts +2 -0
  144. package/dist/text-match.js +8 -0
  145. package/dist/textarea.d.ts +10 -0
  146. package/dist/textarea.js +48 -0
  147. package/dist/time-input.d.ts +19 -0
  148. package/dist/time-input.js +63 -0
  149. package/dist/timeline.d.ts +327 -0
  150. package/dist/timeline.js +31 -0
  151. package/dist/toast-parts.d.ts +63 -0
  152. package/dist/toast-parts.js +144 -0
  153. package/dist/toast.d.ts +2 -0
  154. package/dist/toast.js +22 -0
  155. package/dist/toggle.d.ts +23 -0
  156. package/dist/toggle.js +76 -0
  157. package/dist/token-input.d.ts +35 -0
  158. package/dist/token-input.js +100 -0
  159. package/dist/toolbar-context.d.ts +6 -0
  160. package/dist/toolbar-context.js +16 -0
  161. package/dist/toolbar.d.ts +38 -0
  162. package/dist/toolbar.js +63 -0
  163. package/dist/tooltip.d.ts +39 -0
  164. package/dist/tooltip.js +108 -0
  165. package/dist/tree.d.ts +51 -0
  166. package/dist/tree.js +150 -0
  167. package/dist/trigger-menu.d.ts +83 -0
  168. package/dist/trigger-menu.js +167 -0
  169. package/dist/use-primitive.d.ts +178 -0
  170. package/dist/use-primitive.js +674 -0
  171. package/dist/waterfall.d.ts +80 -0
  172. package/dist/waterfall.js +108 -0
  173. package/docs/README.md +89 -0
  174. package/docs/agents.md +1523 -0
  175. package/docs/components/accordion.md +1391 -0
  176. package/docs/components/alert-dialog.md +850 -0
  177. package/docs/components/autocomplete.md +1963 -0
  178. package/docs/components/avatar.md +252 -0
  179. package/docs/components/button.md +444 -0
  180. package/docs/components/calendar.md +1687 -0
  181. package/docs/components/carousel.md +1244 -0
  182. package/docs/components/checkbox.md +1069 -0
  183. package/docs/components/collapsible.md +567 -0
  184. package/docs/components/color-picker.md +736 -0
  185. package/docs/components/combobox.md +3647 -0
  186. package/docs/components/command.md +1573 -0
  187. package/docs/components/date-input.md +608 -0
  188. package/docs/components/date-picker.md +1266 -0
  189. package/docs/components/dialog.md +1469 -0
  190. package/docs/components/drawer.md +1197 -0
  191. package/docs/components/field.md +549 -0
  192. package/docs/components/file-input.md +609 -0
  193. package/docs/components/hover-card.md +514 -0
  194. package/docs/components/image-cropper.md +579 -0
  195. package/docs/components/input.md +301 -0
  196. package/docs/components/label.md +217 -0
  197. package/docs/components/listbox.md +1130 -0
  198. package/docs/components/menu.md +1286 -0
  199. package/docs/components/menubar.md +455 -0
  200. package/docs/components/meter.md +304 -0
  201. package/docs/components/navigation-menu.md +1581 -0
  202. package/docs/components/number-input.md +1086 -0
  203. package/docs/components/otp-input.md +565 -0
  204. package/docs/components/pagination.md +648 -0
  205. package/docs/components/password-input.md +737 -0
  206. package/docs/components/popover.md +1552 -0
  207. package/docs/components/preferences.md +220 -0
  208. package/docs/components/progress.md +443 -0
  209. package/docs/components/radio.md +846 -0
  210. package/docs/components/rating.md +458 -0
  211. package/docs/components/resizable.md +982 -0
  212. package/docs/components/scroll-area.md +980 -0
  213. package/docs/components/segmented-control.md +465 -0
  214. package/docs/components/select.md +2133 -0
  215. package/docs/components/separator.md +243 -0
  216. package/docs/components/slider.md +1169 -0
  217. package/docs/components/switch.md +613 -0
  218. package/docs/components/tabs.md +1014 -0
  219. package/docs/components/textarea.md +318 -0
  220. package/docs/components/time-input.md +231 -0
  221. package/docs/components/timeline.md +677 -0
  222. package/docs/components/toast.md +1395 -0
  223. package/docs/components/toggle.md +541 -0
  224. package/docs/components/token-input.md +1007 -0
  225. package/docs/components/toolbar.md +787 -0
  226. package/docs/components/tooltip.md +884 -0
  227. package/docs/components/tree.md +1346 -0
  228. package/docs/components/trigger-menu.md +1257 -0
  229. package/docs/components/waterfall.md +754 -0
  230. package/docs/controllers.md +89 -0
  231. package/docs/core.md +8027 -0
  232. package/docs/custom-parts.md +120 -0
  233. package/docs/first-component.md +83 -0
  234. package/docs/forms.md +148 -0
  235. package/docs/hooks/async-options.md +366 -0
  236. package/docs/hooks/shortcuts.md +221 -0
  237. package/docs/installation.md +45 -0
  238. package/docs/introduction.md +32 -0
  239. package/docs/lists-and-menus.md +170 -0
  240. package/docs/llms.txt +1844 -0
  241. package/docs/parts-and-composition.md +93 -0
  242. package/docs/popups.md +117 -0
  243. package/docs/rendering.md +121 -0
  244. package/docs/server-rendering.md +253 -0
  245. package/docs/state-and-events.md +105 -0
  246. package/docs/styling-and-animation.md +176 -0
  247. package/package.json +333 -3
@@ -0,0 +1,458 @@
1
+ # Rating
2
+
3
+ Pick a score from a row of stars, whole or half, with a preview as the pointer moves over them.
4
+
5
+ Use a rating to collect a score, like how a stay went, or to show one, like an average. Each star is a radio, so it works like a radio group, with one value and a single tab stop.
6
+
7
+ ```tsx title="basic.tsx"
8
+ "use client"
9
+
10
+ import { Rating, RatingItem } from "@ui-sdk/react/rating"
11
+ import { StarIcon } from "lucide-react"
12
+
13
+ function Example() {
14
+ return (
15
+ <Rating aria-label="Rating" defaultValue={3}>
16
+ <RatingItem>
17
+ <StarIcon aria-hidden="true" />
18
+ </RatingItem>
19
+ </Rating>
20
+ )
21
+ }
22
+
23
+ export { Example }
24
+ ```
25
+
26
+ Choose a star, then use the arrow keys to change the score.
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install @ui-sdk/react @ui-sdk/core
32
+ ```
33
+
34
+ ## Composition
35
+
36
+ Use the following composition to build a `Rating`:
37
+
38
+ ```text
39
+ Rating
40
+ └── RatingItem
41
+ ```
42
+
43
+ `Rating` renders its children once per star, so put one `RatingItem` inside it. Without children, it renders a `RatingItem` with no icon.
44
+
45
+ ## Usage
46
+
47
+ Import the parts and put them together:
48
+
49
+ ```tsx
50
+ import { Rating, RatingItem } from "@ui-sdk/react/rating"
51
+ import { StarIcon } from "lucide-react"
52
+
53
+ function Example() {
54
+ return (
55
+ <Rating aria-label="Rating" defaultValue={3}>
56
+ <RatingItem>
57
+ <StarIcon aria-hidden="true" />
58
+ </RatingItem>
59
+ </Rating>
60
+ )
61
+ }
62
+
63
+ export { Example }
64
+ ```
65
+
66
+ Name the rating with `aria-label`, or put it in a [Field](./field.md) whose label names it. Without `defaultValue`, nothing starts checked and Tab enters on the first star.
67
+
68
+ ## Stars
69
+
70
+ Put your icon in `RatingItem`. Each item says how much of its star the shown score covers: `--rating-fill` goes from 0 to 1, `data-filled` marks a whole star and `data-partial` the star a score ends partway through. The radios that pick the score sit over the icon, so it needs no events of its own.
71
+
72
+ ```css
73
+ [data-slot="rating-item"] {
74
+ color: lightgray;
75
+ }
76
+
77
+ [data-slot="rating-item"][data-filled] {
78
+ color: gold;
79
+ }
80
+ ```
81
+
82
+ For half stars and averages, paint the icon up to `calc(var(--rating-fill) * 100%)`, like with a gradient behind a star-shaped mask.
83
+
84
+ Pass a function as the item's children to render from its state, like an icon that fills once the score covers the star:
85
+
86
+ ```tsx
87
+ <RatingItem>
88
+ {({ fill }) => (
89
+ <StarIcon aria-hidden="true" fill={fill === 1 ? "currentColor" : "none"} />
90
+ )}
91
+ </RatingItem>
92
+ ```
93
+
94
+ ## Half Stars
95
+
96
+ Set `step={0.5}` to split each star in two. Each half is its own radio, named like "2.5 stars", and a press on the first half of a star picks the half score.
97
+
98
+ ```tsx title="half-stars.tsx"
99
+ "use client"
100
+
101
+ import { Rating, RatingItem } from "@ui-sdk/react/rating"
102
+ import { StarIcon } from "lucide-react"
103
+
104
+ function Example() {
105
+ return (
106
+ <Rating aria-label="Rating" step={0.5} defaultValue={3.5}>
107
+ <RatingItem>
108
+ <StarIcon aria-hidden="true" />
109
+ </RatingItem>
110
+ </Rating>
111
+ )
112
+ }
113
+
114
+ export { Example }
115
+ ```
116
+
117
+ Choose the first half of a star. Its star fills halfway.
118
+
119
+ ## Preview
120
+
121
+ While a pointer moves over the stars, they show the score under it: `--rating-fill` follows the pointer, and `data-highlighted` marks the stars up to it. Leaving the stars shows the score again. Touch has no preview, since a tap picks the score at once.
122
+
123
+ ## Deselectable
124
+
125
+ Set `deselectable` to let people clear their score: a press on the checked star, or Space on it, sets the score back to `null`.
126
+
127
+ ```tsx title="deselectable.tsx"
128
+ "use client"
129
+
130
+ import { Rating, RatingItem } from "@ui-sdk/react/rating"
131
+ import { StarIcon } from "lucide-react"
132
+
133
+ function Example() {
134
+ return (
135
+ <Rating aria-label="Rating" defaultValue={4} deselectable>
136
+ <RatingItem>
137
+ <StarIcon aria-hidden="true" />
138
+ </RatingItem>
139
+ </Rating>
140
+ )
141
+ }
142
+
143
+ export { Example }
144
+ ```
145
+
146
+ Press the fourth star. The score clears.
147
+
148
+ ## Read-Only
149
+
150
+ Set `readOnly` to show a score that can't change, like an average. Any score shows, like 4.2, which fills a fifth of the last star. The rating becomes one image for screen readers, and its radios are hidden from them.
151
+
152
+ Name a read-only rating with `getValueLabel`, so its name includes the score. An `aria-label` would replace it.
153
+
154
+ ```tsx title="read-only.tsx"
155
+ "use client"
156
+
157
+ import { Rating, RatingItem } from "@ui-sdk/react/rating"
158
+ import { StarIcon } from "lucide-react"
159
+
160
+ function Example() {
161
+ return (
162
+ <Rating
163
+ value={4.2}
164
+ readOnly
165
+ getValueLabel={(value, max) => `Rated ${value} out of ${max}`}
166
+ >
167
+ <RatingItem>
168
+ <StarIcon aria-hidden="true" />
169
+ </RatingItem>
170
+ </Rating>
171
+ )
172
+ }
173
+
174
+ export { Example }
175
+ ```
176
+
177
+ An average of 4.2, named Rated 4.2 out of 5.
178
+
179
+ ## Disabled
180
+
181
+ Set `disabled` to stop every star from being focused or changed. A disabled rating submits nothing.
182
+
183
+ ```tsx title="disabled.tsx"
184
+ "use client"
185
+
186
+ import { Rating, RatingItem } from "@ui-sdk/react/rating"
187
+ import { StarIcon } from "lucide-react"
188
+
189
+ function Example() {
190
+ return (
191
+ <Rating aria-label="Rating" defaultValue={2} disabled>
192
+ <RatingItem>
193
+ <StarIcon aria-hidden="true" />
194
+ </RatingItem>
195
+ </Rating>
196
+ )
197
+ }
198
+
199
+ export { Example }
200
+ ```
201
+
202
+ The rating is disabled, so the stars can't be focused or pressed.
203
+
204
+ ## Controlled
205
+
206
+ Pass `value` and update it in `onValueChange`. Call `details.cancel()` in the callback to keep the current score. A [controller](#controller) from `createRatingController()` sets the score from anywhere, like the Clear Rating button below. Create one controller per mounted rating.
207
+
208
+ ```tsx title="controlled.tsx"
209
+ "use client"
210
+
211
+ import {
212
+ createRatingController,
213
+ Rating,
214
+ RatingItem,
215
+ } from "@ui-sdk/react/rating"
216
+ import { StarIcon } from "lucide-react"
217
+ import * as React from "react"
218
+ import { useLog } from "./log"
219
+
220
+ function Example() {
221
+ const log = useLog()
222
+ const [rating] = React.useState(() => createRatingController())
223
+ const [value, setValue] = React.useState<number | null>(4)
224
+
225
+ return (
226
+ <div>
227
+ <div data-slot="controls">
228
+ <button type="button" onClick={() => rating.setValue(null)}>
229
+ Clear Rating
230
+ </button>
231
+ </div>
232
+ <Rating
233
+ aria-label="Rating"
234
+ value={value}
235
+ onValueChange={(next, details) => {
236
+ setValue(next)
237
+ log(`value: ${next} (${details.reason})`)
238
+ }}
239
+ controller={rating}
240
+ >
241
+ <RatingItem>
242
+ <StarIcon aria-hidden="true" />
243
+ </RatingItem>
244
+ </Rating>
245
+ </div>
246
+ )
247
+ }
248
+
249
+ export { Example }
250
+ ```
251
+
252
+ Choose a star, then press Clear Rating. The console logs each change and its reason.
253
+
254
+ See [State and Events](../state-and-events.md) for controlled state, cancellation and debugging.
255
+
256
+ ## Form
257
+
258
+ Each radio renders a hidden native radio, so the rating takes part in forms. Set `name` to submit the score; nothing submits without a name or a score. `required` blocks submission until there's a score, and a reset returns to `defaultValue`.
259
+
260
+ ```tsx title="form.tsx"
261
+ "use client"
262
+
263
+ import { Field, FieldLabel } from "@ui-sdk/react/field"
264
+ import { Rating, RatingItem } from "@ui-sdk/react/rating"
265
+ import { StarIcon } from "lucide-react"
266
+ import { useLog } from "./log"
267
+
268
+ function Example() {
269
+ const log = useLog()
270
+
271
+ return (
272
+ <form
273
+ data-slot="stack"
274
+ onSubmit={(event) => {
275
+ event.preventDefault()
276
+ log(`Submitted stay=${new FormData(event.currentTarget).get("stay")}`)
277
+ }}
278
+ >
279
+ <Field>
280
+ <FieldLabel>Rate your stay</FieldLabel>
281
+ <Rating name="stay" required>
282
+ <RatingItem>
283
+ <StarIcon aria-hidden="true" />
284
+ </RatingItem>
285
+ </Rating>
286
+ </Field>
287
+ <div data-slot="row">
288
+ <button type="submit" data-variant="solid">
289
+ Send Review
290
+ </button>
291
+ <button type="reset">Reset</button>
292
+ </div>
293
+ </form>
294
+ )
295
+ }
296
+
297
+ export { Example }
298
+ ```
299
+
300
+ Press Send Review without a score to see the browser's message. Choose a star and send it again.
301
+
302
+ ## Stars and Labels
303
+
304
+ Set `max` for the number of stars, and `loop` to let the arrow keys wrap from the last star to the first. Each radio is named by `getValueLabel`, which gets the score and `max` and says "1 star" or "3 stars" by default.
305
+
306
+ ```tsx
307
+ <Rating
308
+ aria-label="Difficulty"
309
+ max={10}
310
+ loop
311
+ getValueLabel={(value, max) => `${value} of ${max}`}
312
+ >
313
+ <RatingItem />
314
+ </Rating>
315
+ ```
316
+
317
+ ## Styling
318
+
319
+ Parts are unstyled. Use `data-filled`, `data-partial`, `data-checked` and `data-highlighted` on each star, and `--rating-fill` for how full it is. `data-disabled`, `data-readonly` and `data-required` are on the rating and its stars.
320
+
321
+ Each part has a `data-slot`, such as `rating-item`, and its state attributes are listed under [Data Attributes](#data-attributes).
322
+
323
+ ### RatingItem
324
+ - `--rating-fill`: How much of the star the shown score covers, from 0 to 1.
325
+
326
+ ## Data Attributes
327
+
328
+ ### Rating
329
+ `[data-slot="rating"]`
330
+
331
+ - `data-required`: Present when the rating is required.
332
+ - `data-readonly`: Present when the rating only shows its score.
333
+ - `data-disabled`: Present when the rating is disabled, by its own prop or a `<fieldset>`.
334
+
335
+ ### RatingItem
336
+ `[data-slot="rating-item"]`
337
+
338
+ - `data-filled`: Present on stars the shown score covers whole.
339
+ - `data-partial`: Present on the star the shown score covers part of, like the last of 2.5.
340
+ - `data-checked`: Present on the star the score ends in.
341
+ - `data-disabled`: Present when the rating is disabled, by its own prop or a `<fieldset>`.
342
+ - `data-readonly`: Present when the rating only shows its score.
343
+ - `data-highlighted`: Present on the stars up to the score a pointer previews.
344
+
345
+ ## API Reference
346
+
347
+ Props and callbacks are the same as below, as React props.
348
+
349
+ ### Rating
350
+
351
+ - `value?` (`number | null`): The score. Pass it to control the rating. `null` means no score yet.
352
+ - `defaultValue?` (`number | null`): The score at first, when uncontrolled. A form reset returns to it.
353
+ - `onValueChange?` (`((value: number | null, details: ChangeDetails<RatingValueChangeReason>) => void)`): Runs when a user or a form reset wants to change the score. `details.reason` says why, and `details.cancel()` stops it.
354
+ - `max?` (`number`): How many stars there are.
355
+ - `step?` (`number`): The smallest change, as a fraction of a star: `0.5` makes half stars, each half its own radio.
356
+ - `deselectable?` (`boolean`): Lets a press on the checked star clear the score.
357
+ - `disabled?` (`boolean`): Disables every star: they can't be focused or changed, and the score isn't submitted.
358
+ - `readOnly?` (`boolean`): Shows the score as an image, named by `getValueLabel`, that can't be changed. Any score shows, like an average of 4.2.
359
+ - `required?` (`boolean`): Blocks form submission until there's a score, with the browser's own message.
360
+ - `name?` (`string`): The name the score submits under. Without one, the rating submits nothing.
361
+ - `form?` (`string`): The id of a form to belong to, when the rating isn't inside that form.
362
+ - `loop?` (`boolean`): Whether arrow keys wrap from the last star to the first.
363
+ - `getValueLabel?` (`((value: number, max: number) => string)`): Names a score, for each star's radio and for a read-only rating.
364
+ - `controller?` (`{ getValue: () => number | null; setValue: (value: number | null, details?: RatingChangeOptions) => boolean; focus: () => void; }`): Sets the score from anywhere. Create one with `createRatingController()`.
365
+ - `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
366
+
367
+ ### State
368
+
369
+ What render functions, state-based class names and slots receive.
370
+
371
+ - `value` (`number | null`): The score, or `null` before anyone rates.
372
+ - `highlighted` (`number | null`): The score a pointer previews over the stars, or `null` while none does.
373
+ - `disabled` (`boolean`): Whether the rating is disabled, by itself or by a `<fieldset>`.
374
+ - `readOnly` (`boolean`): Whether the rating only shows its score.
375
+ - `required` (`boolean`): Whether a form won't submit until there's a score.
376
+
377
+ - `index` (`number`): Which star this is, from 1.
378
+ - `fill` (`number`): How much of this star the shown score covers, from 0 to 1. Also `--rating-fill`.
379
+ - `checked` (`boolean`): Whether the score ends in this star.
380
+ - `highlighted` (`boolean`): Whether a pointer previews a score that reaches this star.
381
+ - `disabled` (`boolean`): Whether the rating is disabled, by itself or by a `<fieldset>`.
382
+ - `readOnly` (`boolean`): Whether the rating only shows its score.
383
+
384
+ ### Reasons
385
+
386
+ `details.reason` says why the score changed.
387
+
388
+ - `item-press` (`MouseEvent | KeyboardEvent`): A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
389
+ - `list-navigation` (`KeyboardEvent`): Arrow, Home or End keys moved the selection, typing picked an item, or Ctrl or ⌘ with A selected every item of a listbox.
390
+ - `reset` (`none`): A form reset.
391
+ - `restore` (`none`): The browser restored state, like after going back, or a saved value was read back from storage.
392
+ - `imperative` (`none`): A controller or `api` call, or a property set on a web component.
393
+
394
+ ### Controller
395
+
396
+ Create one with `createRatingController()` and pass it as `controller`.
397
+
398
+ Every write method takes an optional `{ reason, event }`, runs the change callback like a press, and returns `false` when the change is canceled.
399
+
400
+ - `getValue()` (`() => number | null`): The score, or `null` before anyone rates.
401
+ - `setValue(value, details?)` (`(value: number | null, details?: RatingChangeOptions | undefined) => boolean`): Sets the score, as a user would. Disabled and read-only ratings ignore it.
402
+ - `focus()` (`() => void`): Moves focus to the checked star, or the first one.
403
+
404
+ ### Events
405
+
406
+ Callbacks get the new score first, then the details.
407
+
408
+ | Prop | On | Receives |
409
+ | --------------- | -------- | ------------------------------------------------------------------- |
410
+ | `onValueChange` | `Rating` | `(value, details)`: the score or `null`, and the [reason](#reasons) |
411
+
412
+ ## Accessibility
413
+
414
+ A rating is a radio group, so it follows the [WAI-ARIA radio group pattern](https://www.w3.org/WAI/ARIA/apg/patterns/radio/) and behaves like native radios that share a name. Each star holds a button with the `radio` role per score it can pick, and a hidden native radio that takes part in forms. Icons inside the stars should be hidden from screen readers with `aria-hidden`, since each radio is already named. A read-only rating has the `img` role instead, named by `getValueLabel`.
415
+
416
+ ### Keyboard
417
+
418
+ | Key | Does |
419
+ | ---------- | ------------------------------------------------------------------------------------------ |
420
+ | Tab | Moves into the rating, onto the checked star or the first one |
421
+ | Arrow keys | Move to the next or previous score and check it, stopping at the ends unless `loop` is set |
422
+ | Space | Checks the focused star, or clears it when it's checked and `deselectable` |
423
+ | Enter | Submits its form |
424
+
425
+ ### Tested Behavior
426
+
427
+ Every line below is an automated test.
428
+
429
+ **Selection**
430
+
431
+ - The default score is checked, and the stars up to it are full.
432
+ - Clicking a star checks it and says why.
433
+ - A half star fills half of its star.
434
+ - Clicking the checked star clears a deselectable rating, and only that one.
435
+ - A change can be cancelled.
436
+ - A controller sets the score.
437
+
438
+ **Preview**
439
+
440
+ - A pointer over a star previews its score, and leaving shows the score again.
441
+
442
+ **Keyboard**
443
+
444
+ - Tab lands on the checked star, and the next Tab leaves.
445
+ - Arrow keys change the score by a step, and stop at the ends.
446
+ - Space on the checked star clears a deselectable rating.
447
+
448
+ **Read-only**
449
+
450
+ - A read-only rating is one image, named by its label, that shows any score.
451
+
452
+ **Forms**
453
+
454
+ - Each score submits under its rating's name.
455
+ - A form reset returns to the default score.
456
+ - A disabled rating submits nothing, and its stars can't be focused or checked.
457
+
458
+ Runs in React, Vue and web components.