@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
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @opsinjs/react
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - The first release of @opsinjs/react: the 60 opsinjs components, the shared substrate (`cn`, the unit table, error codes, the clinical vocabulary and the shared types), a precompiled stylesheet (`@opsinjs/react/styles.css`), a Tailwind CSS v4 entry (`@opsinjs/react/tailwind.css`) and the opt-in element rules (`@opsinjs/react/base.css`). Each component is also importable on its own as `@opsinjs/react/<id>`.
8
+
9
+ opsinjs is at 0.x. The API may change in any release, and no component has had an independent accessibility review or a clinical review.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 the opsinjs authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,115 @@
1
- # Temporary Holding Version
1
+ # @opsinjs/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React components for consumer health apps: readings, reference ranges, clinical status and the controls around them, built on Base UI.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@opsinjs/react)](https://www.npmjs.com/package/@opsinjs/react)
6
+ [![licence](https://img.shields.io/npm/l/@opsinjs/react)](https://github.com/prashantonomy/opsinjs/blob/main/packages/react/LICENSE)
7
+
8
+ opsinjs is for the screen where somebody who is not a clinician reads their own blood
9
+ pressure, HbA1c or symptom log. This package holds its 60 components, the shared
10
+ substrate they use (units, error codes, the clinical status vocabulary and `cn`) and
11
+ the stylesheets.
12
+
13
+ > **Review status.** The components are implemented and installable, and the API may
14
+ > change in any release. No component has had an independent accessibility review or a
15
+ > clinical review, so they are not for a production health surface. Each component's
16
+ > page in the documentation lists what has not been measured.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install @opsinjs/react
22
+ ```
23
+
24
+ `@opsinjs/tokens` comes with it. React 19 and React DOM 19 are peer dependencies. The
25
+ package is ESM-only and declares Node 20.19 or newer.
26
+
27
+ ## Add the styles
28
+
29
+ Choose one.
30
+
31
+ **An app without Tailwind.** Import the precompiled stylesheet once, at the root of the
32
+ app:
33
+
34
+ ```ts
35
+ import "@opsinjs/react/styles.css"
36
+ ```
37
+
38
+ It holds the tokens, the role layer and only the utilities the components use. It has
39
+ no preflight, so it never resets the rest of your page, and its utilities sit in
40
+ cascade layers, so your own unlayered CSS wins.
41
+
42
+ **An app on Tailwind CSS v4.** In your stylesheet:
43
+
44
+ ```css
45
+ @import "tailwindcss";
46
+ @import "@opsinjs/react/tailwind.css";
47
+ ```
48
+
49
+ That loads the tokens, the role layer and the theme bridge, and points Tailwind at the
50
+ compiled components. The opsinjs utilities, such as `text-opsin-headline`,
51
+ `bg-background` and `rounded-opsin-*`, then work in your own code as well.
52
+
53
+ **Optional, either way.** `@opsinjs/react/base.css` holds the element rules: the html
54
+ font, the body background and ink, the border role on every element, the selection
55
+ wash, the focus ring, tabular figures on `[data-opsinjs-value]`, and a 2.75rem target
56
+ floor on buttons, inputs, selects and textareas. It is opt-in because it reaches every element on the page, not only opsinjs
57
+ ones.
58
+
59
+ ## Use a component
60
+
61
+ ```tsx
62
+ import { Button, StatusPill, type ClinicalStatus } from "@opsinjs/react"
63
+
64
+ export function ReadingSummary({ status }: { status: ClinicalStatus }) {
65
+ return (
66
+ <>
67
+ {/* The status comes from your data. opsinjs never decides one. */}
68
+ <StatusPill status={status} describes="Blood pressure" />
69
+ <Button variant="primary">Log a reading</Button>
70
+ </>
71
+ )
72
+ }
73
+ ```
74
+
75
+ One component on its own is also a subpath, named by its kebab-case id:
76
+
77
+ ```ts
78
+ import { RangeBar } from "@opsinjs/react/range-bar"
79
+ ```
80
+
81
+ In the Next.js App Router, 27 of the 60 components carry `"use client"`, and every one
82
+ of them can be imported from a server component.
83
+
84
+ ## Theme it
85
+
86
+ - **Dark mode** is the `.dark` class on an ancestor, usually `<html>`.
87
+ - **Accent themes** are `data-accent-theme="normal" | "vibes" | "stryk"` with
88
+ `data-accent="cobalt" | "sky" | "jade" | "volt" | "rose" | "orchid" | "violet" | "iris" | "graphite"`
89
+ on any element, and they theme everything inside it.
90
+ - **Compact density** is `data-density="compact"`.
91
+
92
+ Change opsinjs through its tokens and roles, which are CSS custom properties, and by
93
+ wrapping or composing components. The source is in the repository under MIT if you
94
+ need to fork one, but forking gives up the fixes later releases bring.
95
+
96
+ ## Upgrade
97
+
98
+ `npm update @opsinjs/react`, then read the
99
+ [changelog](https://github.com/prashantonomy/opsinjs/blob/main/packages/react/CHANGELOG.md). opsinjs is at 0.x,
100
+ and any release may change the API. A team that has to evidence its dependencies pins an
101
+ exact version and reads the changelog before moving it.
102
+
103
+ ## Links
104
+
105
+ - [Documentation](https://opsinjs.pensievelabs.org/docs)
106
+ - [Getting started](https://opsinjs.pensievelabs.org/docs/getting-started)
107
+ - [Components](https://opsinjs.pensievelabs.org/docs/components)
108
+ - [Source and issues](https://github.com/prashantonomy/opsinjs)
109
+ - [Report a safety concern](https://github.com/prashantonomy/opsinjs/issues/new?template=safety-concern.yml)
110
+
111
+ ## Licence
112
+
113
+ [MIT](https://github.com/prashantonomy/opsinjs/blob/main/packages/react/LICENSE). opsinjs is a presentation layer. It does not diagnose, triage or
114
+ decide what a number means; thresholds, reference ranges and clinical wording belong to
115
+ the product that uses it.
@@ -0,0 +1,82 @@
1
+ import type { ReactNode } from "react";
2
+ /**
3
+ * One section in the stack. Kept as a local type rather than a fourth public
4
+ * export, for the reason `segmented-control.tsx` gives about its own option
5
+ * shape: the registry contract fixes this file at three public exports, so a
6
+ * consumer names this shape as `AccordionProps["items"][number]` rather than
7
+ * importing a fourth symbol.
8
+ */
9
+ interface AccordionSection {
10
+ /**
11
+ * The value that identifies this section. Unique within the stack, and what
12
+ * `value` and `defaultValue` match against. It is what a controlled caller
13
+ * stores to say which sections are open.
14
+ */
15
+ value: string;
16
+ /**
17
+ * The header's words, shown in the trigger button beside the chevron. Keep it
18
+ * to a short, scannable line: a reader reads the whole stack of headers before
19
+ * opening any one panel, so a header that runs to a sentence defeats the index.
20
+ */
21
+ title: ReactNode;
22
+ /**
23
+ * The panel's content, revealed when the section is open. Ordinary content
24
+ * only. Nothing a reader must always see belongs here, because a collapsed
25
+ * panel is hidden by default; put a safety message or an urgent instruction in
26
+ * a card or a callout that stays open on the surface instead.
27
+ */
28
+ content: ReactNode;
29
+ /**
30
+ * Whether this section cannot be opened. A disabled header stays in the tab
31
+ * order so a reader still meets it, drops to the muted ink, and does not toggle
32
+ * its panel. Defaults to open-able.
33
+ */
34
+ disabled?: boolean;
35
+ }
36
+ export interface AccordionProps {
37
+ /**
38
+ * The sections, in the order they appear. Each is a value, a header title, the
39
+ * panel content, and an optional `disabled` flag. An empty array renders
40
+ * nothing and raises a development warning, because an accordion with no
41
+ * sections has nothing to disclose.
42
+ */
43
+ items: AccordionSection[];
44
+ /**
45
+ * Whether more than one section may be open at once. Left off, opening a
46
+ * section closes the others, which suits a small screen where a stack of open
47
+ * panels would grow past the fold. Set it when the sections are independent and
48
+ * a reader may want several open together. Defaults to `false`.
49
+ */
50
+ multiple?: boolean;
51
+ /**
52
+ * The sections open on first render, by their `value`, when the accordion
53
+ * manages its own open state. Use this for an uncontrolled accordion; for a
54
+ * controlled one, use `value` and `onValueChange` instead. Omitted, every
55
+ * section starts closed.
56
+ */
57
+ defaultValue?: string[];
58
+ /**
59
+ * The sections that are open, by their `value`, when the caller controls the
60
+ * open state. Pass it together with `onValueChange`. A `value` here that
61
+ * matches no section's `value` simply opens nothing, so a stale entry is
62
+ * harmless rather than a crash.
63
+ */
64
+ value?: string[];
65
+ /**
66
+ * Called with the new list of open section values when the reader opens or
67
+ * closes a section. The caller stores it and passes it back as `value`; with
68
+ * `value` set and this omitted, the accordion cannot change and reads as fixed.
69
+ */
70
+ onValueChange?: (value: string[]) => void;
71
+ /**
72
+ * Merged onto the root. Width, margin and place in a layout belong here. It is
73
+ * the one route by which colour can reach an accordion, and the two-colour-axes
74
+ * rule applies to it in full: an accordion takes neither a status nor a
75
+ * category tint. A class you pass wins over the root's own where the two
76
+ * conflict, because it is merged last.
77
+ */
78
+ className?: string;
79
+ }
80
+ export declare function Accordion({ items, multiple, defaultValue, value, onValueChange, className, }: AccordionProps): import("react").JSX.Element | null;
81
+ export {};
82
+ //# sourceMappingURL=accordion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accordion.d.ts","sourceRoot":"","sources":["../../src/components/accordion.tsx"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKtC;;;;;;GAMG;AACH,UAAU,gBAAgB;IACxB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,KAAK,EAAE,SAAS,CAAA;IAChB;;;;;OAKG;IACH,OAAO,EAAE,SAAS,CAAA;IAClB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AA2FD,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,KAAK,EAAE,gBAAgB,EAAE,CAAA;IACzB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IACzC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,QAAgB,EAChB,YAAY,EACZ,KAAK,EACL,aAAa,EACb,SAAS,GACV,EAAE,cAAc,sCA2DhB"}
@@ -0,0 +1,154 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ /**
4
+ * Accordion is a stack of sections that each expand and collapse, so a long page
5
+ * of headings can be scanned first and read second. Its home is a set of related
6
+ * passages a reader wants an index of before they commit to any one of them, a
7
+ * list of questions and answers being the case it was built for.
8
+ *
9
+ * ONE THING IT MUST NEVER DO, STATED FIRST BECAUSE IT IS THE ONE THAT MATTERS.
10
+ * A collapsed panel is hidden by default, so nothing a reader must not miss may
11
+ * live inside one. A safety message, an urgent instruction, a warning about a
12
+ * dose or an interaction, a step a reader has to take: none of these belong in a
13
+ * panel that is shut when the screen loads, because a reader who never opens the
14
+ * panel never meets the message, and that is a defect whatever component drew the
15
+ * panel. Content a reader must always see belongs in a card or a callout that is
16
+ * open on the surface at all times. This wrapper cannot inspect the words a
17
+ * caller places inside it, so the rule is a contract stated here and on the page
18
+ * rather than a check the code can make.
19
+ *
20
+ * WHY BASE UI'S Accordion RATHER THAN A PAIR OF <button> AND A HIDDEN <div>. The
21
+ * naive build, a button that toggles a sibling's `hidden`, drops every keyboard
22
+ * and screen-reader affordance the pattern owes. Base UI's Accordion renders the
23
+ * header as an `<h3>` with a `<button>` inside it, wires `aria-expanded` and
24
+ * `aria-controls` between the trigger and its panel, and manages open state for
25
+ * the single-open and multi-open cases both, so a reader meets the WAI-ARIA
26
+ * disclosure pattern rather than a bespoke one nobody has tested. Each trigger is
27
+ * an ordinary tab stop, which is correct here: unlike a segmented control, an
28
+ * accordion is a set of independent disclosures and a reader expects Tab to visit
29
+ * each header in turn.
30
+ *
31
+ * NEITHER COLOUR AXIS. An accordion organises content: it states no clinical
32
+ * level and names no category, so it carries neither `data-status` nor
33
+ * `data-category` and draws only neutral chrome. The chevron and the header ink
34
+ * are the two things that move, and both are neutral. When a section is about a
35
+ * measurement, the level and the words for it are the consuming product's to
36
+ * place inside the panel with the components that carry them, and the accordion
37
+ * around them stays plain.
38
+ *
39
+ * SINGLE OPEN IS THE DEFAULT, AND THAT IS DELIBERATE. With `multiple` left off,
40
+ * opening one section closes the others, which keeps a small screen from growing
41
+ * a wall of open panels the reader then has to scroll past. Set `multiple` when
42
+ * the sections are independent and a reader may want several open at once, such
43
+ * as a set of filters. Base UI's own default is the same, so the prop maps
44
+ * straight through.
45
+ */
46
+ import { Accordion as BaseAccordion } from "@base-ui/react/accordion";
47
+ import { ChevronDown } from "lucide-react";
48
+ import { isDevelopment } from "../opsinjs.js";
49
+ import { cn } from "../utils.js";
50
+ /**
51
+ * The stack, spelled once. A single card surface with a hairline, the sections
52
+ * set into it and divided by hairlines, so the whole control reads as one object
53
+ * rather than a row of loose bars. `overflow-hidden` keeps the first and last
54
+ * sections' corners inside the rounded border.
55
+ */
56
+ const ROOT = "overflow-hidden rounded-opsin-md border border-edge bg-card shadow-card [corner-shape:var(--opsin-corner-shape)] print:border-border";
57
+ /**
58
+ * One section wrapper. The top hairline divides it from the section above; the
59
+ * first section drops it, because the root's own border already draws that edge.
60
+ */
61
+ const ITEM = "border-t border-edge first:border-t-0";
62
+ /**
63
+ * The header row and its button, spelled once.
64
+ *
65
+ * The trigger is a full-width button with the title on one side and the chevron
66
+ * on the other. The ink is written as the arbitrary property
67
+ * `[color:var(--foreground)]` and not `text-foreground`, for the reason
68
+ * `segmented-control.tsx` sets out: tailwind-merge files a `text-*` colour in the
69
+ * same conflict group as the `text-opsin-*` type step and would drop one of them.
70
+ * A disabled header drops to the measured `--muted-foreground` chrome role rather
71
+ * than an opacity wash, so it stays readable while reading as unavailable.
72
+ *
73
+ * The focus ring is carried here rather than left to the product stylesheet, so a
74
+ * project installed without that stylesheet does not lose it. The target floor is
75
+ * `--opsin-target-minimum` in rem, so the 44pt pressable region grows with the
76
+ * reader's text size rather than pinning at a device pixel, with a literal
77
+ * fallback so the declaration stays valid where the generated token sheet was not
78
+ * installed. The offset is negated so the ring draws inside the trigger rather
79
+ * than around it. The root sets `overflow-hidden` to keep the first and last
80
+ * corners rounded, and the trigger runs edge to edge inside it, so an outward
81
+ * ring would be clipped on its left and right and on the top of the first
82
+ * section. An inset ring sits within that clip and stays whole along every
83
+ * straight edge. One honest limit remains: the trigger keeps square corners
84
+ * while the root clips to a rounded radius, so on the first section's top
85
+ * corners and the last section's bottom corners the square ring is trimmed to
86
+ * a small notch where the curve cuts in. Most of the ring is present and the
87
+ * focus stays clearly visible, so this does not reopen the 2.4.7 gap the inset
88
+ * closed, but the ring is not literally unbroken at those two pairs of corners.
89
+ * `group` is set so the chevron can read the trigger's own `data-panel-open`
90
+ * state and turn with it.
91
+ */
92
+ const TRIGGER = "group flex w-full items-center justify-between gap-opsin-3 " +
93
+ "px-opsin-4 py-opsin-3 text-left align-middle text-opsin-headline font-medium " +
94
+ "min-h-(--opsin-target-minimum,2.75rem) cursor-pointer [color:var(--foreground)] " +
95
+ "transition-colors duration-(--opsin-duration-fast) ease-opsin-standard " +
96
+ "hover:bg-state-hover " +
97
+ "data-[disabled]:cursor-not-allowed data-[disabled]:[color:var(--muted-foreground)] data-[disabled]:hover:bg-transparent " +
98
+ "focus-visible:outline-[length:var(--opsin-border-focus,2px)] focus-visible:outline-offset-[calc(var(--opsin-border-focus-offset,2px)*-1)] focus-visible:outline-ring";
99
+ /**
100
+ * The chevron. It rotates a half turn when its section opens, reading the
101
+ * trigger's `data-panel-open` through the `group` on the trigger. `shrink-0`
102
+ * keeps it from squashing when the title wraps. It is decorative: the open state
103
+ * a reader relies on is `aria-expanded` on the button, which Base UI sets, so the
104
+ * chevron is `aria-hidden` and carries no meaning of its own.
105
+ */
106
+ const CHEVRON = "size-[1em] shrink-0 [color:var(--muted-foreground)] " +
107
+ "transition-transform duration-(--opsin-duration-fast) ease-opsin-standard " +
108
+ "group-data-[panel-open]:rotate-180";
109
+ /**
110
+ * The panel that holds a section's content. The top padding is dropped because
111
+ * the header above already spaces it; the reader gets the body ink at the body
112
+ * step. Base UI unmounts the panel while the section is closed, so a shut section
113
+ * costs nothing and its content is not in the tab order.
114
+ */
115
+ const PANEL = "px-opsin-4 pb-opsin-4 text-opsin-body [color:var(--foreground)]";
116
+ /**
117
+ * Development warnings, said once per distinct offender. Nothing here has an
118
+ * `OpsinErrorCode`: the codes in `tokens/errors.json` describe mistakes a
119
+ * consumer makes with the clinical API, and an accordion asserts nothing
120
+ * clinical. `segmented-control.tsx` and `divider.tsx` keep the same small set for
121
+ * the same reason.
122
+ */
123
+ const warned = new Set();
124
+ function warnDev(key, message) {
125
+ if (!isDevelopment() || warned.has(key))
126
+ return;
127
+ warned.add(key);
128
+ console.warn(message);
129
+ }
130
+ export function Accordion({ items, multiple = false, defaultValue, value, onValueChange, className, }) {
131
+ if (isDevelopment()) {
132
+ if (!Array.isArray(items) || items.length === 0) {
133
+ warnDev("no-items", "[opsinjs] <Accordion> was rendered with no items, so it has nothing to " +
134
+ "disclose. Pass the sections through the `items` prop, each with a " +
135
+ "`value`, a `title` and its `content`.");
136
+ }
137
+ else {
138
+ const seen = new Set();
139
+ for (const item of items) {
140
+ if (seen.has(item.value)) {
141
+ warnDev(`duplicate-value:${String(item.value)}`, `[opsinjs] <Accordion> has two sections with value="${String(item.value)}". ` +
142
+ "Section values must be unique, because they are how open state is " +
143
+ "tracked; the second section will open and close with the first.");
144
+ }
145
+ seen.add(item.value);
146
+ }
147
+ }
148
+ }
149
+ if (!Array.isArray(items) || items.length === 0) {
150
+ return null;
151
+ }
152
+ return (_jsx(BaseAccordion.Root, { "data-slot": "accordion", multiple: multiple, value: value, defaultValue: defaultValue, onValueChange: onValueChange ? (next) => onValueChange(next) : undefined, className: cn(ROOT, className), children: items.map((item) => (_jsxs(BaseAccordion.Item, { value: item.value, disabled: item.disabled, "data-slot": "accordion-item", className: ITEM, children: [_jsx(BaseAccordion.Header, { "data-slot": "accordion-header", className: "m-0", children: _jsxs(BaseAccordion.Trigger, { "data-slot": "accordion-trigger", className: TRIGGER, children: [_jsx("span", { "data-slot": "accordion-title", children: item.title }), _jsx(ChevronDown, { "aria-hidden": "true", className: CHEVRON })] }) }), _jsx(BaseAccordion.Panel, { "data-slot": "accordion-panel", className: PANEL, children: item.content })] }, item.value))) }));
153
+ }
154
+ //# sourceMappingURL=accordion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accordion.js","sourceRoot":"","sources":["../../src/components/accordion.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAG1C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAqChC;;;;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