@opsinjs/react 0.0.0-stage → 0.1.0

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 (266) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +21 -0
  3. package/README.md +114 -2
  4. package/dist/components/accordion.d.ts +82 -0
  5. package/dist/components/accordion.d.ts.map +1 -0
  6. package/dist/components/accordion.js +154 -0
  7. package/dist/components/accordion.js.map +1 -0
  8. package/dist/components/alert-banner.d.ts +291 -0
  9. package/dist/components/alert-banner.d.ts.map +1 -0
  10. package/dist/components/alert-banner.js +529 -0
  11. package/dist/components/alert-banner.js.map +1 -0
  12. package/dist/components/avatar.d.ts +45 -0
  13. package/dist/components/avatar.d.ts.map +1 -0
  14. package/dist/components/avatar.js +159 -0
  15. package/dist/components/avatar.js.map +1 -0
  16. package/dist/components/badge.d.ts +78 -0
  17. package/dist/components/badge.d.ts.map +1 -0
  18. package/dist/components/badge.js +32 -0
  19. package/dist/components/badge.js.map +1 -0
  20. package/dist/components/body-map.d.ts +51 -0
  21. package/dist/components/body-map.d.ts.map +1 -0
  22. package/dist/components/body-map.js +190 -0
  23. package/dist/components/body-map.js.map +1 -0
  24. package/dist/components/button.d.ts +260 -0
  25. package/dist/components/button.d.ts.map +1 -0
  26. package/dist/components/button.js +609 -0
  27. package/dist/components/button.js.map +1 -0
  28. package/dist/components/callout.d.ts +99 -0
  29. package/dist/components/callout.d.ts.map +1 -0
  30. package/dist/components/callout.js +285 -0
  31. package/dist/components/callout.js.map +1 -0
  32. package/dist/components/card.d.ts +156 -0
  33. package/dist/components/card.d.ts.map +1 -0
  34. package/dist/components/card.js +396 -0
  35. package/dist/components/card.js.map +1 -0
  36. package/dist/components/care-card.d.ts +182 -0
  37. package/dist/components/care-card.d.ts.map +1 -0
  38. package/dist/components/care-card.js +544 -0
  39. package/dist/components/care-card.js.map +1 -0
  40. package/dist/components/checkbox.d.ts +58 -0
  41. package/dist/components/checkbox.d.ts.map +1 -0
  42. package/dist/components/checkbox.js +167 -0
  43. package/dist/components/checkbox.js.map +1 -0
  44. package/dist/components/combobox.d.ts +71 -0
  45. package/dist/components/combobox.d.ts.map +1 -0
  46. package/dist/components/combobox.js +204 -0
  47. package/dist/components/combobox.js.map +1 -0
  48. package/dist/components/consent-sheet.d.ts +186 -0
  49. package/dist/components/consent-sheet.d.ts.map +1 -0
  50. package/dist/components/consent-sheet.js +452 -0
  51. package/dist/components/consent-sheet.js.map +1 -0
  52. package/dist/components/dialog.d.ts +108 -0
  53. package/dist/components/dialog.d.ts.map +1 -0
  54. package/dist/components/dialog.js +573 -0
  55. package/dist/components/dialog.js.map +1 -0
  56. package/dist/components/disclaimer-note.d.ts +144 -0
  57. package/dist/components/disclaimer-note.d.ts.map +1 -0
  58. package/dist/components/disclaimer-note.js +486 -0
  59. package/dist/components/disclaimer-note.js.map +1 -0
  60. package/dist/components/divider.d.ts +76 -0
  61. package/dist/components/divider.d.ts.map +1 -0
  62. package/dist/components/divider.js +101 -0
  63. package/dist/components/divider.js.map +1 -0
  64. package/dist/components/dose-tracker.d.ts +137 -0
  65. package/dist/components/dose-tracker.d.ts.map +1 -0
  66. package/dist/components/dose-tracker.js +154 -0
  67. package/dist/components/dose-tracker.js.map +1 -0
  68. package/dist/components/empty-state.d.ts +171 -0
  69. package/dist/components/empty-state.d.ts.map +1 -0
  70. package/dist/components/empty-state.js +387 -0
  71. package/dist/components/empty-state.js.map +1 -0
  72. package/dist/components/field.d.ts +195 -0
  73. package/dist/components/field.d.ts.map +1 -0
  74. package/dist/components/field.js +282 -0
  75. package/dist/components/field.js.map +1 -0
  76. package/dist/components/goal-ring.d.ts +114 -0
  77. package/dist/components/goal-ring.d.ts.map +1 -0
  78. package/dist/components/goal-ring.js +254 -0
  79. package/dist/components/goal-ring.js.map +1 -0
  80. package/dist/components/icon-button.d.ts +124 -0
  81. package/dist/components/icon-button.d.ts.map +1 -0
  82. package/dist/components/icon-button.js +113 -0
  83. package/dist/components/icon-button.js.map +1 -0
  84. package/dist/components/link.d.ts +122 -0
  85. package/dist/components/link.d.ts.map +1 -0
  86. package/dist/components/link.js +164 -0
  87. package/dist/components/link.js.map +1 -0
  88. package/dist/components/log-sheet.d.ts +259 -0
  89. package/dist/components/log-sheet.d.ts.map +1 -0
  90. package/dist/components/log-sheet.js +437 -0
  91. package/dist/components/log-sheet.js.map +1 -0
  92. package/dist/components/menu.d.ts +69 -0
  93. package/dist/components/menu.d.ts.map +1 -0
  94. package/dist/components/menu.js +190 -0
  95. package/dist/components/menu.js.map +1 -0
  96. package/dist/components/metric-tile.d.ts +301 -0
  97. package/dist/components/metric-tile.d.ts.map +1 -0
  98. package/dist/components/metric-tile.js +533 -0
  99. package/dist/components/metric-tile.js.map +1 -0
  100. package/dist/components/number-field.d.ts +62 -0
  101. package/dist/components/number-field.d.ts.map +1 -0
  102. package/dist/components/number-field.js +134 -0
  103. package/dist/components/number-field.js.map +1 -0
  104. package/dist/components/popover.d.ts +70 -0
  105. package/dist/components/popover.d.ts.map +1 -0
  106. package/dist/components/popover.js +174 -0
  107. package/dist/components/popover.js.map +1 -0
  108. package/dist/components/progress.d.ts +83 -0
  109. package/dist/components/progress.d.ts.map +1 -0
  110. package/dist/components/progress.js +140 -0
  111. package/dist/components/progress.js.map +1 -0
  112. package/dist/components/questionnaire.d.ts +123 -0
  113. package/dist/components/questionnaire.d.ts.map +1 -0
  114. package/dist/components/questionnaire.js +148 -0
  115. package/dist/components/questionnaire.js.map +1 -0
  116. package/dist/components/radio-group.d.ts +66 -0
  117. package/dist/components/radio-group.d.ts.map +1 -0
  118. package/dist/components/radio-group.js +186 -0
  119. package/dist/components/radio-group.js.map +1 -0
  120. package/dist/components/range-bar.d.ts +172 -0
  121. package/dist/components/range-bar.d.ts.map +1 -0
  122. package/dist/components/range-bar.js +578 -0
  123. package/dist/components/range-bar.js.map +1 -0
  124. package/dist/components/range-legend.d.ts +97 -0
  125. package/dist/components/range-legend.d.ts.map +1 -0
  126. package/dist/components/range-legend.js +166 -0
  127. package/dist/components/range-legend.js.map +1 -0
  128. package/dist/components/reading-input.d.ts +225 -0
  129. package/dist/components/reading-input.d.ts.map +1 -0
  130. package/dist/components/reading-input.js +651 -0
  131. package/dist/components/reading-input.js.map +1 -0
  132. package/dist/components/relative-time.d.ts +177 -0
  133. package/dist/components/relative-time.d.ts.map +1 -0
  134. package/dist/components/relative-time.js +603 -0
  135. package/dist/components/relative-time.js.map +1 -0
  136. package/dist/components/result-card.d.ts +319 -0
  137. package/dist/components/result-card.d.ts.map +1 -0
  138. package/dist/components/result-card.js +614 -0
  139. package/dist/components/result-card.js.map +1 -0
  140. package/dist/components/scale-input.d.ts +58 -0
  141. package/dist/components/scale-input.d.ts.map +1 -0
  142. package/dist/components/scale-input.js +170 -0
  143. package/dist/components/scale-input.js.map +1 -0
  144. package/dist/components/score-dial.d.ts +205 -0
  145. package/dist/components/score-dial.d.ts.map +1 -0
  146. package/dist/components/score-dial.js +728 -0
  147. package/dist/components/score-dial.js.map +1 -0
  148. package/dist/components/scroll-area.d.ts +38 -0
  149. package/dist/components/scroll-area.d.ts.map +1 -0
  150. package/dist/components/scroll-area.js +138 -0
  151. package/dist/components/scroll-area.js.map +1 -0
  152. package/dist/components/segmented-control.d.ts +69 -0
  153. package/dist/components/segmented-control.d.ts.map +1 -0
  154. package/dist/components/segmented-control.js +259 -0
  155. package/dist/components/segmented-control.js.map +1 -0
  156. package/dist/components/select.d.ts +72 -0
  157. package/dist/components/select.d.ts.map +1 -0
  158. package/dist/components/select.js +205 -0
  159. package/dist/components/select.js.map +1 -0
  160. package/dist/components/sheet.d.ts +192 -0
  161. package/dist/components/sheet.d.ts.map +1 -0
  162. package/dist/components/sheet.js +952 -0
  163. package/dist/components/sheet.js.map +1 -0
  164. package/dist/components/skeleton.d.ts +104 -0
  165. package/dist/components/skeleton.d.ts.map +1 -0
  166. package/dist/components/skeleton.js +266 -0
  167. package/dist/components/skeleton.js.map +1 -0
  168. package/dist/components/slider.d.ts +55 -0
  169. package/dist/components/slider.d.ts.map +1 -0
  170. package/dist/components/slider.js +170 -0
  171. package/dist/components/slider.js.map +1 -0
  172. package/dist/components/source-citation.d.ts +127 -0
  173. package/dist/components/source-citation.d.ts.map +1 -0
  174. package/dist/components/source-citation.js +391 -0
  175. package/dist/components/source-citation.js.map +1 -0
  176. package/dist/components/spinner.d.ts +86 -0
  177. package/dist/components/spinner.d.ts.map +1 -0
  178. package/dist/components/spinner.js +97 -0
  179. package/dist/components/spinner.js.map +1 -0
  180. package/dist/components/status-pill.d.ts +90 -0
  181. package/dist/components/status-pill.d.ts.map +1 -0
  182. package/dist/components/status-pill.js +259 -0
  183. package/dist/components/status-pill.js.map +1 -0
  184. package/dist/components/stepper.d.ts +99 -0
  185. package/dist/components/stepper.d.ts.map +1 -0
  186. package/dist/components/stepper.js +152 -0
  187. package/dist/components/stepper.js.map +1 -0
  188. package/dist/components/surface.d.ts +92 -0
  189. package/dist/components/surface.d.ts.map +1 -0
  190. package/dist/components/surface.js +261 -0
  191. package/dist/components/surface.js.map +1 -0
  192. package/dist/components/switch.d.ts +48 -0
  193. package/dist/components/switch.d.ts.map +1 -0
  194. package/dist/components/switch.js +152 -0
  195. package/dist/components/switch.js.map +1 -0
  196. package/dist/components/symptom-picker.d.ts +69 -0
  197. package/dist/components/symptom-picker.d.ts.map +1 -0
  198. package/dist/components/symptom-picker.js +170 -0
  199. package/dist/components/symptom-picker.js.map +1 -0
  200. package/dist/components/tab-bar.d.ts +110 -0
  201. package/dist/components/tab-bar.d.ts.map +1 -0
  202. package/dist/components/tab-bar.js +118 -0
  203. package/dist/components/tab-bar.js.map +1 -0
  204. package/dist/components/table.d.ts +117 -0
  205. package/dist/components/table.d.ts.map +1 -0
  206. package/dist/components/table.js +65 -0
  207. package/dist/components/table.js.map +1 -0
  208. package/dist/components/tabs.d.ts +106 -0
  209. package/dist/components/tabs.d.ts.map +1 -0
  210. package/dist/components/tabs.js +136 -0
  211. package/dist/components/tabs.js.map +1 -0
  212. package/dist/components/term.d.ts +243 -0
  213. package/dist/components/term.d.ts.map +1 -0
  214. package/dist/components/term.js +562 -0
  215. package/dist/components/term.js.map +1 -0
  216. package/dist/components/textarea.d.ts +157 -0
  217. package/dist/components/textarea.d.ts.map +1 -0
  218. package/dist/components/textarea.js +66 -0
  219. package/dist/components/textarea.js.map +1 -0
  220. package/dist/components/timeline-entry.d.ts +99 -0
  221. package/dist/components/timeline-entry.d.ts.map +1 -0
  222. package/dist/components/timeline-entry.js +47 -0
  223. package/dist/components/timeline-entry.js.map +1 -0
  224. package/dist/components/toast.d.ts +80 -0
  225. package/dist/components/toast.d.ts.map +1 -0
  226. package/dist/components/toast.js +266 -0
  227. package/dist/components/toast.js.map +1 -0
  228. package/dist/components/tooltip.d.ts +48 -0
  229. package/dist/components/tooltip.d.ts.map +1 -0
  230. package/dist/components/tooltip.js +159 -0
  231. package/dist/components/tooltip.js.map +1 -0
  232. package/dist/components/trend-sparkline.d.ts +188 -0
  233. package/dist/components/trend-sparkline.d.ts.map +1 -0
  234. package/dist/components/trend-sparkline.js +796 -0
  235. package/dist/components/trend-sparkline.js.map +1 -0
  236. package/dist/components/value.d.ts +150 -0
  237. package/dist/components/value.d.ts.map +1 -0
  238. package/dist/components/value.js +402 -0
  239. package/dist/components/value.js.map +1 -0
  240. package/dist/components/visually-hidden.d.ts +61 -0
  241. package/dist/components/visually-hidden.d.ts.map +1 -0
  242. package/dist/components/visually-hidden.js +172 -0
  243. package/dist/components/visually-hidden.js.map +1 -0
  244. package/dist/index.d.ts +63 -0
  245. package/dist/index.d.ts.map +1 -0
  246. package/dist/index.js +72 -0
  247. package/dist/index.js.map +1 -0
  248. package/dist/opsinjs.d.ts +443 -0
  249. package/dist/opsinjs.d.ts.map +1 -0
  250. package/dist/opsinjs.js +906 -0
  251. package/dist/opsinjs.js.map +1 -0
  252. package/dist/status.d.ts +111 -0
  253. package/dist/status.d.ts.map +1 -0
  254. package/dist/status.js +125 -0
  255. package/dist/status.js.map +1 -0
  256. package/dist/styles.css +2 -0
  257. package/dist/utils.d.ts +20 -0
  258. package/dist/utils.d.ts.map +1 -0
  259. package/dist/utils.js +82 -0
  260. package/dist/utils.js.map +1 -0
  261. package/package.json +86 -3
  262. package/styles/base.css +132 -0
  263. package/styles/roles.css +412 -0
  264. package/styles/standalone.css +20 -0
  265. package/styles/tailwind.css +18 -0
  266. package/styles/theme.css +309 -0
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Field is a label, its guidance, its error, and the wiring that ties all
3
+ * three to one control.
4
+ *
5
+ * THIS IS THE COMPONENT THAT DECIDES WHETHER EVERY FORM IN A PRODUCT IS
6
+ * ACCESSIBLE, once. Not because a label is hard, but because the relationships
7
+ * are: an id that has to match a `for`, a description list that has to name two
8
+ * elements and drop one when it unmounts, an invalid state that has to reach the
9
+ * control rather than the wrapper. Hand-wired, those four things are correct on
10
+ * the day they are written and wrong by the third refactor. Field's whole claim
11
+ * is that a product never types any of them.
12
+ *
13
+ * WHAT IS BASE UI'S RESPONSIBILITY AND WHAT IS THIS FILE'S. A component that
14
+ * delegates its central promise and does not say so is one nobody can audit, so
15
+ * the split is written out here and repeated on the page.
16
+ *
17
+ * Base UI (`@base-ui/react/field`, 1.7.0) owns EVERY id relationship:
18
+ * - `Field.Control` mints an id and registers it on the labelable context;
19
+ * `Field.Label` renders a real `<label for>` against that id, so the
20
+ * accessible name comes from a native label relationship rather than from
21
+ * `aria-label`.
22
+ * - `Field.Description` and `Field.Error` each register their own id into
23
+ * the same context on mount and REMOVE it on unmount; the control's
24
+ * `aria-describedby` is rebuilt from that set. This is the part hand-rolled
25
+ * forms get wrong: an error that unmounts and leaves its id behind points
26
+ * the description at nothing.
27
+ * - `aria-invalid` is applied to the control rather than the wrapper
28
+ * whenever the field's computed validity is false.
29
+ * - `data-invalid`, `data-valid`, `data-touched`, `data-dirty`, `data-filled`,
30
+ * `data-focused` and `data-disabled` on the root and the control.
31
+ *
32
+ * This file owns everything that is a JUDGEMENT rather than a mechanism:
33
+ * - that the label is required, visible and has no way to be hidden;
34
+ * - that the error appears IN ADDITION to the hint and never replaces it;
35
+ * - that the error is carried by a word, a glyph and the invalid state,
36
+ * which takes visible form as the left rule down the invalid field, and
37
+ * by no colour at all (see NO STATUS COLOUR below);
38
+ * - that optionality is marked in words inside the label, so it is part of
39
+ * the accessible name rather than a symbol beside it;
40
+ * - the `data-slot` names, the type steps, the spacing and the 44px floor.
41
+ *
42
+ * NO STATUS COLOUR, AND THIS IS THE DECISION MOST LIKELY TO BE "FIXED" BY
43
+ * SOMEBODY LATER. A form error is not a clinical status. The four status levels
44
+ * say how much attention a READING needs; painting a mistyped date in
45
+ * `--opsin-status-attention-*` would teach a reader that the colour meaning
46
+ * "this measurement needs a decision" also means "you typed the date wrong",
47
+ * and the two-axis rule is worth nothing if the axes leak into ordinary form
48
+ * chrome. There is also no non-clinical danger role in the product theme at
49
+ * all: the one the docs chrome uses is declared in `apps/www/app/globals.css`
50
+ * and resolves to nothing under /view, which the accessibility gate fails a
51
+ * component for reaching. So the error is carried by a glyph, the left rule
52
+ * down the invalid field, the emphasis shadow on the control, and the words. It
53
+ * is NOT carried by a weight change against the label. `text-opsin-headline` is
54
+ * what both the label and the error use, and `tokens/type.json` sets `headline`
55
+ * and `body` at the same 17px on purpose, so the error is heavier than the HINT
56
+ * but exactly as heavy as the LABEL directly above it. Anybody reading this
57
+ * file should not count weight as the carrier that separates an error from a
58
+ * field name; what separates them is the rule and the glyph. That is close to
59
+ * what the specification asks for anyway ("text plus an icon plus the invalid
60
+ * state"), arrived at from the other direction.
61
+ *
62
+ * The glyph is `CircleAlert` and it is deliberately NOT `TriangleAlert`. The
63
+ * triangle is `attention`'s glyph in CLINICAL_STATUS_META, and four distinct
64
+ * silhouettes only work as a vocabulary if nothing else in the system borrows
65
+ * one of them.
66
+ *
67
+ * IT IS A SERVER COMPONENT. Every Base UI part it composes carries its own
68
+ * 'use client', so the state, the effects and the id generation all happen
69
+ * inside the client boundary the primitive already declares. This file adds no
70
+ * hook, no state and no handler of its own. It maps props to markup, so a
71
+ * directive here would only pull the wrapper into a bundle it does not need to
72
+ * be in.
73
+ */
74
+ import type { ComponentPropsWithoutRef, CSSProperties, ReactElement, ReactNode } from "react";
75
+ import { type FormProps } from "@base-ui/react/form";
76
+ export interface FieldProps {
77
+ /**
78
+ * Required, visible, and never hidden. There is no `hideLabel` prop and no
79
+ * value of any other prop that removes it: a control whose name lives only in
80
+ * a placeholder loses it the moment somebody types.
81
+ */
82
+ label: string;
83
+ /**
84
+ * The control. Put a `Field.Control` here. Field supplies its id, its
85
+ * `aria-describedby` and its invalid state through context, so a product
86
+ * never wires them by hand. Anything else that participates in Base UI's
87
+ * field context works too; anything that does not gets a label pointing at
88
+ * nothing, which is the one failure this component cannot detect for you.
89
+ */
90
+ children: ReactNode;
91
+ /**
92
+ * Guidance shown before a mistake rather than after it. Stays visible when an
93
+ * error appears, because a reader who has just made a mistake still needs the
94
+ * guidance that would have prevented it.
95
+ */
96
+ hint?: string;
97
+ /**
98
+ * The error message, in the product's own words. Its presence marks the
99
+ * control invalid and adds the message to the control's description; it never
100
+ * removes the hint. Omit it and the field falls back to whatever the browser
101
+ * says about the control's own constraints, which is words opsinjs has not
102
+ * written.
103
+ */
104
+ error?: string;
105
+ /**
106
+ * Which state is marked, in words, inside the label. Mark the exception: in a
107
+ * form where most fields are required, mark the optional ones, and the
108
+ * reverse. Defaults to `"none"`, because marking both is the same as marking
109
+ * neither.
110
+ */
111
+ optionality?: "required" | "optional" | "none";
112
+ /**
113
+ * When the control's own constraints are checked. Governs the invalid state,
114
+ * not the `error` prop. A message the product passed in is a message the
115
+ * product has already decided to show. Defaults to `"submit-then-change"`:
116
+ * never tell somebody their answer is wrong while they are still typing it.
117
+ *
118
+ * The `submit-then-change` default needs Base UI's `<Form>` around the fields,
119
+ * which `Field.Form` re-exports. Base UI gates it on a flag that only its own
120
+ * form primitive ever sets, so inside a plain `<form>` the constraints are
121
+ * checked on Enter in a text input and at no other moment. `"blur"` needs no
122
+ * `<Form>`. Field cannot warn you when the `<Form>` is missing, because it is
123
+ * a server component with no hook to read the form context from, so the
124
+ * mismatch is documented here rather than reported at runtime. Passing `error`
125
+ * is unaffected either way, and is the path to be on.
126
+ */
127
+ validateOn?: "blur" | "submit-then-change";
128
+ /**
129
+ * Merged onto the root. Field lays its own parts out in a column and leaves
130
+ * the space BETWEEN fields to the form, which is the only place that knows
131
+ * how many there are.
132
+ */
133
+ className?: string;
134
+ }
135
+ export declare function Field({ label, children, hint, error, optionality, validateOn, className, }: FieldProps): import("react").JSX.Element;
136
+ export declare namespace Field {
137
+ var Control: typeof FieldControl;
138
+ var Form: typeof FieldForm;
139
+ }
140
+ type NativeInputProps = Omit<ComponentPropsWithoutRef<"input">, "children" | "className" | "color" | "defaultValue" | "style">;
141
+ export interface FieldControlProps extends NativeInputProps {
142
+ /**
143
+ * Renders a different element in place of the `<input>`, keeping every id and
144
+ * aria attribute Field generated: `render={<textarea rows={3} />}`. This is
145
+ * the escape hatch that makes the wiring guarantee survive a control opsinjs
146
+ * does not ship.
147
+ */
148
+ render?: ReactElement;
149
+ /**
150
+ * Only meaningful alongside `render`, for an element that has children of its
151
+ * own, such as the `<option>` list of a `<select>`. An `<input>` is void and
152
+ * takes none.
153
+ */
154
+ children?: ReactNode;
155
+ /** Merged onto the control. The control's own classes win where they conflict. */
156
+ className?: string;
157
+ /** The uncontrolled starting value. Use `value` and `onChange` for a controlled control. */
158
+ defaultValue?: string | number | readonly string[];
159
+ /** Merged onto the control. */
160
+ style?: CSSProperties;
161
+ }
162
+ /**
163
+ * The one part of Field that is a real export rather than a `data-slot`.
164
+ *
165
+ * Everywhere else in opsinjs a part is internal structure identified by
166
+ * `data-slot`, because the content arrives as a prop. Field is one of three
167
+ * exceptions, and the reason is specific: the CONSUMER supplies the control, and
168
+ * there is no prop that could carry an `<input>` with its own type, name,
169
+ * `autocomplete`, `inputmode`, value and change handler. So the slot is a
170
+ * component, and it is the only way to get the generated id, the description
171
+ * list and the invalid state onto an element this file never sees.
172
+ *
173
+ * It sets no `autocomplete` and no `inputmode` of its own. Both are required by
174
+ * the accessibility contract and both are answers only the product has: the
175
+ * right `autocomplete` token depends on what is being asked for, and a guess
176
+ * would fill somebody's postcode into a field asking for something else.
177
+ */
178
+ export declare function FieldControl({ className, ...props }: FieldControlProps): import("react").JSX.Element;
179
+ /** Props for `Field.Form`: Base UI Form's own props, re-exported unchanged. */
180
+ export type FieldFormProps = FormProps;
181
+ /**
182
+ * Base UI's `<Form>`, re-exported with a `data-slot`.
183
+ *
184
+ * It is Base UI's Form and not a part of Field. The "one of three exceptions"
185
+ * note above is about Field's PARTS, and a Form is not one of them, so that
186
+ * claim stays true and needs no edit. What this export is for is narrower: the
187
+ * default `validateOn` does nothing without a `<Form>` ancestor, because Base
188
+ * UI's submit mode reads a flag only its own Form sets, so wrapping the fields
189
+ * in `<Field.Form>` is what makes `submit-then-change` fire on submit at all. A
190
+ * product that already runs a form library should keep that library and pass
191
+ * `error` instead, which never goes through a validation mode.
192
+ */
193
+ export declare function FieldForm(props: FieldFormProps): import("react").JSX.Element;
194
+ export {};
195
+ //# sourceMappingURL=field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/components/field.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwEG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAG7F,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAqN3E,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;;OAMG;IACH,QAAQ,EAAE,SAAS,CAAA;IACnB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA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import { Field as FieldPrimitive } from "@base-ui/react/field";
3
+ import { Form as FormPrimitive } from "@base-ui/react/form";
4
+ import { CircleAlert } from "lucide-react";
5
+ import { isDevelopment } from "../opsinjs.js";
6
+ import { cn } from "../utils.js";
7
+ /**
8
+ * The two words Field ships, and the only reader-facing copy it owns.
9
+ *
10
+ * They are words rather than an asterisk on purpose: the specification asks for
11
+ * required and optional to be "marked in text, with a legend where a symbol is
12
+ * used", and a marker that needs a legend is a marker most readers meet without
13
+ * one. Rendered inside the `<label>`, so the accessible name is
14
+ * "Example measurement (optional)" and a screen-reader user hears the exception
15
+ * at the same moment a sighted reader sees it rather than as a floating symbol
16
+ * somewhere near the field.
17
+ *
18
+ * They are English, and there is no prop to translate them. That is a real gap
19
+ * and it is listed on the page rather than hidden here.
20
+ */
21
+ const OPTIONALITY_WORD = {
22
+ required: "(required)",
23
+ optional: "(optional)",
24
+ };
25
+ /**
26
+ * `validateOn` in this system's vocabulary, mapped to Base UI's.
27
+ *
28
+ * A SUBMIT-ONLY VALUE WAS REMOVED, because the runtime cannot honour it. Base
29
+ * UI's `onSubmit` is documented as "triggers validation when the form is
30
+ * submitted, and re-validates on change after submission", which IS this
31
+ * system's `submit-then-change`. There is no mode that validates on submit and
32
+ * then refuses to look again, so a bare `"submit"` had nowhere of its own to
33
+ * map, and a component should not offer a value it cannot keep. The union is
34
+ * the two the runtime can actually tell apart. The lost mode is one nobody
35
+ * should want anyway: it would leave a corrected field still marked invalid
36
+ * until the next submit, which is the cruelty the specification names. Field is
37
+ * more forgiving than asked, never less.
38
+ *
39
+ * `submit-then-change` NEEDS BASE UI'S `<Form>`, WHICH THE NAME DOES NOT
40
+ * SUGGEST. `onSubmit` is not "the browser submitted the form": Base UI gates it
41
+ * on a `submitAttemptedRef` that lives on its own form context (`form/Form.js`),
42
+ * and the context's default value is a ref that is permanently `false`. So
43
+ * inside a plain `<form onSubmit={…}>` with no `<Form>` ancestor, the control's
44
+ * OWN constraints are never checked on submit and never re-checked on change;
45
+ * the only remaining trigger is Base UI's Enter-key commit, and that fires on
46
+ * `<input>` alone. `Field.Form` re-exports that `<Form>` so the default value
47
+ * has a path to working; `"blur"` needs no `<Form>` and works as its name reads.
48
+ *
49
+ * This does not touch the `error` prop, which is the path a product should be
50
+ * on: `invalid` is applied from `error` directly and does not go through a
51
+ * validation mode at all. What it changes is how much the un-styled fallback
52
+ * branch below is really worth without a `<Form>`, and the page says so.
53
+ */
54
+ const VALIDATION_MODE = {
55
+ blur: "onBlur",
56
+ "submit-then-change": "onSubmit",
57
+ };
58
+ /**
59
+ * Written out rather than assembled, because Tailwind reads class names as
60
+ * literal strings and anything built at runtime generates no CSS at all.
61
+ *
62
+ * Four things here are load-bearing and easy to mistake for taste:
63
+ *
64
+ * `min-h-` AND `min-w-[var(--opsin-target-minimum,2.75rem)]` set the target
65
+ * floor on the control. `@opsinjs/react/base.css` now floors every text entry
66
+ * control, `select` and `textarea` included, with the same
67
+ * `--opsin-target-minimum` token and the same `2.75rem` fallback, so on the
68
+ * documentation site, which loads it, the floor is not at risk and a
69
+ * hand-rolled input beside a Field is protected by that stylesheet too. The
70
+ * reason to declare it again here is that `base.css` is opt-in: a consumer
71
+ * who imports only `styles.css` or `tailwind.css` does not get it, and
72
+ * without the local declaration the floor is simply absent in an app that
73
+ * installed the component and not the element rules. The token is a rem, so
74
+ * wherever it resolves it grows with the reader's own text size rather than
75
+ * staying at a fixed pixel count.
76
+ *
77
+ * Both axes, not just the block one, because `w-full` holds the inline axis
78
+ * only while nobody narrows the control. `FieldControlProps.className` is
79
+ * merged onto the control and the caller's classes win, so a two-digit
80
+ * numeric entry written `<Field.Control className="w-8" />` is a 32px target
81
+ * and nothing says so. `base.css` sets both `min-block-size` and
82
+ * `min-inline-size` on the controls it covers; this matches it.
83
+ *
84
+ * And the `2.75rem` fallback is not decoration. `@opsinjs/tokens/tokens.css`
85
+ * is the one place `--opsin-target-minimum` is declared, and it reaches a
86
+ * page only when the app imports it, directly or through `styles.css` or
87
+ * `tailwind.css`. Without the fallback the declaration is invalid at
88
+ * computed-value time in an app that has not wired the token sheet,
89
+ * `min-height` becomes `auto`, and the input still looks like an input and is
90
+ * simply short. That is the one degradation of this component nobody would
91
+ * notice. `base.css` and `button.tsx` both write the same fallback, for the
92
+ * same reason.
93
+ *
94
+ * No focus styles. `@opsinjs/react/base.css` gives every `:focus-visible` a
95
+ * two-pixel ring in `--ring` with a two-pixel offset, so a component that
96
+ * writes its own is a component that will drift from the rest of the product
97
+ * the first time that rule changes. That stylesheet is opt-in, and in an app
98
+ * that leaves it out the control keeps the browser's own focus indicator,
99
+ * because nothing here removes it.
100
+ *
101
+ * `data-[invalid]:` and not a colour. Base UI stamps `data-invalid` on the
102
+ * control, so the emphasis shadow tracks the field's real validity rather
103
+ * than only the half this file knows about. Real validity is the `error` prop
104
+ * AND a native constraint that failed. The shadow is an inset shadow rather
105
+ * than a wider border so that the control itself does not move by a pixel
106
+ * when the error appears, which is what marks WHICH control failed inside a
107
+ * Field that has more than one. Know what the shadow costs on its own: a
108
+ * `box-shadow` is dropped by forced-colors mode and by the docs stylesheet's
109
+ * print rules, so on paper and under Windows High Contrast that one carrier
110
+ * is gone. It is not swapped for an `outline` because `base.css` already
111
+ * spends the control's outline on `:focus-visible`, and a focused invalid
112
+ * field would then show one state or the other rather than both.
113
+ * `--opsin-border-emphasis` carries its `2px` fallback for the same reason
114
+ * the two above carry theirs, and the consequence for the shadow alone is
115
+ * worse: an invalid `box-shadow` built from a token that fails to resolve is
116
+ * not a short shadow but no shadow at all, so in an app without the token
117
+ * sheet the whole declaration drops. `button.tsx` writes the token the same
118
+ * way.
119
+ *
120
+ * Because a shadow can vanish that way, the invalid state has a fourth carrier
121
+ * that does not: a real left rule on the root, `data-[invalid]:border-l-*`
122
+ * with the width from `--opsin-border-emphasis` and the colour the `foreground`
123
+ * role, set beside the root's `pl-opsin-3` so the copy clears it. A border is a
124
+ * real property that forced-colors mode recolours to `CanvasText` and keeps,
125
+ * and the printer draws, so the invalid field is marked as invalid on paper
126
+ * and under Windows High Contrast where the shadow is not. This is the GOV.UK
127
+ * and NHS error-group device. The cost, named rather than hidden: the field
128
+ * indents by one space step at the moment it becomes invalid, so its column
129
+ * shifts left to right by that step. That shift is accepted because an error
130
+ * line appearing already reflows the column beneath it, so the field is moving
131
+ * anyway, and the shadow stays precisely because it is the carrier that does
132
+ * NOT move the control and so keeps pointing at the one that failed. So there
133
+ * are four carriers that are not colour, the glyph, the words, the shadow and
134
+ * the rule, and three of the four, the glyph, the words and now the rule,
135
+ * survive forced colours and print. Only the shadow does not. That leaves one
136
+ * gap the rule alone does not close: the rule sits on the field root, so under
137
+ * forced colours it says a field failed without saying which control did, and
138
+ * pointing at the offending control is the shadow's own job. The control
139
+ * closes that gap in forced-colors mode alone with
140
+ * `data-[invalid]:forced-colors:border-dashed`, which switches the control's
141
+ * already-repainted system-ink border from solid to dashed. The style change
142
+ * moves nothing by a pixel, needs no extra box, and leaves the
143
+ * `:focus-visible` outline untouched, so a focused invalid field still shows
144
+ * both. It is scoped to forced colours on purpose: outside that mode the
145
+ * shadow already marks the control and a second edge would be noise, and print
146
+ * stays a gap because the query does not fire on paper.
147
+ *
148
+ * AND ONE TRAP, because this list goes through `cn()` and the parts above do
149
+ * not. `cn` is `twMerge(clsx(...))`, and tailwind-merge is unconfigured. It has
150
+ * never been told that `--text-opsin-*` is a font-size namespace, so it files
151
+ * `text-opsin-body` and `text-foreground` in the SAME conflict group and
152
+ * silently drops whichever comes first. There is no ordering that keeps both.
153
+ * So the size is set here and the colour is not: Tailwind's preflight already
154
+ * gives every form control `color: inherit`, which takes the page's foreground
155
+ * and is one fewer value to keep in step. Adding a text colour to this list
156
+ * would remove the type step, not sit beside it.
157
+ */
158
+ const CONTROL_CLASS = [
159
+ "block w-full min-h-[var(--opsin-target-minimum,2.75rem)]",
160
+ "min-w-[var(--opsin-target-minimum,2.75rem)]",
161
+ "rounded-opsin-md border border-input bg-background [corner-shape:var(--opsin-corner-shape)]",
162
+ "px-opsin-4 py-opsin-2",
163
+ "placeholder:text-muted-foreground text-opsin-body",
164
+ "data-[invalid]:shadow-[inset_0_0_0_var(--opsin-border-emphasis,2px)_currentColor]",
165
+ "data-[invalid]:forced-colors:border-dashed",
166
+ "disabled:opacity-70",
167
+ ].join(" ");
168
+ /**
169
+ * Once per cause, not once per render.
170
+ *
171
+ * `tokens/errors.json`'s policy says warnings are emitted "once per offending
172
+ * call site, through console.warn", and `warnOnce()` in `../opsinjs.ts`
173
+ * implements that half for the codes in the table. Neither warning below has a
174
+ * code. See the note at the top of `Field`. The once-per-cause half of the
175
+ * policy is not attached to the code, though, and dropping it along with the
176
+ * code is how a component floods a console. Field is imported into a product's
177
+ * own form, which is a client component with state, so an empty `label` on a
178
+ * controlled field prints once per keystroke; Strict Mode doubles it; and the
179
+ * warning that gets buried is somebody else's.
180
+ *
181
+ * The key is the cause, never the whole message, so a message that carries the
182
+ * label does not mint a new key every time the label changes. Two consequences,
183
+ * both the same trade `warnOnce()` documents: the empty-`label` cause has
184
+ * nothing to distinguish one offender from another, so it collapses to one
185
+ * warning for the whole session; and on the server the module scope is the
186
+ * process, so it is one warning per process rather than per request. Coarse is
187
+ * the right direction. A repeated identical complaint teaches nothing.
188
+ */
189
+ const warnedCauses = new Set();
190
+ function warnDevelopmentOnce(cause, message) {
191
+ if (!isDevelopment() || warnedCauses.has(cause)) {
192
+ return;
193
+ }
194
+ warnedCauses.add(cause);
195
+ console.warn(message);
196
+ }
197
+ /**
198
+ * The error's classes, shared by both branches below so they cannot drift.
199
+ *
200
+ * `items-start` and not `items-center`: at 200% text a message wraps to three
201
+ * lines, and a centred glyph then floats in the middle of the paragraph.
202
+ */
203
+ const ERROR_CLASS = "m-0 flex items-start gap-opsin-1 text-opsin-headline text-foreground";
204
+ export function Field({ label, children, hint, error, optionality = "none", validateOn = "submit-then-change", className, }) {
205
+ /* THE TWO FAILURES THAT ARE WORTH A WARNING, and neither gets an OPSIN code.
206
+ `tokens/errors.json` has no entry for either, and a component may not mint
207
+ one: the table is generated from that file and the codes are a versioned
208
+ contract. A plain development warning, de-duplicated by cause the way that
209
+ file's policy asks for, is the honest channel.
210
+
211
+ Nothing is dropped from the render in either case. Field wraps somebody's
212
+ form control, and refusing to draw it in order to report a copy mistake
213
+ takes the form off the screen. */
214
+ if (label.trim() === "") {
215
+ warnDevelopmentOnce("empty-label", "[opsinjs] <Field> was given an empty `label`. The control now has no " +
216
+ "accessible name, which is the single thing this component exists to " +
217
+ "prevent. No substitute is invented here on purpose: a made-up name " +
218
+ 'like "Field" would silence the audit that would otherwise catch this. ' +
219
+ "See /docs/components/field.");
220
+ }
221
+ const message = error !== undefined && error.trim() !== "" ? error : undefined;
222
+ if (error !== undefined && message === undefined) {
223
+ warnDevelopmentOnce("empty-error:" + label, '[opsinjs] <Field label="' +
224
+ label +
225
+ '"> was given an empty `error` string. An ' +
226
+ "empty message would have marked the control invalid and then said " +
227
+ "nothing about why, so it was ignored. Pass a sentence that says what " +
228
+ "went wrong and what to do, or omit the prop.");
229
+ }
230
+ const marker = optionality === "none" ? null : OPTIONALITY_WORD[optionality];
231
+ return (_jsxs(FieldPrimitive.Root, { "data-slot": "field",
232
+ /* App-controlled invalidity. Base UI keeps this true even while the
233
+ field's own constraint validation says otherwise, which is what makes
234
+ a form library's verdict win over the browser's. */
235
+ invalid: message !== undefined, validationMode: VALIDATION_MODE[validateOn], className: cn("flex w-full flex-col gap-opsin-2 data-[invalid]:border-l-[length:var(--opsin-border-emphasis,2px)] data-[invalid]:border-l-foreground data-[invalid]:pl-opsin-3", className), children: [_jsxs(FieldPrimitive.Label, { "data-slot": "field-label", className: "text-opsin-headline text-foreground", children: [label, marker === null ? null : (_jsxs(_Fragment, { children: [" ", _jsx("span", { "data-slot": "field-optionality", className: "font-normal", children: marker })] }))] }), hint === undefined || hint.trim() === "" ? null : (_jsx(FieldPrimitive.Description, { "data-slot": "field-hint", className: "m-0 text-opsin-body text-muted-foreground", children: hint })), message === undefined ? (_jsx(FieldPrimitive.Error, { "data-slot": "field-error", className: ERROR_CLASS, role: "alert", "aria-atomic": "true" })) : (_jsxs(FieldPrimitive.Error, { match: true, "data-slot": "field-error", className: ERROR_CLASS, role: "alert", "aria-atomic": "true", children: [_jsx(CircleAlert, { "aria-hidden": "true", className: "mt-[0.1em] size-[1.25em] shrink-0" }), _jsx("span", { children: message })] })), children] }));
236
+ }
237
+ /**
238
+ * The one part of Field that is a real export rather than a `data-slot`.
239
+ *
240
+ * Everywhere else in opsinjs a part is internal structure identified by
241
+ * `data-slot`, because the content arrives as a prop. Field is one of three
242
+ * exceptions, and the reason is specific: the CONSUMER supplies the control, and
243
+ * there is no prop that could carry an `<input>` with its own type, name,
244
+ * `autocomplete`, `inputmode`, value and change handler. So the slot is a
245
+ * component, and it is the only way to get the generated id, the description
246
+ * list and the invalid state onto an element this file never sees.
247
+ *
248
+ * It sets no `autocomplete` and no `inputmode` of its own. Both are required by
249
+ * the accessibility contract and both are answers only the product has: the
250
+ * right `autocomplete` token depends on what is being asked for, and a guess
251
+ * would fill somebody's postcode into a field asking for something else.
252
+ */
253
+ export function FieldControl({ className, ...props }) {
254
+ return (_jsx(FieldPrimitive.Control, { ...props, "data-slot": "field-control", className: cn(CONTROL_CLASS, className) }));
255
+ }
256
+ /* Assigned after the declaration rather than through `Object.assign`, so the
257
+ function keeps its name in a stack trace and in React devtools. */
258
+ Field.Control = FieldControl;
259
+ /**
260
+ * Base UI's `<Form>`, re-exported with a `data-slot`.
261
+ *
262
+ * It is Base UI's Form and not a part of Field. The "one of three exceptions"
263
+ * note above is about Field's PARTS, and a Form is not one of them, so that
264
+ * claim stays true and needs no edit. What this export is for is narrower: the
265
+ * default `validateOn` does nothing without a `<Form>` ancestor, because Base
266
+ * UI's submit mode reads a flag only its own Form sets, so wrapping the fields
267
+ * in `<Field.Form>` is what makes `submit-then-change` fire on submit at all. A
268
+ * product that already runs a form library should keep that library and pass
269
+ * `error` instead, which never goes through a validation mode.
270
+ */
271
+ export function FieldForm(props) {
272
+ /* No base class to merge, and Base UI's `className` can be a callback rather
273
+ than a string, which `cn()` does not take, so `className` passes straight
274
+ through in `props` rather than through `cn` the way `Field.Control`'s does.
275
+ Only `data-slot` is added, and it is placed after the spread so the wrapper
276
+ name wins over anything a caller passes. */
277
+ return _jsx(FormPrimitive, { ...props, "data-slot": "field-form" });
278
+ }
279
+ /* Assigned the same way as `Field.Control`, so the function keeps its name in a
280
+ stack trace and in React devtools. */
281
+ Field.Form = FieldForm;
282
+ //# sourceMappingURL=field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.js","sourceRoot":"","sources":["../../src/components/field.tsx"],"names":[],"mappings":";AA4EA,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC9D,OAAO,EAAE,IAAI,IAAI,aAAa,EAAkB,MAAM,qBAAqB,CAAA;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAEhC;;;;;;;;;;;;;GAaG;AACH,MAAM,gBAAgB,GAA4C;IAChE,QAAQ,EAAE,YAAY;IACtB,QAAQ,EAAE,YAAY;CACvB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,eAAe,GAGjB;IACF,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,UAAU;CACjC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmGG;AACH,MAAM,aAAa,GAAG;IACpB,0DAA0D;IAC1D,6CAA6C;IAC7C,6FAA6F;IAC7F,uBAAuB;IACvB,mDAAmD;IACnD,mFAAmF;IACnF,4CAA4C;IAC5C,qBAAqB;CACtB,CAAC,IAAI,CAAC,GAAG,CAA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zB,SAAS,EAAE,EAAE,CAAC,aAAa,EAAE,SAAS,CAAC,GACvC,CACH,CAAA;AACH,CAAC;AAED;qEACqE;AACrE,KAAK,CAAC,OAAO,GAAG,YAAY,CAAA;AAK5B;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C;;;;kDAI8C;IAC9C,OAAO,KAAC,aAAa,OAAK,KAAK,eAAY,YAAY,GAAG,CAAA;AAC5D,CAAC;AAED;wCACwC;AACxC,KAAK,CAAC,IAAI,GAAG,SAAS,CAAA"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * GoalRing shows how far a reading has come towards a goal the product set,
3
+ * drawn as a ring, with the same fact stated in words beside it.
4
+ *
5
+ * THE RING REWARDS NOTHING, AND THAT IS THE WHOLE DESIGN. The roster declined
6
+ * goal rings for years because the pattern they come from turns progress into a
7
+ * game: a ring that closes, a streak that must not break, a celebration when it
8
+ * does and a quiet reproach when it does not. That is a fine incentive for
9
+ * somebody training and a bad one for somebody managing a condition, for whom a
10
+ * missed day is information rather than a failure. So this ring closes and stops.
11
+ * Nothing counts up on first paint, nothing sweeps, no streak is tracked, no
12
+ * confetti fires and no shame is implied. It draws where a number the product
13
+ * supplied sits against a goal the product supplied, and the words beside it
14
+ * carry every fact. Cover the ring with your hand and nothing is lost.
15
+ *
16
+ * OPSINJS OWNS NEITHER THE GOAL NOR THE WORDS. `goal` is the product's target,
17
+ * `label` is the product's name for what the ring counts, and `unit` is the
18
+ * product's unit. This component ships no default goal, no default label and no
19
+ * clinical vocabulary of any kind. It asserts one thing only, that a value is
20
+ * this far towards a goal somebody else chose, and it is careful never to be read
21
+ * as a verdict or as a target opsinjs set.
22
+ *
23
+ * IT IS A PRESENTATION LAYER. It renders what the product hands it and works out
24
+ * nothing a product should own. The one number it derives is the fraction of the
25
+ * goal reached, which is arithmetic over two numbers the product supplied, and it
26
+ * is shown as a plain progress sentence rather than a score. It reads no
27
+ * reference range, assigns no clinical status, and takes no `status` prop at all,
28
+ * because progress towards a goal is not a clinical verdict and must never be
29
+ * coloured as one.
30
+ *
31
+ * WHY `role="img"` AND NOT `meter` OR `progressbar`. `meter` announces a value
32
+ * within a measured range, which is a reading, and this is not one: it is a
33
+ * position against a goal a product set. `progressbar` implies a task advancing
34
+ * to completion under the interface's control, and a person's steps are not a
35
+ * task the app is running. Both roles also carry no words. So the ring is a
36
+ * labelled image, never focusable and never in the tab order, and every fact it
37
+ * carries is repeated in a visible text twin that no prop of this component turns
38
+ * off.
39
+ *
40
+ * THE THREE STATES ARE KEPT THREE. A finite value is progress and draws a fill.
41
+ * `null` is no reading yet, and it draws an empty ring with words that say so; it
42
+ * is never rendered as a value of zero, because an empty ring that meant zero and
43
+ * an empty ring that meant "nothing measured" would be the same picture telling
44
+ * two different truths. A value that is not a finite number is a third state
45
+ * again, a reading that arrived broken, and it is announced as one rather than
46
+ * drawn.
47
+ *
48
+ * COLOUR IS THE CATEGORY AXIS ONLY. The fill may take the identity tint of the
49
+ * kind of thing it counts, an activity ring in the activity colour, so a reader
50
+ * who keeps several rings can tell them apart. It never takes the status axis:
51
+ * this ring makes no clinical claim, so it carries `data-category` and never
52
+ * `data-status`, and the two are never on one element. Given no category it draws
53
+ * a neutral ring, which is the honest default rather than a borrowed colour.
54
+ */
55
+ import { type HealthCategory } from "../opsinjs.ts";
56
+ export interface GoalRingProps {
57
+ /**
58
+ * What the ring counts, in the reader's language: "Steps today", "Water", the
59
+ * product's own name for the thing, not an internal code. Required, because a
60
+ * ring with no label is a coloured arc a reader cannot name.
61
+ */
62
+ label: string;
63
+ /**
64
+ * The reading. `null` renders the no-reading state, an empty ring with words
65
+ * that say nothing has been measured yet. That is not a value of zero: zero is a
66
+ * real reading on a goal a person has not started against, and an absent reading
67
+ * is not a reading at all. A value that is not a finite number is a third state
68
+ * again, a reading that arrived broken, and it is announced rather than drawn.
69
+ */
70
+ value: number | null;
71
+ /**
72
+ * The target the product set, on the value's own scale. opsinjs ships no
73
+ * default goal and never invents one: a goal is a target somebody chose for
74
+ * somebody, and this component does not know the reader. A goal of zero or less,
75
+ * or one that is not a finite number, is not a goal a fraction can be taken
76
+ * against, so the ring is drawn empty and the words say the progress cannot be
77
+ * shown.
78
+ */
79
+ goal: number;
80
+ /**
81
+ * The unit the value and the goal are counted in, in the reader's language,
82
+ * such as "steps" or "ml". Optional: a goal that is a plain count needs none.
83
+ * It is printed after the numbers in the readout and never abbreviated by this
84
+ * component, because opsinjs does not own the reader's units.
85
+ */
86
+ unit?: string;
87
+ /**
88
+ * Tints the ring's fill with the identity colour of the kind of thing it
89
+ * counts, so a reader with several rings can tell them apart. It is the category
90
+ * axis and only the category axis: it says what the ring is about, never how
91
+ * urgent it is. Given none, the ring is drawn in a neutral tone. A value outside
92
+ * the known categories has no ramp, so it is refused with a development warning
93
+ * and the ring falls back to neutral rather than losing its fill silently.
94
+ */
95
+ category?: HealthCategory;
96
+ /**
97
+ * BCP 47 locale for every number. Omitted, the reader's own environment
98
+ * decides.
99
+ */
100
+ locale?: string;
101
+ /**
102
+ * Merged onto the root, and a class passed here wins over the component's own
103
+ * where the two conflict.
104
+ *
105
+ * That includes `truncate`, `sr-only`, a zeroed type size and any fixed height.
106
+ * The label, the readout and the progress sentence are mandatory content that no
107
+ * prop of this component removes, and a class that clips or hides them is the
108
+ * one way left to remove them anyway. The ring's own accessible name would
109
+ * survive; the words a sighted reader needs would not.
110
+ */
111
+ className?: string;
112
+ }
113
+ export declare function GoalRing({ label, value, goal, unit, category, locale, className, }: GoalRingProps): import("react").JSX.Element;
114
+ //# sourceMappingURL=goal-ring.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"goal-ring.d.ts","sourceRoot":"","sources":["../../src/components/goal-ring.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,eAAe,CAAA;AAwGtB,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB;;;;;;;OAOG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAMD,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,SAAS,GACV,EAAE,aAAa,+BAoRf"}