@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,167 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * Checkbox is a single labelled box for choosing one option on its own: a box
5
+ * that is ticked, not ticked, or in a mixed state that is neither. Its home is
6
+ * a lone agreement or a single setting a reader turns on or off, and it carries
7
+ * its own visible label and, when there is one, a line of supporting guidance
8
+ * beneath that label.
9
+ *
10
+ * IT IS THE SINGLE CHECKBOX, NOT A SET. A box for choosing any number of
11
+ * options from a list, where a parent box reflects and drives its children, is
12
+ * a checkbox group and belongs in a component that owns that relationship
13
+ * (Base UI publishes a CheckboxGroup primitive for exactly that). This file is
14
+ * one box. The three-state parent shown in the examples is a parent a PRODUCT
15
+ * wires up by passing `checked="indeterminate"` and handling the change; the
16
+ * mixed state is offered here so that a group built from these boxes has a head
17
+ * box to render, and nothing in this file assumes a group exists.
18
+ *
19
+ * WHY BASE UI'S Checkbox RATHER THAN A BARE <input type="checkbox">. A native
20
+ * checkbox cannot be styled to the box treatment this system asks for without
21
+ * hiding the real control and painting a stand-in, and a hidden control is the
22
+ * usual way a checkbox loses its keyboard behaviour and its form value. Base
23
+ * UI's Checkbox keeps a real hidden `<input>` for the form and renders a
24
+ * `<span>` as the visible box with `role="checkbox"` and `aria-checked`, so the
25
+ * keyboard contract (Tab to focus, Space to toggle) and the mixed state are the
26
+ * primitive's rather than this file's to get right. The tick is a
27
+ * Checkbox.Indicator that Base UI mounts only while the box is ticked or mixed,
28
+ * so the glyph is present in the DOM exactly when it has something to say.
29
+ *
30
+ * THE MIXED STATE HAS ITS OWN GLYPH, ON PURPOSE. A ticked box shows a lucide
31
+ * Check; a mixed box shows a lucide Minus. Two silhouettes rather than one
32
+ * means the difference between "this is on" and "some of what this stands for
33
+ * is on" survives greyscale and does not rest on the reader noticing that a
34
+ * tick has become a dash of a different shape. Which glyph is drawn is decided
35
+ * from the resolved state this file already holds, not read back out of the
36
+ * DOM, so the indicator never has to guess.
37
+ *
38
+ * NEITHER COLOUR AXIS. A checkbox records a choice; it states no clinical level
39
+ * and names no category, so it carries neither `data-status` nor `data-category`
40
+ * and draws no status or category hue. The ticked and mixed box is filled with
41
+ * the accent, `--brand`, and its paired ink, the selected-state role every
42
+ * selection control shares (ADR 0029), never a status hue. The unticked box is a neutral hairline on the page
43
+ * ground. The semantic carrier underneath the fill is `aria-checked`, which is
44
+ * `mixed` for the indeterminate box, rather than any pixel at all.
45
+ *
46
+ * THE LABEL IS REQUIRED AND VISIBLE. A checkbox with no words beside it asks a
47
+ * reader to guess what they are agreeing to, so `label` has no default and a
48
+ * missing one raises a development warning rather than rendering a bare box.
49
+ * The label wraps the box, so a tap anywhere across the label toggles it and the
50
+ * pointer target is the whole row rather than the twenty-pixel box; the optional
51
+ * `description` sits outside that label as a sibling and is tied to the box with
52
+ * `aria-describedby`, so it is announced as guidance rather than folded into the
53
+ * accessible name.
54
+ */
55
+ import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";
56
+ import { Check, Minus } from "lucide-react";
57
+ import { useId } from "react";
58
+ import { isDevelopment } from "../opsinjs.js";
59
+ import { cn } from "../utils.js";
60
+ /**
61
+ * The box itself, spelled once.
62
+ *
63
+ * The ticked and mixed states are carried three ways so none of them is
64
+ * load-bearing alone: `aria-checked` for assistive technology, the accent fill
65
+ * `--brand` lifting the box off the page ground for a sighted reader (ADR 0029),
66
+ * inside its `--brand-edge` rim where a bright accent needs one, and the glyph
67
+ * inside it for greyscale and for a reader stylesheet that strips fills. The
68
+ * unticked box is a neutral hairline on the background, so the two states differ
69
+ * in fill, in border and in glyph at once.
70
+ *
71
+ * The ink is written as the arbitrary property `[color:var(--brand-foreground)]`
72
+ * rather than a `text-*` class, for the reason `button.tsx` sets out at length:
73
+ * tailwind-merge files a `text-*` colour in the same conflict group as a type
74
+ * step and would drop one of them. The disabled box drops to the measured
75
+ * `--muted-foreground` chrome role rather than an opacity wash, so it stays
76
+ * readable while reading as unavailable.
77
+ *
78
+ * The focus ring is carried here rather than left to the product stylesheet, so
79
+ * a project installed without that stylesheet does not lose it. The box grows
80
+ * with the reader's text size because it is sized in rem, and the pointer target
81
+ * floor lives on the label row below, not on the box.
82
+ */
83
+ const CONTROL = "grid shrink-0 place-items-center size-[1.25rem] mt-[0.125rem] rounded-opsin-sm " +
84
+ "border border-border bg-background [color:var(--foreground)] " +
85
+ "transition-colors duration-(--opsin-duration-fast) ease-opsin-standard " +
86
+ "data-[checked]:border-brand-edge data-[checked]:bg-brand data-[checked]:[color:var(--brand-foreground)] " +
87
+ "data-[indeterminate]:border-brand-edge data-[indeterminate]:bg-brand data-[indeterminate]:[color:var(--brand-foreground)] " +
88
+ "data-[disabled]:cursor-not-allowed data-[disabled]:[color:var(--muted-foreground)] " +
89
+ "focus-visible:outline-ring focus-visible:outline-[length:var(--opsin-border-focus,2px)] focus-visible:outline-offset-[var(--opsin-border-focus-offset,2px)]";
90
+ /**
91
+ * TOGGLE, the second of the five interaction motions (ADR 0031), as a checkbox
92
+ * draws it: the tick writes itself.
93
+ *
94
+ * Base UI mounts the indicator only while the box is ticked or mixed, and
95
+ * marks its first frame `data-starting-style`, so both glyphs start with their
96
+ * stroke pushed out of sight along its own dash and then draw in on
97
+ * `spring-snap`, the spring tokens/motion.json names for a control the reader
98
+ * just flipped. The dash is 24 user units, longer than either path: the tick,
99
+ * `M20 6 9 17l-5-5`, is about 22.6 long, and the dash, `M5 12h14`, is 14. The
100
+ * tick starts from a negative offset, which reveals its path from the end, so
101
+ * the stroke runs the way a hand writes a tick, from the short arm down to the
102
+ * crook and up the long arm. The dash starts from a positive offset and draws
103
+ * from left to right. The box's fill changes on its own colour transition
104
+ * underneath. On untick the glyph fades on `ease-exit` over `duration-fast`
105
+ * rather than unwriting itself, because a reader does not need to watch a
106
+ * dismissal finish.
107
+ *
108
+ * A tick shows a choice and never a reading, so the spring's overshoot is
109
+ * allowed. Under `prefers-reduced-motion: reduce` `spring-snap` collapses to
110
+ * 0ms in the generated sheet and `duration-fast` to 1ms in the product sheet,
111
+ * so the tick is whole the frame after the box is ticked.
112
+ */
113
+ const INDICATOR = "group/tick grid place-items-center " +
114
+ "transition-opacity duration-(--opsin-duration-spring-snap) ease-opsin-spring-snap " +
115
+ "data-[starting-style]:opacity-0 data-[ending-style]:opacity-0 " +
116
+ "data-[ending-style]:duration-(--opsin-duration-fast) data-[ending-style]:ease-opsin-exit";
117
+ /** The tick, drawn from its short arm. See `INDICATOR`. */
118
+ const TICK = "size-[0.875rem] shrink-0 [stroke-dasharray:24] " +
119
+ "transition-[stroke-dashoffset] duration-(--opsin-duration-spring-snap) ease-opsin-spring-snap " +
120
+ "group-data-[starting-style]/tick:[stroke-dashoffset:-24]";
121
+ /** The dash, drawn from the left. See `INDICATOR`. */
122
+ const DASH = "size-[0.875rem] shrink-0 [stroke-dasharray:24] " +
123
+ "transition-[stroke-dashoffset] duration-(--opsin-duration-spring-snap) ease-opsin-spring-snap " +
124
+ "group-data-[starting-style]/tick:[stroke-dashoffset:24]";
125
+ /**
126
+ * The label row, spelled once. It wraps the box and the visible words, so a tap
127
+ * anywhere along it toggles the box and the row is the 44pt pointer target,
128
+ * floored at `--opsin-target-minimum` in rem so it grows with the reader's text
129
+ * size rather than pinning at a device pixel. `items-start` keeps the box
130
+ * aligned to the first line when the label wraps to two.
131
+ */
132
+ const ROW = "flex items-start gap-opsin-3 min-h-(--opsin-target-minimum,2.75rem) " +
133
+ "cursor-pointer select-none py-opsin-1";
134
+ /**
135
+ * Development warnings, said once per distinct offender. Nothing here has an
136
+ * `OpsinErrorCode`: the codes in `tokens/errors.json` describe mistakes a
137
+ * consumer makes with the clinical API, and a checkbox asserts nothing clinical.
138
+ * `divider.tsx` and `segmented-control.tsx` keep the same small set for the same
139
+ * reason.
140
+ */
141
+ const warned = new Set();
142
+ function warnDev(key, message) {
143
+ if (!isDevelopment() || warned.has(key))
144
+ return;
145
+ warned.add(key);
146
+ console.warn(message);
147
+ }
148
+ export function Checkbox({ label, checked, onCheckedChange, indeterminate, disabled = false, description, className, }) {
149
+ const generatedId = useId();
150
+ const labelId = `${generatedId}-label`;
151
+ const descriptionId = description ? `${generatedId}-description` : undefined;
152
+ if (isDevelopment()) {
153
+ if (typeof label !== "string" || label.trim() === "") {
154
+ warnDev("no-label", "[opsinjs] <Checkbox> was rendered with no `label`. The box needs a visible " +
155
+ "accessible name: without one a reader is asked to agree to something they " +
156
+ "cannot see, and a screen-reader user hears a checkbox with no idea what it " +
157
+ "chooses. Pass `label` with the words that name the choice.");
158
+ }
159
+ }
160
+ // The mixed state is reachable two ways, and `indeterminate` wins when both
161
+ // are given. A mixed box is not ticked, so its resolved checked value is
162
+ // false while the mixed flag carries the rest.
163
+ const isIndeterminate = indeterminate ?? checked === "indeterminate";
164
+ const resolvedChecked = checked === "indeterminate" ? false : checked;
165
+ return (_jsxs("div", { "data-slot": "checkbox", className: cn("flex flex-col gap-opsin-1", className), children: [_jsxs("label", { className: cn(ROW, disabled ? "cursor-not-allowed" : null), children: [_jsx(CheckboxPrimitive.Root, { "data-slot": "checkbox-control", checked: resolvedChecked, indeterminate: isIndeterminate, disabled: disabled, "aria-labelledby": labelId, "aria-describedby": descriptionId, onCheckedChange: (next) => onCheckedChange?.(next), className: CONTROL, children: _jsx(CheckboxPrimitive.Indicator, { "data-slot": "checkbox-indicator", className: INDICATOR, children: isIndeterminate ? (_jsx(Minus, { "aria-hidden": "true", className: DASH, strokeWidth: 3 })) : (_jsx(Check, { "aria-hidden": "true", className: TICK, strokeWidth: 3 })) }) }), _jsx("span", { id: labelId, "data-slot": "checkbox-label", className: cn("text-opsin-body", disabled ? "[color:var(--muted-foreground)]" : "[color:var(--foreground)]"), children: label })] }), description ? (_jsx("span", { id: descriptionId, "data-slot": "checkbox-description", className: "ps-[calc(1.25rem+var(--opsin-space-3,0.75rem))] text-opsin-footnote [color:var(--muted-foreground)]", children: description })) : null] }));
166
+ }
167
+ //# sourceMappingURL=checkbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../src/components/checkbox.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AACvE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAEhC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,GACX,iFAAiF;IACjF,+DAA+D;IAC/D,yEAAyE;IACzE,0GAA0G;IAC1G,4HAA4H;IAC5H,qFAAqF;IACrF,6JAA6J,CAAA;AAE/J;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,SAAS,GACb,qCAAqC;IACrC,oFAAoF;IACpF,gEAAgE;IAChE,0FAA0F,CAAA;AAE5F,2DAA2D;AAC3D,MAAM,IAAI,GACR,iDAAiD;IACjD,gGAAgG;IAChG,0DAA0D,CAAA;AAE5D,sDAAsD;AACtD,MAAM,IAAI,GACR,iDAAiD;IACjD,gGAAgG;IAChG,yDAAyD,CAAA;AAE3D;;;;;;GAMG;AACH,MAAM,GAAG,GACP,sEAAsE;IACtE,uCAAuC,CAAA;AAEzC;;;;;;GAMG;AACH,MAAM,MAAM,GAAG,IAA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,KAAC,iBAAiB,CAAC,IAAI,iBACX,kBAAkB,EAC5B,OAAO,EAAE,eAAe,EACxB,aAAa,EAAE,eAAe,EAC9B,QAAQ,EAAE,QAAQ,qBACD,OAAO,sBACN,aAAa,EAC/B,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,EAAE,CAAC,IAAI,CAAC,EAClD,SAAS,EAAE,OAAO,YAElB,KAAC,iBAAiB,CAAC,SAAS,iBAChB,oBAAoB,EAC9B,SAAS,EAAE,SAAS,YAEnB,eAAe,CAAC,CAAC,CAAC,CACjB,KAAC,KAAK,mBAAa,MAAM,EAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,GAAI,CAC9D,CAAC,CAAC,CAAC,CACF,KAAC,KAAK,mBAAa,MAAM,EAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,GAAI,CAC9D,GAC2B,GACP,EACzB,eACE,EAAE,EAAE,OAAO,eACD,gBAAgB,EAC1B,SAAS,EAAE,EAAE,CACX,iBAAiB,EACjB,QAAQ,CAAC,CAAC,CAAC,iCAAiC,CAAC,CAAC,CAAC,2BAA2B,CAC3E,YAEA,KAAK,GACD,IACD,EACP,WAAW,CAAC,CAAC,CAAC,CACb,eACE,EAAE,EAAE,aAAa,eACP,sBAAsB,EAChC,SAAS,EAAC,qGAAqG,YAE9G,WAAW,GACP,CACR,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * One item in the list. Kept as a local type rather than a fourth public export,
3
+ * for the reason `select.tsx` gives about its own option shape: the registry
4
+ * contract fixes a file at three public exports, so a consumer names this shape
5
+ * as `ComboboxProps["items"][number]` rather than importing a fourth symbol. The
6
+ * `{ value, label }` shape is the one Base UI reads directly, using the label for
7
+ * the input text and the value for the selected value, so no converter is needed.
8
+ */
9
+ interface ComboboxItem {
10
+ /** The value this item sets. Unique within the list, and what `value` matches. */
11
+ value: string;
12
+ /** The visible words, what is searched, and what fills the input once chosen. */
13
+ label: string;
14
+ }
15
+ export interface ComboboxProps {
16
+ /**
17
+ * The items to search, in the order they appear before any typing narrows
18
+ * them. Each item is a `{ value, label }` pair: the label is what is searched,
19
+ * shown in the list and written into the input once chosen, and the value is
20
+ * what `value` matches and what `onValueChange` reports. opsinjs ships none of
21
+ * these, because the list a health product searches is the product's to own and
22
+ * keep current, not the presentation layer's to guess.
23
+ */
24
+ items: ComboboxItem[];
25
+ /**
26
+ * The currently chosen value, matching one item's `value`, or `null` when
27
+ * nothing is chosen. This is a controlled component with no internal selection
28
+ * state, so the caller stores the value and passes it back. A non-null value
29
+ * that matches no item is treated as nothing chosen, and a development warning
30
+ * names it.
31
+ */
32
+ value: string | null;
33
+ /**
34
+ * Called with the new value when the reader chooses an item, or with `null`
35
+ * when the selection is cleared. The caller stores it and passes it back as
36
+ * `value`; the control keeps no state of its own.
37
+ */
38
+ onValueChange: (value: string | null) => void;
39
+ /**
40
+ * Required. The accessible name for the input, applied as its `aria-label`, so
41
+ * a screen-reader user hears what the field searches before they type. Name the
42
+ * thing being chosen, "Medication" rather than the current text. There is no
43
+ * default, because a guessed name would describe the wrong thing on most
44
+ * screens.
45
+ */
46
+ label: string;
47
+ /**
48
+ * The text shown in the empty input before the reader types. Keep it a short
49
+ * instruction such as "Search medications". It is a prompt, not a value, so it
50
+ * is never chosen and never reported. Omitted, the input is blank until typed
51
+ * into.
52
+ */
53
+ placeholder?: string;
54
+ /**
55
+ * The line shown inside the popup when the typed text matches no item. Keep it
56
+ * short and useful, such as "No matches. Check the spelling." Omitted, a plain
57
+ * fallback line is shown so a reader is never left staring at a blank popup.
58
+ */
59
+ emptyMessage?: string;
60
+ /**
61
+ * Merged onto the field box. Width, margin and place in a layout belong here. A
62
+ * class you pass wins over the box's own where the two conflict, because it is
63
+ * merged last. It is the one route by which colour can reach the control, and
64
+ * the two-colour-axes rule applies to it in full: a combobox takes neither a
65
+ * status nor a category tint.
66
+ */
67
+ className?: string;
68
+ }
69
+ export declare function Combobox({ items, value, onValueChange, label, placeholder, emptyMessage, className, }: ComboboxProps): import("react").JSX.Element;
70
+ export {};
71
+ //# sourceMappingURL=combobox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combobox.d.ts","sourceRoot":"","sources":["../../src/components/combobox.tsx"],"names":[],"mappings":"AA4DA;;;;;;;GAOG;AACH,UAAU,YAAY;IACpB,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAA;IACb,iFAAiF;IACjF,KAAK,EAAE,MAAM,CAAA;CACd;AAwID,MAAM,WAAW,aAAa;IAC5B;;;;;;;OAOG;IACH,KAAK,EAAE,YAAY,EAAE,CAAA;IACrB;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB;;;;OAIG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IAC7C;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,KAAK,EACL,aAAa,EACb,KAAK,EACL,WAAW,EACX,YAAY,EACZ,SAAS,GACV,EAAE,aAAa,+BA4Ff"}
@@ -0,0 +1,204 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * Combobox is a text input that filters a list as the reader types, then lets
5
+ * them choose one item from what is left. Its home is a single choice out of a
6
+ * list too long to scroll comfortably, a country, a city or a medication name
7
+ * being the shape it was built for, where typing a few letters is faster than
8
+ * paging through everything.
9
+ *
10
+ * opsinjs SHIPS NO VOCABULARY, AND THAT IS THE WHOLE POINT OF THIS COMPONENT.
11
+ * The hard part of a searchable list in a health product is never the widget. It
12
+ * is the list: which medicines, which conditions, which units, spelled which way,
13
+ * and kept current against which source. Getting that list wrong is a clinical
14
+ * mistake, so opsinjs refuses to own it. The component takes the items through
15
+ * the `items` prop and filters and renders exactly what the product hands it. It
16
+ * ships no default list, no built-in vocabulary, and no suggestion of its own,
17
+ * because a presentation layer that guessed a drug name would be asserting
18
+ * something it has no right to assert.
19
+ *
20
+ * IT IS BUILT ON BASE UI's Combobox, AND THAT IS WHERE THE KEYBOARD AND THE
21
+ * FILTERING COME FROM. The input is the one tab stop; typing filters the list
22
+ * with Base UI's default contains match; Arrow Down moves focus into the popup;
23
+ * the Arrow keys move a highlight through the matches; Enter chooses the
24
+ * highlighted item and closes; Escape closes without choosing. That is the
25
+ * WAI-ARIA combobox pattern rather than a bespoke one nobody has tested, and the
26
+ * primitive renders `role="combobox"` on the input, `role="listbox"` on the
27
+ * popup and `role="option"` with `aria-selected` on each item, so a screen reader
28
+ * reads the control in the register a reader expects.
29
+ *
30
+ * THE LIST FLOATS IN A PORTAL, ON PURPOSE. The matches are rendered through
31
+ * `Combobox.Portal` into a `Combobox.Positioner`, so the popup escapes the
32
+ * overflow clipping and stacking context of whatever card or scroll area the
33
+ * input sits in. The positioner publishes the input's width as `--anchor-width`
34
+ * and the room below as `--available-height`, so the popup matches the field and
35
+ * scrolls inside the viewport rather than growing past it. When nothing matches,
36
+ * `Combobox.Empty` announces the empty message politely instead of leaving a
37
+ * reader typing into a list that silently went blank.
38
+ *
39
+ * NEITHER COLOUR AXIS. A combobox picks a value; it states no clinical level and
40
+ * names no category, so it carries neither `data-status` nor `data-category` and
41
+ * draws only neutral chrome. The chosen item is marked in the list by a tick from
42
+ * `Combobox.ItemIndicator`, a lucide Check, rather than by a hue, so the
43
+ * selection survives greyscale and reads without colour, and the semantic carrier
44
+ * underneath it is `aria-selected` rather than any pixel at all.
45
+ *
46
+ * THE INPUT AND THE TRIGGER FLOOR THEIR TARGETS AND CARRY THEIR OWN RINGS. Both
47
+ * floor their hit area at `--opsin-target-minimum` in rem so a 44pt pressable
48
+ * region survives and grows with the reader's text size, and each carries the
49
+ * focus ring in its own class list so a project installed without the product
50
+ * stylesheet does not lose it. The placeholder ink is the measured
51
+ * `--muted-foreground` chrome role rather than an opacity wash, so an empty field
52
+ * stays legible while reading as unfilled.
53
+ */
54
+ import { Combobox as ComboboxPrimitive } from "@base-ui/react/combobox";
55
+ import { Check, ChevronsUpDown } from "lucide-react";
56
+ import { isDevelopment } from "../opsinjs.js";
57
+ import { cn } from "../utils.js";
58
+ /**
59
+ * The field box, spelled once. A hairline box on the background surface that
60
+ * holds the input and the trigger side by side, so the two read as one control
61
+ * rather than a text box with a stray button after it. It draws only the neutral
62
+ * chrome roles, so it can be mistaken for neither a status nor a category.
63
+ */
64
+ const FIELD = "flex w-full items-stretch gap-opsin-1 rounded-opsin-md border border-border " +
65
+ "bg-background [color:var(--foreground)]";
66
+ /**
67
+ * The input, spelled once. It grows to fill the field, draws no border of its own
68
+ * because the field box already has one, and floors its target at
69
+ * `--opsin-target-minimum` in rem with a literal fallback so the declaration
70
+ * stays valid where the token sheet was not installed. The ink is written as the
71
+ * arbitrary property `[color:var(--foreground)]` and not `text-foreground`, for
72
+ * the reason `select.tsx` sets out at length: tailwind-merge files a `text-*`
73
+ * colour in the same conflict group as the `text-opsin-*` type step and drops one
74
+ * of them, so the arbitrary property lands in the `color` group instead and both
75
+ * the ink and the size survive. The placeholder ink is the measured muted chrome
76
+ * role rather than an opacity wash. The focus ring is carried here rather than
77
+ * left to the product stylesheet, so a project installed without it keeps the
78
+ * ring.
79
+ */
80
+ const INPUT = "min-w-0 flex-1 bg-transparent px-opsin-3 py-opsin-2 " +
81
+ "min-h-(--opsin-target-minimum,2.75rem) rounded-opsin-md " +
82
+ "text-opsin-body [color:var(--foreground)] " +
83
+ "placeholder:[color:var(--muted-foreground)] " +
84
+ "focus-visible:outline-[length:var(--opsin-border-focus,2px)] focus-visible:outline-offset-[var(--opsin-border-focus-offset,2px)] focus-visible:outline-ring";
85
+ /**
86
+ * The trigger, spelled once. A button at the trailing edge that opens the popup
87
+ * without the reader having to type, carrying a lucide ChevronsUpDown in the
88
+ * muted chrome role. It floors the same target as the input and carries its own
89
+ * focus ring, so a reader who tabs to it rather than the input still meets a
90
+ * visible focus and a 44pt region.
91
+ */
92
+ const TRIGGER = "flex shrink-0 items-center justify-center px-opsin-2 " +
93
+ "min-h-(--opsin-target-minimum,2.75rem) min-w-(--opsin-target-minimum,2.75rem) " +
94
+ "rounded-opsin-md [color:var(--muted-foreground)] cursor-pointer " +
95
+ "transition-colors duration-(--opsin-duration-fast) ease-opsin-standard " +
96
+ "hover:bg-state-hover " +
97
+ "focus-visible:outline-[length:var(--opsin-border-focus,2px)] focus-visible:outline-offset-[var(--opsin-border-focus-offset,2px)] focus-visible:outline-ring";
98
+ /**
99
+ * UNFOLD, the fourth of the five interaction motions (ADR 0031), shared by every
100
+ * popup in the system so a list opens the way a menu, a select, a combobox, a
101
+ * popover and a tooltip all do.
102
+ *
103
+ * The list grows out of the input that opened it rather than appearing out
104
+ * of nowhere. `origin-(--transform-origin)` reads the point Base UI's
105
+ * positioner computes on the input's side of the popup, so it scales up from
106
+ * there and collapses back into it. It arrives from 0.96 and slightly soft, a
107
+ * 4px blur that clears as it settles, so it comes into focus the way an object
108
+ * does when it is brought close, on `spring-settle`, the spring
109
+ * tokens/motion.json names for popovers, tooltips and menus. It leaves faster
110
+ * than it came, to 0.98 and transparent on `ease-exit` over `duration-fast`,
111
+ * because a reader does not need to watch a dismissal finish. When Escape, or
112
+ * a second press on the control that opened it, closes it, Base UI marks the
113
+ * popup `data-instant="dismiss"`, and that cancels the transition, so a reader
114
+ * who asked for it gone has it gone at once. Base UI also marks a popup opened from the keyboard
115
+ * `data-instant="click"`, and that one is ignored on purpose: a reader who
116
+ * opens it with Enter sees the same unfold as a reader with a pointer.
117
+ *
118
+ * Under `prefers-reduced-motion: reduce` the scale and the blur are pinned to
119
+ * rest, and `spring-settle` collapses in the generated sheet to a 100ms linear
120
+ * fade, so the list still visibly appears and does not travel. The exit's
121
+ * `duration-fast` collapses to 1ms. The list holds suggestions and never a reading, so nothing here animates a value.
122
+ */
123
+ const UNFOLD = "origin-(--transform-origin) " +
124
+ "transition-[opacity,scale,filter] duration-(--opsin-duration-spring-settle) ease-opsin-spring-settle " +
125
+ "data-[starting-style]:opacity-0 data-[starting-style]:scale-96 data-[starting-style]:blur-xs " +
126
+ "data-[ending-style]:opacity-0 data-[ending-style]:scale-98 " +
127
+ "data-[ending-style]:duration-(--opsin-duration-fast) data-[ending-style]:ease-opsin-exit " +
128
+ "data-[instant=dismiss]:transition-none " +
129
+ "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[starting-style]:blur-none " +
130
+ "motion-reduce:data-[ending-style]:scale-100";
131
+ /**
132
+ * The popup surface, spelled once. A raised card with a hairline: `bg-card` lifts
133
+ * it off whatever it floats over, `border-border` draws its edge for greyscale,
134
+ * and the `overlay` material rung casts the one black-alpha shadow the material
135
+ * ladder publishes for a floating surface, so the list reads as a raised object
136
+ * rather than a flat block. It matches the input's width through the positioner's
137
+ * `--anchor-width` and caps its height at `--available-height` with an internal
138
+ * scroll, so a long list stays inside the viewport. Consuming the material token
139
+ * rather than a raw shadow literal keeps this file inside the colour contract.
140
+ * Its entrance and exit are `UNFOLD`, set out above.
141
+ */
142
+ const POPUP = "max-h-[var(--available-height)] w-[var(--anchor-width)] overflow-y-auto " +
143
+ "rounded-opsin-md border border-edge bg-card p-opsin-1 " +
144
+ "shadow-(--opsin-material-raised-shadow) [color:var(--foreground)] " +
145
+ UNFOLD;
146
+ /**
147
+ * One match row, spelled once. A full-width row with the label on the left and
148
+ * room for the tick on the right. The highlight is the neutral `state-hover`
149
+ * surface switched on by `data-highlighted`, which is the active match under the
150
+ * Arrow keys and under the pointer, so the roving highlight is visible without a
151
+ * colour on either axis. Each row floors its target at `--opsin-target-minimum`
152
+ * so a touch reader gets a 44pt row.
153
+ */
154
+ const ITEM = "relative flex w-full cursor-pointer select-none items-center gap-opsin-2 " +
155
+ "rounded-opsin-sm px-opsin-3 py-opsin-2 min-h-(--opsin-target-minimum,2.75rem) " +
156
+ "text-opsin-body [color:var(--foreground)] outline-none " +
157
+ "data-[highlighted]:bg-state-hover";
158
+ /**
159
+ * The empty message, spelled once. Muted chrome ink at the footnote step, so a
160
+ * reader who has filtered everything away meets a quiet line of guidance rather
161
+ * than a blank popup. Base UI keeps this element mounted and announces its
162
+ * children politely, so the message is read when the matches run out.
163
+ */
164
+ const EMPTY = "px-opsin-3 py-opsin-2 text-opsin-footnote [color:var(--muted-foreground)]";
165
+ /**
166
+ * Development warnings, said once per distinct offender. Nothing here has an
167
+ * `OpsinErrorCode`: the codes in `tokens/errors.json` describe mistakes a
168
+ * consumer makes with the clinical API, and a combobox asserts nothing clinical.
169
+ * `select.tsx` keeps the same small set for the same reason.
170
+ */
171
+ const warned = new Set();
172
+ function warnDev(key, message) {
173
+ if (!isDevelopment() || warned.has(key))
174
+ return;
175
+ warned.add(key);
176
+ console.warn(message);
177
+ }
178
+ export function Combobox({ items, value, onValueChange, label, placeholder, emptyMessage, className, }) {
179
+ if (isDevelopment()) {
180
+ if (!Array.isArray(items) || items.length === 0) {
181
+ warnDev("no-items", "[opsinjs] <Combobox> was rendered with no items, so it has nothing to " +
182
+ "search. A combobox filters a list the product supplies; pass it " +
183
+ "through the `items` prop. opsinjs ships no vocabulary of its own.");
184
+ }
185
+ if (typeof label !== "string" || label.trim() === "") {
186
+ warnDev("no-label", "[opsinjs] <Combobox> was rendered with no `label`. The input is a " +
187
+ "combobox and needs an accessible name: without one a screen-reader " +
188
+ "user hears a text field with no idea what it searches. Pass `label` " +
189
+ 'with the name of the thing being chosen, such as "Medication".');
190
+ }
191
+ if (Array.isArray(items) &&
192
+ items.length > 0 &&
193
+ typeof value === "string" &&
194
+ value !== "" &&
195
+ !items.some((item) => item.value === value)) {
196
+ warnDev(`value-not-in-items:${value}`, `[opsinjs] <Combobox value="${value}"> does not match any item's value, ` +
197
+ "so the control renders with nothing chosen. This is a controlled " +
198
+ "component: pass a `value` equal to one item's `value`, or `null`.");
199
+ }
200
+ }
201
+ const selected = typeof value === "string" ? (items.find((item) => item.value === value) ?? null) : null;
202
+ return (_jsxs(ComboboxPrimitive.Root, { items: items, value: selected, onValueChange: (next) => onValueChange(next ? next.value : null), children: [_jsxs("div", { "data-slot": "combobox", className: cn(FIELD, className), children: [_jsx(ComboboxPrimitive.Input, { "data-slot": "combobox-input", "aria-label": label, placeholder: placeholder, className: INPUT }), _jsx(ComboboxPrimitive.Trigger, { "data-slot": "combobox-trigger", "aria-label": `Show ${label} options`, className: TRIGGER, children: _jsx(ChevronsUpDown, { "aria-hidden": "true", className: "size-[1em]" }) })] }), _jsx(ComboboxPrimitive.Portal, { children: _jsx(ComboboxPrimitive.Positioner, { className: "z-50", sideOffset: 6, children: _jsxs(ComboboxPrimitive.Popup, { "data-slot": "combobox-popup", className: POPUP, children: [_jsx(ComboboxPrimitive.Empty, { "data-slot": "combobox-empty", className: EMPTY, children: emptyMessage ? emptyMessage : "No matches." }), _jsx(ComboboxPrimitive.List, { children: (item) => (_jsxs(ComboboxPrimitive.Item, { value: item, "data-slot": "combobox-item", className: ITEM, children: [_jsx("span", { "data-slot": "combobox-item-label", className: "truncate", children: item.label }), _jsx(ComboboxPrimitive.ItemIndicator, { "data-slot": "combobox-item-indicator", className: "ml-auto flex shrink-0 items-center [color:var(--foreground)]", children: _jsx(Check, { "aria-hidden": "true", className: "size-[1em]" }) })] }, item.value)) })] }) }) })] }));
203
+ }
204
+ //# sourceMappingURL=combobox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combobox.js","sourceRoot":"","sources":["../../src/components/combobox.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE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