@photonhealth/react 0.0.0-stage → 2.0.0-rc.2

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 (277) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +111 -2
  3. package/dist/adapters/index.d.ts +2 -0
  4. package/dist/adapters/index.d.ts.map +1 -0
  5. package/dist/adapters/index.js +2 -0
  6. package/dist/adapters/index.js.map +1 -0
  7. package/dist/adapters/tailwind.d.ts +3 -0
  8. package/dist/adapters/tailwind.d.ts.map +1 -0
  9. package/dist/adapters/tailwind.js +126 -0
  10. package/dist/adapters/tailwind.js.map +1 -0
  11. package/dist/analytics/PhotonAnalyticsProvider.d.ts +16 -0
  12. package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
  13. package/dist/analytics/PhotonAnalyticsProvider.js +57 -0
  14. package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
  15. package/dist/analytics/fieldInteraction.d.ts +18 -0
  16. package/dist/analytics/fieldInteraction.d.ts.map +1 -0
  17. package/dist/analytics/fieldInteraction.js +102 -0
  18. package/dist/analytics/fieldInteraction.js.map +1 -0
  19. package/dist/analytics/tracker.d.ts +17 -0
  20. package/dist/analytics/tracker.d.ts.map +1 -0
  21. package/dist/analytics/tracker.js +36 -0
  22. package/dist/analytics/tracker.js.map +1 -0
  23. package/dist/analytics/viewed.d.ts +11 -0
  24. package/dist/analytics/viewed.d.ts.map +1 -0
  25. package/dist/analytics/viewed.js +16 -0
  26. package/dist/analytics/viewed.js.map +1 -0
  27. package/dist/components/ChangeList.d.ts +21 -0
  28. package/dist/components/ChangeList.d.ts.map +1 -0
  29. package/dist/components/ChangeList.js +40 -0
  30. package/dist/components/ChangeList.js.map +1 -0
  31. package/dist/components/PhotonOrder.d.ts +46 -0
  32. package/dist/components/PhotonOrder.d.ts.map +1 -0
  33. package/dist/components/PhotonOrder.js +274 -0
  34. package/dist/components/PhotonOrder.js.map +1 -0
  35. package/dist/components/PhotonPatient.d.ts +48 -0
  36. package/dist/components/PhotonPatient.d.ts.map +1 -0
  37. package/dist/components/PhotonPatient.js +85 -0
  38. package/dist/components/PhotonPatient.js.map +1 -0
  39. package/dist/components/PhotonPrescription.d.ts +32 -0
  40. package/dist/components/PhotonPrescription.d.ts.map +1 -0
  41. package/dist/components/PhotonPrescription.js +11 -0
  42. package/dist/components/PhotonPrescription.js.map +1 -0
  43. package/dist/components/ScreeningAlerts.d.ts +6 -0
  44. package/dist/components/ScreeningAlerts.d.ts.map +1 -0
  45. package/dist/components/ScreeningAlerts.js +11 -0
  46. package/dist/components/ScreeningAlerts.js.map +1 -0
  47. package/dist/components/SignedIn.d.ts +12 -0
  48. package/dist/components/SignedIn.d.ts.map +1 -0
  49. package/dist/components/SignedIn.js +84 -0
  50. package/dist/components/SignedIn.js.map +1 -0
  51. package/dist/components/activity.d.ts +7 -0
  52. package/dist/components/activity.d.ts.map +1 -0
  53. package/dist/components/activity.js +24 -0
  54. package/dist/components/activity.js.map +1 -0
  55. package/dist/components/display.d.ts +90 -0
  56. package/dist/components/display.d.ts.map +1 -0
  57. package/dist/components/display.js +223 -0
  58. package/dist/components/display.js.map +1 -0
  59. package/dist/components/flow.d.ts +35 -0
  60. package/dist/components/flow.d.ts.map +1 -0
  61. package/dist/components/flow.js +53 -0
  62. package/dist/components/flow.js.map +1 -0
  63. package/dist/components/format.d.ts +26 -0
  64. package/dist/components/format.d.ts.map +1 -0
  65. package/dist/components/format.js +61 -0
  66. package/dist/components/format.js.map +1 -0
  67. package/dist/components/index.d.ts +6 -0
  68. package/dist/components/index.d.ts.map +1 -0
  69. package/dist/components/index.js +6 -0
  70. package/dist/components/index.js.map +1 -0
  71. package/dist/components/open.d.ts +47 -0
  72. package/dist/components/open.d.ts.map +1 -0
  73. package/dist/components/open.js +73 -0
  74. package/dist/components/open.js.map +1 -0
  75. package/dist/components/order/DraftOrderPrompt.d.ts +18 -0
  76. package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
  77. package/dist/components/order/DraftOrderPrompt.js +26 -0
  78. package/dist/components/order/DraftOrderPrompt.js.map +1 -0
  79. package/dist/components/patient/Benefits.d.ts +25 -0
  80. package/dist/components/patient/Benefits.d.ts.map +1 -0
  81. package/dist/components/patient/Benefits.js +48 -0
  82. package/dist/components/patient/Benefits.js.map +1 -0
  83. package/dist/components/patient/Clinical.d.ts +56 -0
  84. package/dist/components/patient/Clinical.d.ts.map +1 -0
  85. package/dist/components/patient/Clinical.js +118 -0
  86. package/dist/components/patient/Clinical.js.map +1 -0
  87. package/dist/components/patient/IntakeForm.d.ts +10 -0
  88. package/dist/components/patient/IntakeForm.d.ts.map +1 -0
  89. package/dist/components/patient/IntakeForm.js +333 -0
  90. package/dist/components/patient/IntakeForm.js.map +1 -0
  91. package/dist/components/patient/Summary.d.ts +48 -0
  92. package/dist/components/patient/Summary.d.ts.map +1 -0
  93. package/dist/components/patient/Summary.js +90 -0
  94. package/dist/components/patient/Summary.js.map +1 -0
  95. package/dist/components/patient/fields.d.ts +42 -0
  96. package/dist/components/patient/fields.d.ts.map +1 -0
  97. package/dist/components/patient/fields.js +72 -0
  98. package/dist/components/patient/fields.js.map +1 -0
  99. package/dist/components/patient/query.d.ts +37 -0
  100. package/dist/components/patient/query.d.ts.map +1 -0
  101. package/dist/components/patient/query.js +70 -0
  102. package/dist/components/patient/query.js.map +1 -0
  103. package/dist/components/prescription/PrescriptionCard.d.ts +45 -0
  104. package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
  105. package/dist/components/prescription/PrescriptionCard.js +179 -0
  106. package/dist/components/prescription/PrescriptionCard.js.map +1 -0
  107. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
  108. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
  109. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
  110. package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
  111. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
  112. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
  113. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
  114. package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
  115. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
  116. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
  117. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
  118. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
  119. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
  120. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
  121. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
  122. package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
  123. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
  124. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
  125. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
  126. package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
  127. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
  128. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
  129. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js +287 -0
  130. package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
  131. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
  132. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
  133. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
  134. package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
  135. package/dist/components/schemaErrors.d.ts +12 -0
  136. package/dist/components/schemaErrors.d.ts.map +1 -0
  137. package/dist/components/schemaErrors.js +24 -0
  138. package/dist/components/schemaErrors.js.map +1 -0
  139. package/dist/components/search.d.ts +154 -0
  140. package/dist/components/search.d.ts.map +1 -0
  141. package/dist/components/search.js +295 -0
  142. package/dist/components/search.js.map +1 -0
  143. package/dist/hooks/index.d.ts +5 -0
  144. package/dist/hooks/index.d.ts.map +1 -0
  145. package/dist/hooks/index.js +5 -0
  146. package/dist/hooks/index.js.map +1 -0
  147. package/dist/hooks/useLatestCallback.d.ts +7 -0
  148. package/dist/hooks/useLatestCallback.d.ts.map +1 -0
  149. package/dist/hooks/useLatestCallback.js +14 -0
  150. package/dist/hooks/useLatestCallback.js.map +1 -0
  151. package/dist/hooks/useLive.d.ts +15 -0
  152. package/dist/hooks/useLive.d.ts.map +1 -0
  153. package/dist/hooks/useLive.js +6 -0
  154. package/dist/hooks/useLive.js.map +1 -0
  155. package/dist/hooks/useOnChange.d.ts +11 -0
  156. package/dist/hooks/useOnChange.d.ts.map +1 -0
  157. package/dist/hooks/useOnChange.js +28 -0
  158. package/dist/hooks/useOnChange.js.map +1 -0
  159. package/dist/hooks/useSession.d.ts +7 -0
  160. package/dist/hooks/useSession.d.ts.map +1 -0
  161. package/dist/hooks/useSession.js +10 -0
  162. package/dist/hooks/useSession.js.map +1 -0
  163. package/dist/index.d.ts +22 -0
  164. package/dist/index.d.ts.map +1 -0
  165. package/dist/index.js +20 -0
  166. package/dist/index.js.map +1 -0
  167. package/dist/meta/version.d.ts +5 -0
  168. package/dist/meta/version.d.ts.map +1 -0
  169. package/dist/meta/version.js +5 -0
  170. package/dist/meta/version.js.map +1 -0
  171. package/dist/primitives/PhotonProvider.d.ts +60 -0
  172. package/dist/primitives/PhotonProvider.d.ts.map +1 -0
  173. package/dist/primitives/PhotonProvider.js +103 -0
  174. package/dist/primitives/PhotonProvider.js.map +1 -0
  175. package/dist/primitives/defaults.d.ts +3 -0
  176. package/dist/primitives/defaults.d.ts.map +1 -0
  177. package/dist/primitives/defaults.js +70 -0
  178. package/dist/primitives/defaults.js.map +1 -0
  179. package/dist/primitives/icons.d.ts +6 -0
  180. package/dist/primitives/icons.d.ts.map +1 -0
  181. package/dist/primitives/icons.js +6 -0
  182. package/dist/primitives/icons.js.map +1 -0
  183. package/dist/primitives/index.d.ts +5 -0
  184. package/dist/primitives/index.d.ts.map +1 -0
  185. package/dist/primitives/index.js +5 -0
  186. package/dist/primitives/index.js.map +1 -0
  187. package/dist/primitives/photonContext.d.ts +3 -0
  188. package/dist/primitives/photonContext.d.ts.map +1 -0
  189. package/dist/primitives/photonContext.js +3 -0
  190. package/dist/primitives/photonContext.js.map +1 -0
  191. package/dist/primitives/select.d.ts +7 -0
  192. package/dist/primitives/select.d.ts.map +1 -0
  193. package/dist/primitives/select.js +16 -0
  194. package/dist/primitives/select.js.map +1 -0
  195. package/dist/primitives/types.d.ts +288 -0
  196. package/dist/primitives/types.d.ts.map +1 -0
  197. package/dist/primitives/types.js +3 -0
  198. package/dist/primitives/types.js.map +1 -0
  199. package/dist/primitives/useProvidedPhoton.d.ts +8 -0
  200. package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
  201. package/dist/primitives/useProvidedPhoton.js +8 -0
  202. package/dist/primitives/useProvidedPhoton.js.map +1 -0
  203. package/dist/styles.css +653 -0
  204. package/dist/test-utils/contract.d.ts +17 -0
  205. package/dist/test-utils/contract.d.ts.map +1 -0
  206. package/dist/test-utils/contract.js +282 -0
  207. package/dist/test-utils/contract.js.map +1 -0
  208. package/package.json +76 -4
  209. package/src/adapters/index.ts +1 -0
  210. package/src/adapters/tailwind.tsx +572 -0
  211. package/src/analytics/PhotonAnalyticsProvider.test.tsx +191 -0
  212. package/src/analytics/PhotonAnalyticsProvider.tsx +96 -0
  213. package/src/analytics/fieldInteraction.test.tsx +184 -0
  214. package/src/analytics/fieldInteraction.tsx +148 -0
  215. package/src/analytics/tracker.test.ts +52 -0
  216. package/src/analytics/tracker.ts +42 -0
  217. package/src/analytics/viewed.ts +27 -0
  218. package/src/components/ChangeList.tsx +85 -0
  219. package/src/components/PhotonOrder.test.tsx +256 -0
  220. package/src/components/PhotonOrder.tsx +508 -0
  221. package/src/components/PhotonPatient.tsx +188 -0
  222. package/src/components/PhotonPrescription.test.tsx +116 -0
  223. package/src/components/PhotonPrescription.tsx +45 -0
  224. package/src/components/ScreeningAlerts.tsx +28 -0
  225. package/src/components/SignedIn.tsx +144 -0
  226. package/src/components/activity.ts +23 -0
  227. package/src/components/display.ts +278 -0
  228. package/src/components/flow.ts +67 -0
  229. package/src/components/format.ts +73 -0
  230. package/src/components/index.ts +5 -0
  231. package/src/components/open.ts +100 -0
  232. package/src/components/order/DraftOrderPrompt.test.tsx +80 -0
  233. package/src/components/order/DraftOrderPrompt.tsx +81 -0
  234. package/src/components/patient/Benefits.tsx +133 -0
  235. package/src/components/patient/Clinical.tsx +215 -0
  236. package/src/components/patient/IntakeForm.test.tsx +89 -0
  237. package/src/components/patient/IntakeForm.tsx +564 -0
  238. package/src/components/patient/Summary.test.tsx +106 -0
  239. package/src/components/patient/Summary.tsx +330 -0
  240. package/src/components/patient/fields.tsx +158 -0
  241. package/src/components/patient/query.ts +83 -0
  242. package/src/components/prescription/PrescriptionCard.test.tsx +85 -0
  243. package/src/components/prescription/PrescriptionCard.tsx +347 -0
  244. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +85 -0
  245. package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
  246. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +209 -0
  247. package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
  248. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +456 -0
  249. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
  250. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
  251. package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
  252. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +75 -0
  253. package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
  254. package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
  255. package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +699 -0
  256. package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
  257. package/src/components/schemaErrors.test.ts +49 -0
  258. package/src/components/schemaErrors.ts +33 -0
  259. package/src/components/search.tsx +377 -0
  260. package/src/hooks/index.ts +4 -0
  261. package/src/hooks/useLatestCallback.ts +16 -0
  262. package/src/hooks/useLive.ts +21 -0
  263. package/src/hooks/useOnChange.ts +34 -0
  264. package/src/hooks/useSession.ts +11 -0
  265. package/src/index.ts +21 -0
  266. package/src/meta/version.test.ts +10 -0
  267. package/src/meta/version.ts +4 -0
  268. package/src/primitives/PhotonProvider.tsx +168 -0
  269. package/src/primitives/defaults.tsx +432 -0
  270. package/src/primitives/icons.tsx +37 -0
  271. package/src/primitives/index.ts +4 -0
  272. package/src/primitives/photonContext.ts +4 -0
  273. package/src/primitives/select.ts +15 -0
  274. package/src/primitives/types.ts +288 -0
  275. package/src/primitives/useProvidedPhoton.ts +21 -0
  276. package/src/styles.css +653 -0
  277. package/src/test-utils/contract.tsx +453 -0
@@ -0,0 +1,432 @@
1
+ import { useId, type ReactNode } from "react";
2
+ import { Icon } from "./icons.tsx";
3
+ import { CHOICE_ACTION, type PhotonComponents } from "./types.ts";
4
+ import { openOnEnter } from "./select.ts";
5
+
6
+ /**
7
+ * Unstyled defaults: plain semantic HTML with stable `prx-*` class names and
8
+ * data attributes. They carry no design of their own — `@photonhealth/react/styles.css`
9
+ * adds only structure (spacing, borders) at zero specificity, in em units, with
10
+ * inherited fonts and colours — so the cards look like whatever page they're in.
11
+ */
12
+
13
+ const cx = (...parts: (string | false | null | undefined)[]) => parts.filter(Boolean).join(" ");
14
+
15
+ function Field({
16
+ label,
17
+ helper,
18
+ invalid,
19
+ errorMessage,
20
+ children,
21
+ }: {
22
+ label?: string;
23
+ helper?: string;
24
+ invalid?: boolean;
25
+ errorMessage?: string;
26
+ children: (ids: { id: string; describedBy?: string }) => ReactNode;
27
+ }) {
28
+ const id = useId();
29
+ const note = invalid && errorMessage ? errorMessage : helper;
30
+ const noteId = note ? `${id}-note` : undefined;
31
+ return (
32
+ <div className="prx-field" data-invalid={invalid || undefined}>
33
+ {label && (
34
+ <label className="prx-label" htmlFor={id}>
35
+ {label}
36
+ </label>
37
+ )}
38
+ {children({ id, describedBy: noteId })}
39
+ <span className="prx-note" id={noteId} role={invalid ? "alert" : undefined}>
40
+ {note}
41
+ </span>
42
+ </div>
43
+ );
44
+ }
45
+
46
+ export const defaultComponents: PhotonComponents = {
47
+ Stack: ({ gap = "4", align = "stretch", children }) => (
48
+ <div className="prx-stack" data-gap={gap} data-align={align}>
49
+ {children}
50
+ </div>
51
+ ),
52
+ Row: ({ gap = "3", align = "center", justify = "start", children }) => (
53
+ <div className="prx-row" data-gap={gap} data-align={align} data-justify={justify}>
54
+ {children}
55
+ </div>
56
+ ),
57
+ Grid: ({ min = "12em", gap = "4", children }) => (
58
+ <div
59
+ className="prx-grid"
60
+ data-gap={gap}
61
+ style={{ gridTemplateColumns: `repeat(auto-fit, minmax(min(${min}, 100%), 1fr))` }}
62
+ >
63
+ {children}
64
+ </div>
65
+ ),
66
+ Container: ({ as: As = "div", children }) => <As className="prx-container">{children}</As>,
67
+ PageHeader: ({ title, description }) => (
68
+ <header className="prx-page-header">
69
+ <h1>{title}</h1>
70
+ {description && <p>{description}</p>}
71
+ </header>
72
+ ),
73
+ Text: ({ tone = "default", children }) => (
74
+ <span className="prx-text" data-tone={tone}>
75
+ {children}
76
+ </span>
77
+ ),
78
+ Card: ({ divided, label, children }) => (
79
+ <section className="prx-card" data-divided={divided || undefined} aria-label={label}>
80
+ {children}
81
+ </section>
82
+ ),
83
+ CardHeader: ({ title, description, action }) => (
84
+ <div className="prx-card-header">
85
+ <div>
86
+ <h2 className="prx-card-title">{title}</h2>
87
+ {description && <p className="prx-card-description">{description}</p>}
88
+ </div>
89
+ {action && <div className="prx-card-action">{action}</div>}
90
+ </div>
91
+ ),
92
+ CardBody: ({ children }) => <div className="prx-card-body">{children}</div>,
93
+ CardFooter: ({ start, children }) => (
94
+ <div className="prx-card-footer">
95
+ {start && <div className="prx-card-footer-start">{start}</div>}
96
+ {children}
97
+ </div>
98
+ ),
99
+ Button: ({
100
+ variant = "primary",
101
+ size = "md",
102
+ loading,
103
+ disabled,
104
+ className,
105
+ children,
106
+ icon,
107
+ tone,
108
+ type = "button",
109
+ ...rest
110
+ }) => (
111
+ <button
112
+ {...rest}
113
+ type={type}
114
+ className={cx("prx-button", className)}
115
+ data-variant={variant}
116
+ data-tone={tone}
117
+ data-size={size}
118
+ data-loading={loading || undefined}
119
+ disabled={disabled || loading}
120
+ aria-busy={loading || undefined}
121
+ data-icon={icon && !children ? "" : undefined}
122
+ >
123
+ {icon && <Icon name={icon} className="prx-icon" />}
124
+ {children}
125
+ </button>
126
+ ),
127
+ Input: ({ label, helper, invalid, errorMessage, className, loading, onClear, clearLabel = "Clear", ...rest }) => {
128
+ const clearable = Boolean(onClear) && !loading && String(rest.value ?? "") !== "";
129
+ return (
130
+ <Field label={label} helper={helper} invalid={invalid} errorMessage={errorMessage}>
131
+ {({ id, describedBy }) => (
132
+ <span className="prx-input-wrap">
133
+ <input
134
+ {...rest}
135
+ id={id}
136
+ className={cx("prx-input", className)}
137
+ data-clearable={clearable || undefined}
138
+ aria-invalid={invalid || undefined}
139
+ aria-describedby={describedBy}
140
+ aria-busy={loading || undefined}
141
+ />
142
+ {loading && <span className="prx-spinner" aria-hidden="true" />}
143
+ {clearable && (
144
+ <button
145
+ type="button"
146
+ className="prx-input-clear"
147
+ aria-label={clearLabel}
148
+ title={clearLabel}
149
+ disabled={rest.disabled}
150
+ onClick={onClear}
151
+ >
152
+ <Icon name="close" className="prx-icon" />
153
+ </button>
154
+ )}
155
+ </span>
156
+ )}
157
+ </Field>
158
+ );
159
+ },
160
+ Textarea: ({ label, helper, invalid, errorMessage, className, ...rest }) => (
161
+ <Field label={label} helper={helper} invalid={invalid} errorMessage={errorMessage}>
162
+ {({ id, describedBy }) => (
163
+ <textarea
164
+ {...rest}
165
+ id={id}
166
+ className={cx("prx-input", className)}
167
+ aria-invalid={invalid || undefined}
168
+ aria-describedby={describedBy}
169
+ />
170
+ )}
171
+ </Field>
172
+ ),
173
+ Checkbox: ({ label, checked, onChange, disabled }) => (
174
+ <label className="prx-check">
175
+ <input type="checkbox" checked={checked} disabled={disabled} onChange={(e) => onChange(e.target.checked)} />
176
+ <span>{label}</span>
177
+ </label>
178
+ ),
179
+ Select: ({ label, options, value, onChange, placeholder = "Select…", helper, disabled, invalid, errorMessage }) => (
180
+ <Field label={label} helper={helper} invalid={invalid} errorMessage={errorMessage}>
181
+ {({ id, describedBy }) => (
182
+ <select
183
+ id={id}
184
+ className="prx-input prx-select"
185
+ value={value ?? ""}
186
+ disabled={disabled}
187
+ aria-invalid={invalid || undefined}
188
+ aria-describedby={describedBy}
189
+ onChange={(e) => e.target.value && onChange(e.target.value as never)}
190
+ onKeyDown={openOnEnter}
191
+ >
192
+ <option value="" disabled>
193
+ {placeholder}
194
+ </option>
195
+ {options.map((o) => (
196
+ <option key={o.value} value={o.value}>
197
+ {o.label}
198
+ </option>
199
+ ))}
200
+ </select>
201
+ )}
202
+ </Field>
203
+ ),
204
+ RadioGroup: ({ label, options, value, onChange, horizontal }) => {
205
+ const name = useId();
206
+ return (
207
+ <fieldset className="prx-radio-group" data-horizontal={horizontal || undefined}>
208
+ <legend className="prx-label">{label}</legend>
209
+ {options.map((o) => (
210
+ <label key={o.value} className="prx-check">
211
+ <input type="radio" name={name} checked={value === o.value} onChange={() => onChange(o.value)} />
212
+ <span>{o.label}</span>
213
+ </label>
214
+ ))}
215
+ </fieldset>
216
+ );
217
+ },
218
+ ChoiceList: ({ label, choices, onChoose, disabled, pendingKey, action, activeKey, id }) => {
219
+ // A field that keeps the cursor drives this list, so its rows are options it points at rather than
220
+ // buttons the keys move between.
221
+ const inField = activeKey !== undefined;
222
+ const row = (key: string, active: boolean, onPick: () => void, body: ReactNode) =>
223
+ inField ? (
224
+ <li
225
+ key={key}
226
+ id={id ? `${id}-${key}` : undefined}
227
+ role="option"
228
+ aria-selected={active}
229
+ aria-busy={key === pendingKey || undefined}
230
+ className={`prx-choice${key === CHOICE_ACTION ? " prx-choice-action" : ""}${active ? " prx-choice-active" : ""}`}
231
+ onClick={disabled ? undefined : onPick}
232
+ >
233
+ {body}
234
+ </li>
235
+ ) : (
236
+ <li key={key}>
237
+ <button
238
+ type="button"
239
+ className={`prx-choice${key === CHOICE_ACTION ? " prx-choice-action" : ""}`}
240
+ disabled={disabled}
241
+ aria-busy={key === pendingKey || undefined}
242
+ onClick={onPick}
243
+ >
244
+ {body}
245
+ </button>
246
+ </li>
247
+ );
248
+ return (
249
+ <ul className="prx-choices" aria-label={label} role={inField ? "listbox" : undefined}>
250
+ {choices.map((c) =>
251
+ row(
252
+ c.key,
253
+ c.key === activeKey,
254
+ () => onChoose(c.key),
255
+ <>
256
+ <span className="prx-choice-text">
257
+ <span className="prx-choice-line">
258
+ <span>{c.label}</span>
259
+ {c.meta && <span className="prx-choice-description">{c.meta}</span>}
260
+ </span>
261
+ {c.description && <span className="prx-choice-description">{c.description}</span>}
262
+ </span>
263
+ <Icon name="return" className="prx-choice-return" />
264
+ </>,
265
+ ),
266
+ )}
267
+ {action &&
268
+ row(
269
+ CHOICE_ACTION,
270
+ activeKey === CHOICE_ACTION,
271
+ action.onChoose,
272
+ <>
273
+ {action.icon && <Icon name={action.icon} className="prx-icon" />}
274
+ <span className="prx-choice-text">{action.label}</span>
275
+ <Icon name="return" className="prx-choice-return" />
276
+ </>,
277
+ )}
278
+ </ul>
279
+ );
280
+ },
281
+ OptionList: ({ label, options, activeKey, activeSelected, onSelect, onKeyDown, disabled, children }) => {
282
+ return (
283
+ <div className="prx-options" tabIndex={0} aria-label={label} onKeyDown={onKeyDown}>
284
+ <ul className="prx-options-list" aria-label={label}>
285
+ {options.map((o) => {
286
+ const text = (
287
+ <span className="prx-option-text">
288
+ <span className="prx-option-label">{o.label}</span>
289
+ {o.description && <span className="prx-choice-description">{o.description}</span>}
290
+ </span>
291
+ );
292
+ const active = o.key === activeKey;
293
+ return (
294
+ <li key={o.key}>
295
+ {active && !o.direct ? (
296
+ <div
297
+ className="prx-option"
298
+ data-active=""
299
+ data-selected={activeSelected || undefined}
300
+ aria-current="true"
301
+ aria-busy={o.loading || undefined}
302
+ >
303
+ <button
304
+ type="button"
305
+ className="prx-option-row"
306
+ aria-expanded="true"
307
+ aria-label={o.ariaLabel}
308
+ disabled={disabled}
309
+ onClick={() => onSelect(o.key)}
310
+ >
311
+ {text}
312
+ {o.loading && <span className="prx-spinner prx-option-chevron" aria-hidden="true" />}
313
+ </button>
314
+ {children}
315
+ </div>
316
+ ) : (
317
+ <button
318
+ type="button"
319
+ className="prx-option"
320
+ data-active={active ? "" : undefined}
321
+ data-selected={(active && activeSelected) || undefined}
322
+ aria-current={active || undefined}
323
+ aria-busy={o.loading || undefined}
324
+ disabled={disabled}
325
+ aria-label={o.ariaLabel}
326
+ onClick={() => onSelect(o.key)}
327
+ >
328
+ <span className="prx-option-row">
329
+ {text}
330
+ {o.loading ? (
331
+ <span className="prx-spinner prx-option-chevron" aria-hidden="true" />
332
+ ) : (
333
+ !o.direct && <Icon name="chevron" className="prx-icon prx-option-chevron" />
334
+ )}
335
+ </span>
336
+ </button>
337
+ )}
338
+ </li>
339
+ );
340
+ })}
341
+ </ul>
342
+ </div>
343
+ );
344
+ },
345
+ ActionBar: ({ children }) => <div className="prx-action-bar">{children}</div>,
346
+ ToggleGroup: ({ label, options, value, onChange, disabled }) => {
347
+ const id = useId();
348
+ return (
349
+ <div className="prx-toggle-group">
350
+ <div className="prx-toggle-label" id={id}>
351
+ <strong>{label}</strong>
352
+ </div>
353
+ <div className="prx-toggles" role="group" aria-labelledby={id}>
354
+ {options.map((o) => (
355
+ <button
356
+ key={o.value}
357
+ type="button"
358
+ className="prx-toggle"
359
+ aria-pressed={o.value === value}
360
+ aria-label={o.ariaLabel}
361
+ data-muted={o.muted || undefined}
362
+ disabled={disabled}
363
+ onClick={() => onChange(o.value)}
364
+ >
365
+ {o.label}
366
+ {o.detail && <span className="prx-choice-description">{o.detail}</span>}
367
+ </button>
368
+ ))}
369
+ </div>
370
+ </div>
371
+ );
372
+ },
373
+ Alert: ({ tone = "info", title, description, onDismiss }) => (
374
+ <div className="prx-alert" data-tone={tone} role={tone === "warning" || tone === "critical" ? "alert" : "status"}>
375
+ <div>
376
+ <strong className="prx-alert-title">{title}</strong>
377
+ {description && <div className="prx-alert-description">{description}</div>}
378
+ </div>
379
+ {onDismiss && (
380
+ <button
381
+ type="button"
382
+ className="prx-button"
383
+ data-variant="ghost"
384
+ data-size="sm"
385
+ onClick={onDismiss}
386
+ aria-label="Dismiss"
387
+ >
388
+ <Icon name="close" className="prx-icon" />
389
+ </button>
390
+ )}
391
+ </div>
392
+ ),
393
+ Badge: ({ tone = "neutral", children, icon, onRemove, removeLabel = "Remove" }) => (
394
+ <span className="prx-badge" data-tone={tone}>
395
+ {icon && <Icon name={icon} className="prx-icon" />}
396
+ {children}
397
+ {onRemove && (
398
+ <button type="button" className="prx-badge-remove" aria-label={removeLabel} onClick={onRemove}>
399
+ <Icon name="close" className="prx-icon" />
400
+ </button>
401
+ )}
402
+ </span>
403
+ ),
404
+ Spinner: ({ label }) => (
405
+ <span className="prx-spinner-status" role="status">
406
+ <span className="prx-spinner" aria-hidden="true" />
407
+ {label}
408
+ </span>
409
+ ),
410
+ Disclosure: ({ summary, open, onOpenChange, children }) => {
411
+ const id = useId();
412
+ return (
413
+ <div className="prx-disclosure" data-open={open || undefined}>
414
+ <button
415
+ type="button"
416
+ className="prx-disclosure-toggle"
417
+ aria-expanded={open}
418
+ aria-controls={id}
419
+ onClick={() => onOpenChange(!open)}
420
+ >
421
+ <Icon name="chevron" className="prx-icon prx-disclosure-chevron" />
422
+ <span>{summary}</span>
423
+ </button>
424
+ {open && (
425
+ <div className="prx-disclosure-body" id={id}>
426
+ {children}
427
+ </div>
428
+ )}
429
+ </div>
430
+ );
431
+ },
432
+ };
@@ -0,0 +1,37 @@
1
+ import type { SVGProps } from "react";
2
+
3
+ /** Minimal line icons for icon-only buttons, removable chips and disclosures. Sized by the caller; colour follows text. */
4
+ export function Icon({
5
+ name,
6
+ ...props
7
+ }: { name: "add" | "close" | "edit" | "trash" | "check" | "chevron" | "return" } & SVGProps<SVGSVGElement>) {
8
+ return (
9
+ <svg
10
+ viewBox="0 0 24 24"
11
+ fill="none"
12
+ stroke="currentColor"
13
+ strokeWidth={2}
14
+ strokeLinecap="round"
15
+ aria-hidden="true"
16
+ {...props}
17
+ >
18
+ {name === "add" ? (
19
+ <path d="M12 5v14M5 12h14" />
20
+ ) : name === "edit" ? (
21
+ <path d="M4 20h4L19 9l-4-4L4 16v4zM13.5 6.5l4 4" strokeLinejoin="round" />
22
+ ) : name === "check" ? (
23
+ <path d="M5 12.5l4.5 4.5L19 7.5" strokeLinejoin="round" />
24
+ ) : name === "trash" ? (
25
+ <path d="M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13M10 11v6M14 11v6" strokeLinejoin="round" />
26
+ ) : name === "return" ? (
27
+ // The Return key's own glyph: what pressing it here would take.
28
+ <path d="M20 6v5a3 3 0 0 1-3 3H5m0 0l4-4m-4 4l4 4" strokeLinejoin="round" />
29
+ ) : name === "chevron" ? (
30
+ // Points right (closed); callers rotate it 90° when open.
31
+ <path d="M9 6l6 6-6 6" strokeLinejoin="round" />
32
+ ) : (
33
+ <path d="M6 6l12 12M18 6L6 18" />
34
+ )}
35
+ </svg>
36
+ );
37
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./types.ts";
2
+ export * from "./defaults.tsx";
3
+ export * from "./icons.tsx";
4
+ export * from "./PhotonProvider.tsx";
@@ -0,0 +1,4 @@
1
+ import { createContext } from "react";
2
+ import type { Photon } from "@photonhealth/client";
3
+
4
+ export const PhotonContext = createContext<Photon | null>(null);
@@ -0,0 +1,15 @@
1
+ import type { KeyboardEvent } from "react";
2
+
3
+ /**
4
+ * A native <select>'s onKeyDown: Enter opens its list, as ↓ or a click does (browsers open it on Space / Alt+↓
5
+ * only). Where the browser won't show it (no showPicker, or a frame that may not), Enter does nothing.
6
+ */
7
+ export function openOnEnter(e: KeyboardEvent<HTMLSelectElement>) {
8
+ if (e.key !== "Enter" || e.altKey || e.metaKey || e.ctrlKey || e.shiftKey) return;
9
+ e.preventDefault();
10
+ try {
11
+ e.currentTarget.showPicker?.();
12
+ } catch {
13
+ // Not allowed here (e.g. a cross-origin frame): the list still opens with Space / Alt+↓.
14
+ }
15
+ }