@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,304 @@
1
+ # Meter
2
+
3
+ Show a measurement within a known range, such as storage used or an account quota.
4
+
5
+ Use a Meter for a value within a known range, such as storage used, a battery level or an account quota. It fills a track to show the value, and screen readers announce the same value.
6
+
7
+ ```tsx title="basic.tsx"
8
+ import {
9
+ Meter,
10
+ MeterIndicator,
11
+ MeterLabel,
12
+ MeterTrack,
13
+ MeterValue,
14
+ } from "@ui-sdk/react/meter"
15
+
16
+ export function Example() {
17
+ return (
18
+ <Meter value={68}>
19
+ <MeterLabel>Storage used</MeterLabel>
20
+ <MeterValue />
21
+ <MeterTrack>
22
+ <MeterIndicator />
23
+ </MeterTrack>
24
+ </Meter>
25
+ )
26
+ }
27
+ ```
28
+
29
+ Read the storage meter. The label names it, and both the visible value and screen reader value report 68%.
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ npm install @ui-sdk/react @ui-sdk/core
35
+ ```
36
+
37
+ ## Composition
38
+
39
+ Use the following composition to build a `Meter`:
40
+
41
+ ```text
42
+ Meter
43
+ ├── MeterLabel
44
+ ├── MeterValue
45
+ └── MeterTrack
46
+ └── MeterIndicator
47
+ ```
48
+
49
+ - `Meter` holds the value and range.
50
+ - `MeterLabel` gives it a visible name. You can use `aria-label` on the root instead.
51
+ - `MeterValue` displays the formatted value.
52
+ - `MeterTrack` gives the bar its size, and `MeterIndicator` fills it.
53
+
54
+ The value is already part of the root's accessible description. The visible value is hidden from screen readers to avoid reading it twice.
55
+
56
+ ## Usage
57
+
58
+ Import the parts and put them together:
59
+
60
+ ```tsx
61
+ <Meter value={40}>
62
+ <MeterLabel />
63
+ <MeterValue />
64
+ <MeterTrack>
65
+ <MeterIndicator />
66
+ </MeterTrack>
67
+ </Meter>
68
+ ```
69
+
70
+ ## Build Your Own
71
+
72
+ `@ui-sdk/react/meter` comes with a ready-made Meter. If you'd like to build your own, with your own names, start from the `meter` primitive in `@ui-sdk/core`:
73
+
74
+ ```ts title="quota.ts"
75
+ "use client"
76
+
77
+ import { meter } from "@ui-sdk/core/meter"
78
+ import { createParts } from "@ui-sdk/react/primitive"
79
+
80
+ const {
81
+ Root: Quota,
82
+ Label: QuotaLabel,
83
+ Value: QuotaValue,
84
+ Track: QuotaTrack,
85
+ Indicator: QuotaFill,
86
+ } = createParts(meter, {
87
+ root: "div",
88
+ label: "span",
89
+ value: "span",
90
+ track: "div",
91
+ indicator: "div",
92
+ })
93
+
94
+ export { Quota, QuotaFill, QuotaLabel, QuotaTrack, QuotaValue }
95
+ ```
96
+
97
+ ```tsx
98
+ <Quota value={68}>
99
+ <QuotaLabel>Storage</QuotaLabel>
100
+ <QuotaValue>{(state) => state.text}</QuotaValue>
101
+ <QuotaTrack>
102
+ <QuotaFill />
103
+ </QuotaTrack>
104
+ </Quota>
105
+ ```
106
+
107
+ `MeterValue` shows the formatted value when it has no children. A part from `createParts` renders only its children, so pass `(state) => state.text` to show the same text.
108
+
109
+ Each part keeps the behavior, state and data attributes of its ready-made counterpart: the root is the `meter`, and the indicator sets its width from the value. See [Rendering](../rendering.md) and [Custom Parts](../custom-parts.md) for more.
110
+
111
+ ## Bounds
112
+
113
+ `min` and `max` set the range. They default to 0 and 100. A value outside the range is clamped for the fill, the percentage and `aria-valuenow`, but the state's `value` and a format other than percent keep it as you passed it. Here, 720 sits about 76% of the way from 300 to 850. Decimal formatting keeps the visible value as 720.
114
+
115
+ ```tsx title="min-max.tsx"
116
+ import {
117
+ Meter,
118
+ MeterIndicator,
119
+ MeterLabel,
120
+ MeterTrack,
121
+ MeterValue,
122
+ } from "@ui-sdk/react/meter"
123
+
124
+ export function Example() {
125
+ return (
126
+ <Meter value={720} min={300} max={850} format={{ style: "decimal" }}>
127
+ <MeterLabel>Credit score</MeterLabel>
128
+ <MeterValue />
129
+ <MeterTrack>
130
+ <MeterIndicator />
131
+ </MeterTrack>
132
+ </Meter>
133
+ )
134
+ }
135
+ ```
136
+
137
+ Compare the score with the filled track. The number shows 720; the fill shows its position between 300 and 850.
138
+
139
+ ## Format and Locale
140
+
141
+ Pass `Intl.NumberFormat` options to `format` for units, currency, or decimal places. A function can return custom text, such as the number of occupied seats.
142
+
143
+ ```tsx title="format.tsx"
144
+ import {
145
+ Meter,
146
+ MeterIndicator,
147
+ MeterLabel,
148
+ MeterTrack,
149
+ MeterValue,
150
+ } from "@ui-sdk/react/meter"
151
+
152
+ const meters = [
153
+ {
154
+ label: "Storage",
155
+ value: 120,
156
+ max: 250,
157
+ format: { style: "unit", unit: "gigabyte" },
158
+ },
159
+ {
160
+ label: "Budget",
161
+ value: 1840,
162
+ max: 2500,
163
+ format: { style: "currency", currency: "USD", maximumFractionDigits: 0 },
164
+ },
165
+ {
166
+ label: "Seats",
167
+ value: 18,
168
+ max: 25,
169
+ format: (seats: number) => `${seats} of 25 seats`,
170
+ },
171
+ { label: "Auslastung", value: 40, locale: "de-DE" },
172
+ ] satisfies {
173
+ label: string
174
+ value: number
175
+ max?: number
176
+ format?: Intl.NumberFormatOptions | ((value: number) => string)
177
+ locale?: string
178
+ }[]
179
+
180
+ export function Example() {
181
+ return (
182
+ <div data-slot="stack">
183
+ {meters.map(({ label, ...options }) => (
184
+ <Meter key={label} {...options}>
185
+ <MeterLabel>{label}</MeterLabel>
186
+ <MeterValue />
187
+ <MeterTrack>
188
+ <MeterIndicator />
189
+ </MeterTrack>
190
+ </Meter>
191
+ ))}
192
+ </div>
193
+ )
194
+ }
195
+ ```
196
+
197
+ Compare the readings. Each meter formats its own value as a unit, currency, custom text, or localized percentage.
198
+
199
+ A percent format reports the value's position between `min` and `max`. Other formats use the value itself.
200
+
201
+ `locale` controls digits and separators. If you omit it, the component reads the page's language after it mounts, with the browser's language as a fallback. The initial server and client render use English.
202
+
203
+ Set `dir="rtl"` on the surrounding content to fill the track from the right.
204
+
205
+ ## Value Label
206
+
207
+ Use `getValueLabel` when a screen reader needs more context than the visible number. It receives the value and details containing `formatted`, `percent`, `min`, and `max`.
208
+
209
+ ```tsx title="value-label.tsx"
210
+ import {
211
+ Meter,
212
+ MeterIndicator,
213
+ MeterLabel,
214
+ MeterTrack,
215
+ MeterValue,
216
+ } from "@ui-sdk/react/meter"
217
+
218
+ export function Example() {
219
+ return (
220
+ <Meter
221
+ value={750}
222
+ max={1000}
223
+ getValueLabel={(value, details) =>
224
+ `${value} of ${details.max} requests, ${details.formatted}`
225
+ }
226
+ >
227
+ <MeterLabel>API requests</MeterLabel>
228
+ <MeterValue>750 / 1,000</MeterValue>
229
+ <MeterTrack>
230
+ <MeterIndicator />
231
+ </MeterTrack>
232
+ </Meter>
233
+ )
234
+ }
235
+ ```
236
+
237
+ Read API requests with a screen reader. It announces 750 of 1000 requests and 75%, while the visible value stays compact.
238
+
239
+ ## Changing the Value
240
+
241
+ Pass a new `value` when your reading changes. Meter follows your state and has no `onValueChange` callback.
242
+
243
+ Use [Progress](./progress.md) for a task that is working toward completion, such as an upload.
244
+
245
+ ## Custom Rendering
246
+
247
+ See [Parts and Composition](../parts-and-composition.md) for changing a part's element or reading its state. Use `format` for text that should be shared by the visible value and screen readers.
248
+
249
+ ## Styling
250
+
251
+ Give the track a height, background, and width. The indicator sets its width as an inline percentage of the track. Both styling options are shown in each example's Code tab.
252
+
253
+ Each part has a `data-slot`, such as `meter-indicator`, and no state attributes: the reading is in `--meter-value` and the indicator's width.
254
+
255
+ ### Meter
256
+ The root exposes a CSS variable for positioning other content alongside the reading.
257
+
258
+ - `--meter-value`: Where the value sits between `min` and `max`, as a percentage, like 40%.
259
+
260
+ ## API Reference
261
+
262
+ Props are the same as below, as React props.
263
+
264
+ ### Meter
265
+
266
+ - `min?` (`number`): The lowest value.
267
+ - `max?` (`number`): The highest value.
268
+ - `format?` (`NumberFormat`): How the value reads, for screen readers and the Value part: `Intl.NumberFormat` options, or a function of the value. A percent style shows where the value sits between `min` and `max`; any other style shows the value itself, like `{ style: "unit", unit: "gigabyte" }`.
269
+ - `locale?` (`string`): The locale the value is formatted in. Defaults to the page's `lang`, or the browser's language without one, once the page is interactive. Server markup uses English until then, so it never disagrees with the client.
270
+ - `getValueLabel?` (`((value: number, details: GaugeLabelDetails<number>) => string)`): The text screen readers announce for the value, when the formatted value says too little, like "3 of 12 files". It receives the value, null while a progress bar is indeterminate, and details: the `formatted` value, its `percent`, `min` and `max`.
271
+ - `value` (`number`): The reading, between `min` and `max`. Outside them, the fill, the percentage and `aria-valuenow` are clamped, while the state keeps the value as given. A meter always has a value, since there's no busy state.
272
+ - `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
273
+
274
+ ### State
275
+
276
+ What render functions, state-based class names and slots receive. Every part gets the same state.
277
+
278
+ - `value` (`number`): The value, as given.
279
+ - `percent` (`number`): Where the value sits between `min` and `max`, from 0 to 100.
280
+
281
+ `MeterValue` adds the formatted text:
282
+
283
+ - `value` (`number`): The value, as given.
284
+ - `percent` (`number`): Where the value sits between `min` and `max`, from 0 to 100.
285
+ - `text` (`string`): The formatted value, like "40%".
286
+
287
+ ## Accessibility
288
+
289
+ Name the component with `MeterLabel` or `aria-label`. It exposes the range and formatted value through the `meter` role. Use `getValueLabel` when that value needs more explanation.
290
+
291
+ ### Tested Behavior
292
+
293
+ Every line below is an automated test.
294
+
295
+ - A meter is named by its label and reads its value.
296
+ - The value part shows the formatted value.
297
+ - The indicator is as wide as the value.
298
+ - A new value updates the meter.
299
+ - Min and max set where the value sits.
300
+ - A unit format reads the value itself.
301
+ - A value label replaces the formatted value for screen readers.
302
+ - A value above the maximum reads as the maximum and fills the track.
303
+
304
+ Runs in React, Vue and web components.