@photonhealth/react 0.0.0-stage → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +84 -2
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/tailwind.d.ts +3 -0
- package/dist/adapters/tailwind.d.ts.map +1 -0
- package/dist/adapters/tailwind.js +123 -0
- package/dist/adapters/tailwind.js.map +1 -0
- package/dist/components/ChangeList.d.ts +21 -0
- package/dist/components/ChangeList.d.ts.map +1 -0
- package/dist/components/ChangeList.js +40 -0
- package/dist/components/ChangeList.js.map +1 -0
- package/dist/components/PhotonOrder.d.ts +46 -0
- package/dist/components/PhotonOrder.d.ts.map +1 -0
- package/dist/components/PhotonOrder.js +270 -0
- package/dist/components/PhotonOrder.js.map +1 -0
- package/dist/components/PhotonPatient.d.ts +48 -0
- package/dist/components/PhotonPatient.d.ts.map +1 -0
- package/dist/components/PhotonPatient.js +83 -0
- package/dist/components/PhotonPatient.js.map +1 -0
- package/dist/components/PhotonPrescription.d.ts +43 -0
- package/dist/components/PhotonPrescription.d.ts.map +1 -0
- package/dist/components/PhotonPrescription.js +364 -0
- package/dist/components/PhotonPrescription.js.map +1 -0
- package/dist/components/ScreeningAlerts.d.ts +6 -0
- package/dist/components/ScreeningAlerts.d.ts.map +1 -0
- package/dist/components/ScreeningAlerts.js +11 -0
- package/dist/components/ScreeningAlerts.js.map +1 -0
- package/dist/components/SignedIn.d.ts +12 -0
- package/dist/components/SignedIn.d.ts.map +1 -0
- package/dist/components/SignedIn.js +84 -0
- package/dist/components/SignedIn.js.map +1 -0
- package/dist/components/TreatmentPicker.d.ts +45 -0
- package/dist/components/TreatmentPicker.d.ts.map +1 -0
- package/dist/components/TreatmentPicker.js +279 -0
- package/dist/components/TreatmentPicker.js.map +1 -0
- package/dist/components/activity.d.ts +7 -0
- package/dist/components/activity.d.ts.map +1 -0
- package/dist/components/activity.js +24 -0
- package/dist/components/activity.js.map +1 -0
- package/dist/components/display.d.ts +90 -0
- package/dist/components/display.d.ts.map +1 -0
- package/dist/components/display.js +223 -0
- package/dist/components/display.js.map +1 -0
- package/dist/components/flow.d.ts +35 -0
- package/dist/components/flow.d.ts.map +1 -0
- package/dist/components/flow.js +53 -0
- package/dist/components/flow.js.map +1 -0
- package/dist/components/format.d.ts +26 -0
- package/dist/components/format.d.ts.map +1 -0
- package/dist/components/format.js +61 -0
- package/dist/components/format.js.map +1 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +6 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/open.d.ts +47 -0
- package/dist/components/open.d.ts.map +1 -0
- package/dist/components/open.js +73 -0
- package/dist/components/open.js.map +1 -0
- package/dist/components/patient/Benefits.d.ts +25 -0
- package/dist/components/patient/Benefits.d.ts.map +1 -0
- package/dist/components/patient/Benefits.js +47 -0
- package/dist/components/patient/Benefits.js.map +1 -0
- package/dist/components/patient/Clinical.d.ts +55 -0
- package/dist/components/patient/Clinical.d.ts.map +1 -0
- package/dist/components/patient/Clinical.js +117 -0
- package/dist/components/patient/Clinical.js.map +1 -0
- package/dist/components/patient/IntakeForm.d.ts +10 -0
- package/dist/components/patient/IntakeForm.d.ts.map +1 -0
- package/dist/components/patient/IntakeForm.js +324 -0
- package/dist/components/patient/IntakeForm.js.map +1 -0
- package/dist/components/patient/Summary.d.ts +48 -0
- package/dist/components/patient/Summary.d.ts.map +1 -0
- package/dist/components/patient/Summary.js +80 -0
- package/dist/components/patient/Summary.js.map +1 -0
- package/dist/components/patient/fields.d.ts +43 -0
- package/dist/components/patient/fields.d.ts.map +1 -0
- package/dist/components/patient/fields.js +71 -0
- package/dist/components/patient/fields.js.map +1 -0
- package/dist/components/patient/query.d.ts +23 -0
- package/dist/components/patient/query.d.ts.map +1 -0
- package/dist/components/patient/query.js +65 -0
- package/dist/components/patient/query.js.map +1 -0
- package/dist/components/search.d.ts +154 -0
- package/dist/components/search.d.ts.map +1 -0
- package/dist/components/search.js +295 -0
- package/dist/components/search.js.map +1 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useLatestCallback.d.ts +7 -0
- package/dist/hooks/useLatestCallback.d.ts.map +1 -0
- package/dist/hooks/useLatestCallback.js +14 -0
- package/dist/hooks/useLatestCallback.js.map +1 -0
- package/dist/hooks/useLive.d.ts +15 -0
- package/dist/hooks/useLive.d.ts.map +1 -0
- package/dist/hooks/useLive.js +6 -0
- package/dist/hooks/useLive.js.map +1 -0
- package/dist/hooks/useOnChange.d.ts +11 -0
- package/dist/hooks/useOnChange.d.ts.map +1 -0
- package/dist/hooks/useOnChange.js +28 -0
- package/dist/hooks/useOnChange.js.map +1 -0
- package/dist/hooks/useSession.d.ts +7 -0
- package/dist/hooks/useSession.d.ts.map +1 -0
- package/dist/hooks/useSession.js +10 -0
- package/dist/hooks/useSession.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/primitives/PhotonProvider.d.ts +58 -0
- package/dist/primitives/PhotonProvider.d.ts.map +1 -0
- package/dist/primitives/PhotonProvider.js +91 -0
- package/dist/primitives/PhotonProvider.js.map +1 -0
- package/dist/primitives/defaults.d.ts +3 -0
- package/dist/primitives/defaults.d.ts.map +1 -0
- package/dist/primitives/defaults.js +67 -0
- package/dist/primitives/defaults.js.map +1 -0
- package/dist/primitives/icons.d.ts +6 -0
- package/dist/primitives/icons.d.ts.map +1 -0
- package/dist/primitives/icons.js +6 -0
- package/dist/primitives/icons.js.map +1 -0
- package/dist/primitives/index.d.ts +5 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +5 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/primitives/select.d.ts +7 -0
- package/dist/primitives/select.d.ts.map +1 -0
- package/dist/primitives/select.js +16 -0
- package/dist/primitives/select.js.map +1 -0
- package/dist/primitives/types.d.ts +276 -0
- package/dist/primitives/types.d.ts.map +1 -0
- package/dist/primitives/types.js +3 -0
- package/dist/primitives/types.js.map +1 -0
- package/dist/styles.css +611 -0
- package/dist/test-utils/contract.d.ts +17 -0
- package/dist/test-utils/contract.d.ts.map +1 -0
- package/dist/test-utils/contract.js +261 -0
- package/dist/test-utils/contract.js.map +1 -0
- package/package.json +74 -4
- package/src/adapters/index.ts +1 -0
- package/src/adapters/tailwind.tsx +544 -0
- package/src/components/ChangeList.tsx +85 -0
- package/src/components/PhotonOrder.tsx +493 -0
- package/src/components/PhotonPatient.tsx +184 -0
- package/src/components/PhotonPrescription.tsx +605 -0
- package/src/components/ScreeningAlerts.tsx +28 -0
- package/src/components/SignedIn.tsx +144 -0
- package/src/components/TreatmentPicker.tsx +350 -0
- package/src/components/activity.ts +23 -0
- package/src/components/display.ts +278 -0
- package/src/components/flow.ts +67 -0
- package/src/components/format.ts +73 -0
- package/src/components/index.ts +5 -0
- package/src/components/open.ts +100 -0
- package/src/components/patient/Benefits.tsx +125 -0
- package/src/components/patient/Clinical.tsx +210 -0
- package/src/components/patient/IntakeForm.tsx +532 -0
- package/src/components/patient/Summary.tsx +310 -0
- package/src/components/patient/fields.tsx +144 -0
- package/src/components/patient/query.ts +77 -0
- package/src/components/search.tsx +377 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/useLatestCallback.ts +16 -0
- package/src/hooks/useLive.ts +21 -0
- package/src/hooks/useOnChange.ts +34 -0
- package/src/hooks/useSession.ts +11 -0
- package/src/index.ts +19 -0
- package/src/primitives/PhotonProvider.tsx +153 -0
- package/src/primitives/defaults.tsx +409 -0
- package/src/primitives/icons.tsx +37 -0
- package/src/primitives/index.ts +4 -0
- package/src/primitives/select.ts +15 -0
- package/src/primitives/types.ts +276 -0
- package/src/styles.css +611 -0
- package/src/test-utils/contract.tsx +410 -0
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import { useId, type ReactNode } from "react";
|
|
2
|
+
import { Icon } from "../primitives/icons.tsx";
|
|
3
|
+
import { CHOICE_ACTION, type PhotonComponents, type Tone } from "../primitives/types.ts";
|
|
4
|
+
import { openOnEnter } from "../primitives/select.ts";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Stock Tailwind v4 building blocks — default palette only (slate / indigo /
|
|
8
|
+
* status colours), no config, no plugins.
|
|
9
|
+
*
|
|
10
|
+
* import { tailwindComponents } from "@photonhealth/react/tailwind";
|
|
11
|
+
* <PhotonProvider client={ph} components={tailwindComponents}>
|
|
12
|
+
*
|
|
13
|
+
* No dependency on Tailwind: these are just class strings. Point your Tailwind
|
|
14
|
+
* build at them so the classes get generated, e.g. in your CSS:
|
|
15
|
+
* @source "../node_modules/@photonhealth/react/src/adapters";
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const cx = (...parts: (string | false | null | undefined)[]) => parts.filter(Boolean).join(" ");
|
|
19
|
+
|
|
20
|
+
const gap = { "1": "gap-1", "2": "gap-2", "3": "gap-3", "4": "gap-4", "6": "gap-6" } as const;
|
|
21
|
+
const items = { start: "items-start", center: "items-center", end: "items-end", stretch: "items-stretch" } as const;
|
|
22
|
+
const justify = { start: "justify-start", between: "justify-between", end: "justify-end" } as const;
|
|
23
|
+
|
|
24
|
+
const alertTone: Record<Tone, string> = {
|
|
25
|
+
neutral: "border-slate-300 bg-slate-50 text-slate-800",
|
|
26
|
+
info: "border-indigo-300 bg-indigo-50 text-indigo-900",
|
|
27
|
+
success: "border-emerald-300 bg-emerald-50 text-emerald-900",
|
|
28
|
+
warning: "border-amber-300 bg-amber-50 text-amber-900",
|
|
29
|
+
critical: "border-red-300 bg-red-50 text-red-900",
|
|
30
|
+
};
|
|
31
|
+
const badgeTone: Record<Tone, string> = {
|
|
32
|
+
neutral: "bg-slate-100 text-slate-700 ring-slate-200",
|
|
33
|
+
info: "bg-indigo-50 text-indigo-700 ring-indigo-200",
|
|
34
|
+
success: "bg-emerald-50 text-emerald-700 ring-emerald-200",
|
|
35
|
+
warning: "bg-amber-50 text-amber-800 ring-amber-200",
|
|
36
|
+
critical: "bg-red-50 text-red-700 ring-red-200",
|
|
37
|
+
};
|
|
38
|
+
const buttonVariant = {
|
|
39
|
+
primary: "bg-indigo-600 text-white hover:bg-indigo-500 shadow-sm",
|
|
40
|
+
secondary: "bg-white text-indigo-600 ring-1 ring-inset ring-indigo-600 hover:bg-indigo-50 active:bg-indigo-100",
|
|
41
|
+
ghost: "bg-transparent text-indigo-600 hover:bg-indigo-50 active:bg-indigo-100",
|
|
42
|
+
danger: "bg-red-600 text-white hover:bg-red-500 shadow-sm",
|
|
43
|
+
} as const;
|
|
44
|
+
const buttonSize = { sm: "px-2.5 py-1.5 text-sm", md: "px-3.5 py-2 text-sm", lg: "px-5 py-2.5 text-base" } as const;
|
|
45
|
+
const focus = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600";
|
|
46
|
+
|
|
47
|
+
const control =
|
|
48
|
+
"block w-full rounded-md bg-white px-3 py-2 text-slate-900 ring-1 ring-inset ring-slate-300 placeholder:text-slate-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 focus:outline-none disabled:bg-slate-50 disabled:text-slate-500";
|
|
49
|
+
|
|
50
|
+
function Field({
|
|
51
|
+
label,
|
|
52
|
+
note,
|
|
53
|
+
invalid,
|
|
54
|
+
children,
|
|
55
|
+
}: {
|
|
56
|
+
label?: string;
|
|
57
|
+
note?: string;
|
|
58
|
+
invalid?: boolean;
|
|
59
|
+
children: (id: string, noteId?: string) => React.ReactNode;
|
|
60
|
+
}) {
|
|
61
|
+
const id = useId();
|
|
62
|
+
const noteId = note ? `${id}-note` : undefined;
|
|
63
|
+
return (
|
|
64
|
+
<div className="flex min-w-0 flex-col gap-1">
|
|
65
|
+
{label && (
|
|
66
|
+
<label htmlFor={id} className="text-sm font-medium text-slate-900">
|
|
67
|
+
{label}
|
|
68
|
+
</label>
|
|
69
|
+
)}
|
|
70
|
+
{children(id, noteId)}
|
|
71
|
+
<span id={noteId} className={cx("min-h-5 text-sm", invalid ? "text-red-600" : "text-slate-500")}>
|
|
72
|
+
{note}
|
|
73
|
+
</span>
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const tailwindComponents: PhotonComponents = {
|
|
79
|
+
Stack: ({ gap: g = "4", align = "stretch", children }) => (
|
|
80
|
+
<div className={cx("flex flex-col", gap[g], items[align])}>{children}</div>
|
|
81
|
+
),
|
|
82
|
+
Row: ({ gap: g = "3", align = "center", justify: j = "start", children }) => (
|
|
83
|
+
<div className={cx("flex flex-wrap", gap[g], items[align], justify[j])}>{children}</div>
|
|
84
|
+
),
|
|
85
|
+
Grid: ({ min = "12rem", gap: g = "4", children }) => (
|
|
86
|
+
<div
|
|
87
|
+
className={cx("grid", gap[g])}
|
|
88
|
+
style={{ gridTemplateColumns: `repeat(auto-fit, minmax(min(${min}, 100%), 1fr))` }}
|
|
89
|
+
>
|
|
90
|
+
{children}
|
|
91
|
+
</div>
|
|
92
|
+
),
|
|
93
|
+
Container: ({ as: As = "div", children }) => (
|
|
94
|
+
<As className="mx-auto max-w-[35rem] px-4 py-8 text-slate-900">{children}</As>
|
|
95
|
+
),
|
|
96
|
+
PageHeader: ({ title, description }) => (
|
|
97
|
+
<header>
|
|
98
|
+
<h1 className="text-2xl font-semibold tracking-tight text-slate-900">{title}</h1>
|
|
99
|
+
{description && <p className="mt-1 text-sm text-slate-600">{description}</p>}
|
|
100
|
+
</header>
|
|
101
|
+
),
|
|
102
|
+
Text: ({ tone = "default", children }) => (
|
|
103
|
+
<span
|
|
104
|
+
className={tone === "tertiary" ? "text-sm text-slate-500" : tone === "secondary" ? "text-slate-600" : undefined}
|
|
105
|
+
>
|
|
106
|
+
{children}
|
|
107
|
+
</span>
|
|
108
|
+
),
|
|
109
|
+
Card: ({ divided, children }) => (
|
|
110
|
+
<section
|
|
111
|
+
className={cx("rounded-lg bg-white shadow-sm ring-1", "ring-slate-200", divided && "divide-y divide-slate-200")}
|
|
112
|
+
>
|
|
113
|
+
{children}
|
|
114
|
+
</section>
|
|
115
|
+
),
|
|
116
|
+
CardHeader: ({ title, description, action }) => (
|
|
117
|
+
<div className="flex items-start justify-between gap-4 px-4 py-3">
|
|
118
|
+
<div>
|
|
119
|
+
<h2 className="text-base font-semibold text-slate-900">{title}</h2>
|
|
120
|
+
{description && <p className="mt-0.5 text-sm text-slate-600">{description}</p>}
|
|
121
|
+
</div>
|
|
122
|
+
{action && <div className="shrink-0">{action}</div>}
|
|
123
|
+
</div>
|
|
124
|
+
),
|
|
125
|
+
CardBody: ({ children }) => <div className="px-4 py-4">{children}</div>,
|
|
126
|
+
CardFooter: ({ start, children }) => (
|
|
127
|
+
<div className="flex flex-wrap items-center justify-end gap-2 px-4 py-3">
|
|
128
|
+
{start && <div className="mr-auto">{start}</div>}
|
|
129
|
+
{children}
|
|
130
|
+
</div>
|
|
131
|
+
),
|
|
132
|
+
Spinner: ({ label }) => (
|
|
133
|
+
<span role="status" className="inline-flex items-center gap-2 text-sm text-slate-500">
|
|
134
|
+
<span
|
|
135
|
+
aria-hidden
|
|
136
|
+
className="size-4 animate-spin rounded-full border-2 border-slate-300 border-t-indigo-600 motion-reduce:animate-none"
|
|
137
|
+
/>
|
|
138
|
+
{label}
|
|
139
|
+
</span>
|
|
140
|
+
),
|
|
141
|
+
Button: ({
|
|
142
|
+
variant = "primary",
|
|
143
|
+
size = "md",
|
|
144
|
+
loading,
|
|
145
|
+
disabled,
|
|
146
|
+
className,
|
|
147
|
+
type = "button",
|
|
148
|
+
children,
|
|
149
|
+
icon,
|
|
150
|
+
tone,
|
|
151
|
+
...rest
|
|
152
|
+
}) => (
|
|
153
|
+
<button
|
|
154
|
+
{...rest}
|
|
155
|
+
type={type}
|
|
156
|
+
disabled={disabled || loading}
|
|
157
|
+
aria-busy={loading || undefined}
|
|
158
|
+
className={cx(
|
|
159
|
+
"inline-flex items-center justify-center gap-2 rounded-md font-semibold disabled:cursor-not-allowed disabled:opacity-50",
|
|
160
|
+
buttonVariant[variant],
|
|
161
|
+
tone === "critical" && "text-red-600 hover:bg-red-50 active:bg-red-100",
|
|
162
|
+
icon && !children ? "size-9 p-0" : buttonSize[size],
|
|
163
|
+
focus,
|
|
164
|
+
className,
|
|
165
|
+
)}
|
|
166
|
+
>
|
|
167
|
+
{loading && (
|
|
168
|
+
<span
|
|
169
|
+
className="size-3 animate-spin rounded-full border-2 border-current border-t-transparent motion-reduce:animate-none"
|
|
170
|
+
aria-hidden
|
|
171
|
+
/>
|
|
172
|
+
)}
|
|
173
|
+
{icon && !children ? (
|
|
174
|
+
<Icon name={icon} className="size-5" />
|
|
175
|
+
) : (
|
|
176
|
+
<>
|
|
177
|
+
{icon && <Icon name={icon} className="size-4 shrink-0" />}
|
|
178
|
+
{children}
|
|
179
|
+
</>
|
|
180
|
+
)}
|
|
181
|
+
</button>
|
|
182
|
+
),
|
|
183
|
+
Input: ({ label, helper, invalid, errorMessage, className, loading, ...rest }) => (
|
|
184
|
+
<Field label={label} note={invalid && errorMessage ? errorMessage : helper} invalid={invalid}>
|
|
185
|
+
{(id, noteId) => (
|
|
186
|
+
<span className="relative block">
|
|
187
|
+
<input
|
|
188
|
+
{...rest}
|
|
189
|
+
id={id}
|
|
190
|
+
aria-invalid={invalid || undefined}
|
|
191
|
+
aria-describedby={noteId}
|
|
192
|
+
aria-busy={loading || undefined}
|
|
193
|
+
className={cx(control, invalid && "ring-red-500", loading && "pr-9", className)}
|
|
194
|
+
/>
|
|
195
|
+
{loading && (
|
|
196
|
+
<span
|
|
197
|
+
aria-hidden
|
|
198
|
+
className="absolute top-1/2 right-3 size-4 -translate-y-1/2 animate-spin rounded-full border-2 border-slate-300 border-t-indigo-600 motion-reduce:animate-none"
|
|
199
|
+
/>
|
|
200
|
+
)}
|
|
201
|
+
</span>
|
|
202
|
+
)}
|
|
203
|
+
</Field>
|
|
204
|
+
),
|
|
205
|
+
Textarea: ({ label, helper, invalid, errorMessage, className, ...rest }) => (
|
|
206
|
+
<Field label={label} note={invalid && errorMessage ? errorMessage : helper} invalid={invalid}>
|
|
207
|
+
{(id, noteId) => (
|
|
208
|
+
<textarea
|
|
209
|
+
{...rest}
|
|
210
|
+
id={id}
|
|
211
|
+
aria-invalid={invalid || undefined}
|
|
212
|
+
aria-describedby={noteId}
|
|
213
|
+
className={cx(control, "resize-y", className)}
|
|
214
|
+
/>
|
|
215
|
+
)}
|
|
216
|
+
</Field>
|
|
217
|
+
),
|
|
218
|
+
Checkbox: ({ label, checked, onChange, disabled }) => (
|
|
219
|
+
<label className="inline-flex items-center gap-2 text-sm text-slate-900">
|
|
220
|
+
<input
|
|
221
|
+
type="checkbox"
|
|
222
|
+
className="size-4 rounded border-slate-300 accent-indigo-600"
|
|
223
|
+
checked={checked}
|
|
224
|
+
disabled={disabled}
|
|
225
|
+
onChange={(e) => onChange(e.target.checked)}
|
|
226
|
+
/>
|
|
227
|
+
{label}
|
|
228
|
+
</label>
|
|
229
|
+
),
|
|
230
|
+
// Safari draws a native <select> itself and ignores the ring / padding below (Photon-Health/prescribe#15).
|
|
231
|
+
Select: ({ label, options, value, onChange, placeholder = "Select…", helper, disabled, invalid, errorMessage }) => (
|
|
232
|
+
<Field label={label} note={invalid && errorMessage ? errorMessage : helper} invalid={invalid}>
|
|
233
|
+
{(id, noteId) => (
|
|
234
|
+
<select
|
|
235
|
+
id={id}
|
|
236
|
+
value={value ?? ""}
|
|
237
|
+
disabled={disabled}
|
|
238
|
+
aria-invalid={invalid || undefined}
|
|
239
|
+
aria-describedby={noteId}
|
|
240
|
+
onChange={(e) => e.target.value && onChange(e.target.value as never)}
|
|
241
|
+
onKeyDown={openOnEnter}
|
|
242
|
+
className={cx(control, "pr-8")}
|
|
243
|
+
>
|
|
244
|
+
<option value="" disabled>
|
|
245
|
+
{placeholder}
|
|
246
|
+
</option>
|
|
247
|
+
{options.map((o) => (
|
|
248
|
+
<option key={o.value} value={o.value}>
|
|
249
|
+
{o.label}
|
|
250
|
+
</option>
|
|
251
|
+
))}
|
|
252
|
+
</select>
|
|
253
|
+
)}
|
|
254
|
+
</Field>
|
|
255
|
+
),
|
|
256
|
+
RadioGroup: ({ label, options, value, onChange, horizontal }) => {
|
|
257
|
+
const name = useId();
|
|
258
|
+
return (
|
|
259
|
+
<fieldset>
|
|
260
|
+
<legend className="text-sm font-medium text-slate-900">{label}</legend>
|
|
261
|
+
<div className={cx("mt-2 flex gap-4", horizontal ? "flex-row flex-wrap" : "flex-col")}>
|
|
262
|
+
{options.map((o) => (
|
|
263
|
+
<label key={o.value} className="inline-flex items-center gap-2 text-sm text-slate-900">
|
|
264
|
+
<input
|
|
265
|
+
type="radio"
|
|
266
|
+
name={name}
|
|
267
|
+
className="size-4 accent-indigo-600"
|
|
268
|
+
checked={value === o.value}
|
|
269
|
+
onChange={() => onChange(o.value)}
|
|
270
|
+
/>
|
|
271
|
+
{o.label}
|
|
272
|
+
</label>
|
|
273
|
+
))}
|
|
274
|
+
</div>
|
|
275
|
+
</fieldset>
|
|
276
|
+
);
|
|
277
|
+
},
|
|
278
|
+
// Rows like OptionList's: separate cards; keyboard focus reads as its selected row (inset indigo ring).
|
|
279
|
+
ChoiceList: ({ label, choices, onChoose, disabled, pendingKey, action, activeKey, id }) => {
|
|
280
|
+
// A field that keeps the cursor drives this list: its rows are options it points at, not buttons.
|
|
281
|
+
const inField = activeKey !== undefined;
|
|
282
|
+
const base = "group flex w-full items-center gap-3 rounded-md px-4 py-3 text-left";
|
|
283
|
+
const choiceRest = "bg-white ring-1 ring-slate-200 ring-inset hover:bg-slate-50 disabled:opacity-50";
|
|
284
|
+
const actionRest = "text-sm font-medium text-indigo-600 hover:bg-slate-50 disabled:opacity-50";
|
|
285
|
+
const lit = "bg-indigo-50 ring-2 ring-indigo-600 ring-inset";
|
|
286
|
+
const focus =
|
|
287
|
+
"focus-visible:bg-indigo-50 focus-visible:ring-2 focus-visible:ring-indigo-600 focus-visible:ring-inset focus-visible:outline-none";
|
|
288
|
+
const row = (key: string, active: boolean, onPick: () => void, body: ReactNode) => {
|
|
289
|
+
const rest = key === CHOICE_ACTION ? actionRest : choiceRest;
|
|
290
|
+
return inField ? (
|
|
291
|
+
<li
|
|
292
|
+
key={key}
|
|
293
|
+
id={id ? `${id}-${key}` : undefined}
|
|
294
|
+
role="option"
|
|
295
|
+
aria-selected={active}
|
|
296
|
+
aria-busy={key === pendingKey || undefined}
|
|
297
|
+
className={`${base} ${rest} cursor-pointer ${active ? lit : ""}`}
|
|
298
|
+
onClick={disabled ? undefined : onPick}
|
|
299
|
+
>
|
|
300
|
+
{body}
|
|
301
|
+
</li>
|
|
302
|
+
) : (
|
|
303
|
+
<li key={key}>
|
|
304
|
+
<button
|
|
305
|
+
type="button"
|
|
306
|
+
disabled={disabled}
|
|
307
|
+
aria-busy={key === pendingKey || undefined}
|
|
308
|
+
onClick={onPick}
|
|
309
|
+
className={`${base} ${rest} ${focus} aria-busy:bg-indigo-50 aria-busy:ring-2 aria-busy:ring-indigo-600`}
|
|
310
|
+
>
|
|
311
|
+
{body}
|
|
312
|
+
</button>
|
|
313
|
+
</li>
|
|
314
|
+
);
|
|
315
|
+
};
|
|
316
|
+
const glyph = (active: boolean) => (
|
|
317
|
+
<Icon
|
|
318
|
+
name="return"
|
|
319
|
+
className={`size-4 shrink-0 text-indigo-600 ${active ? "visible" : "invisible group-focus-visible:visible"}`}
|
|
320
|
+
/>
|
|
321
|
+
);
|
|
322
|
+
return (
|
|
323
|
+
<ul aria-label={label} role={inField ? "listbox" : undefined} className="flex flex-col gap-2">
|
|
324
|
+
{choices.map((c) =>
|
|
325
|
+
row(
|
|
326
|
+
c.key,
|
|
327
|
+
c.key === activeKey,
|
|
328
|
+
() => onChoose(c.key),
|
|
329
|
+
<>
|
|
330
|
+
<span className="flex min-w-0 flex-1 flex-col">
|
|
331
|
+
<span className="flex flex-wrap items-baseline gap-x-2">
|
|
332
|
+
<span className="text-sm text-slate-900">{c.label}</span>
|
|
333
|
+
{c.meta && <span className="text-xs text-slate-500">{c.meta}</span>}
|
|
334
|
+
</span>
|
|
335
|
+
{c.description && <span className="text-xs text-slate-500">{c.description}</span>}
|
|
336
|
+
</span>
|
|
337
|
+
{glyph(c.key === activeKey)}
|
|
338
|
+
</>,
|
|
339
|
+
),
|
|
340
|
+
)}
|
|
341
|
+
{action &&
|
|
342
|
+
row(
|
|
343
|
+
CHOICE_ACTION,
|
|
344
|
+
activeKey === CHOICE_ACTION,
|
|
345
|
+
action.onChoose,
|
|
346
|
+
<>
|
|
347
|
+
{action.icon && <Icon name={action.icon} className="size-4 shrink-0" />}
|
|
348
|
+
<span className="min-w-0 flex-1">{action.label}</span>
|
|
349
|
+
{glyph(activeKey === CHOICE_ACTION)}
|
|
350
|
+
</>,
|
|
351
|
+
)}
|
|
352
|
+
</ul>
|
|
353
|
+
);
|
|
354
|
+
},
|
|
355
|
+
OptionList: function TailwindOptionList({
|
|
356
|
+
label,
|
|
357
|
+
options,
|
|
358
|
+
activeKey,
|
|
359
|
+
activeSelected,
|
|
360
|
+
onSelect,
|
|
361
|
+
onKeyDown,
|
|
362
|
+
disabled,
|
|
363
|
+
children,
|
|
364
|
+
}) {
|
|
365
|
+
return (
|
|
366
|
+
<div tabIndex={0} aria-label={label} onKeyDown={onKeyDown} className="outline-none">
|
|
367
|
+
<ul aria-label={label} className="flex flex-col gap-2">
|
|
368
|
+
{options.map((o) => {
|
|
369
|
+
const active = o.key === activeKey;
|
|
370
|
+
// Top right: a spinner while its choice is saved, else (a row that opens) the chevron.
|
|
371
|
+
const trailing = o.loading ? (
|
|
372
|
+
<span
|
|
373
|
+
aria-hidden
|
|
374
|
+
className="ml-auto size-4 shrink-0 animate-spin rounded-full border-2 border-slate-300 border-t-indigo-600 motion-reduce:animate-none"
|
|
375
|
+
/>
|
|
376
|
+
) : active || o.direct ? null : (
|
|
377
|
+
<Icon name="chevron" className="ml-auto size-4 shrink-0 self-center text-slate-400" />
|
|
378
|
+
);
|
|
379
|
+
const row = (
|
|
380
|
+
<span className="flex w-full items-center gap-2.5">
|
|
381
|
+
<span className="flex min-w-0 flex-col">
|
|
382
|
+
<span className={cx("text-sm text-slate-900", active && "font-semibold")}>{o.label}</span>
|
|
383
|
+
{o.description && <span className="text-xs text-slate-500">{o.description}</span>}
|
|
384
|
+
</span>
|
|
385
|
+
{trailing}
|
|
386
|
+
</span>
|
|
387
|
+
);
|
|
388
|
+
return (
|
|
389
|
+
<li key={o.key}>
|
|
390
|
+
{active && !o.direct ? (
|
|
391
|
+
<div
|
|
392
|
+
aria-current="true"
|
|
393
|
+
aria-busy={o.loading || undefined}
|
|
394
|
+
className={cx(
|
|
395
|
+
"flex flex-col gap-3 rounded-md px-4 pt-3.5 pb-4",
|
|
396
|
+
activeSelected
|
|
397
|
+
? "bg-indigo-50 ring-2 ring-indigo-600 ring-inset"
|
|
398
|
+
: "bg-white ring-1 ring-slate-200",
|
|
399
|
+
)}
|
|
400
|
+
>
|
|
401
|
+
{row}
|
|
402
|
+
{children}
|
|
403
|
+
</div>
|
|
404
|
+
) : (
|
|
405
|
+
<button
|
|
406
|
+
type="button"
|
|
407
|
+
disabled={disabled}
|
|
408
|
+
aria-label={o.ariaLabel}
|
|
409
|
+
aria-current={active || undefined}
|
|
410
|
+
aria-busy={o.loading || undefined}
|
|
411
|
+
onClick={() => onSelect(o.key)}
|
|
412
|
+
className={cx(
|
|
413
|
+
"flex w-full rounded-md px-4 py-3 text-left hover:bg-slate-50 disabled:opacity-50",
|
|
414
|
+
active && activeSelected
|
|
415
|
+
? "bg-indigo-50 ring-2 ring-indigo-600 ring-inset"
|
|
416
|
+
: "bg-white ring-1 ring-slate-200",
|
|
417
|
+
focus,
|
|
418
|
+
)}
|
|
419
|
+
>
|
|
420
|
+
{row}
|
|
421
|
+
</button>
|
|
422
|
+
)}
|
|
423
|
+
</li>
|
|
424
|
+
);
|
|
425
|
+
})}
|
|
426
|
+
</ul>
|
|
427
|
+
</div>
|
|
428
|
+
);
|
|
429
|
+
},
|
|
430
|
+
ActionBar: ({ children }) => <div className="flex items-center justify-end gap-4">{children}</div>,
|
|
431
|
+
// In a narrow container (a phone, a dialog, a side panel) the chips share the row evenly, for thumbs.
|
|
432
|
+
// Chips in a grid of equal columns: every chip the same width, a partial last row too. How many across goes by
|
|
433
|
+
// the longest label (and its detail): short 3 (4 on a wider card), medium 2, longer 1 (2).
|
|
434
|
+
ToggleGroup: function TailwindToggleGroup({ label, options, value, onChange, disabled }) {
|
|
435
|
+
const id = useId();
|
|
436
|
+
const longest = Math.max(0, ...options.map((o) => o.label.length + (o.detail ? o.detail.length + 1 : 0)));
|
|
437
|
+
const columns =
|
|
438
|
+
longest <= 15 ? "grid-cols-3 @md:grid-cols-4" : longest <= 24 ? "grid-cols-2" : "grid-cols-1 @md:grid-cols-2";
|
|
439
|
+
return (
|
|
440
|
+
<div className="@container flex flex-col gap-2">
|
|
441
|
+
<div id={id} className="text-xs font-semibold text-slate-700">
|
|
442
|
+
{label}
|
|
443
|
+
</div>
|
|
444
|
+
<div role="group" aria-labelledby={id} className={cx("grid gap-2", columns)}>
|
|
445
|
+
{options.map((o) => {
|
|
446
|
+
const selected = o.value === value;
|
|
447
|
+
return (
|
|
448
|
+
<button
|
|
449
|
+
key={o.value}
|
|
450
|
+
type="button"
|
|
451
|
+
aria-pressed={selected}
|
|
452
|
+
aria-label={o.ariaLabel}
|
|
453
|
+
data-muted={o.muted || undefined}
|
|
454
|
+
disabled={disabled}
|
|
455
|
+
onClick={() => onChange(o.value)}
|
|
456
|
+
className={cx(
|
|
457
|
+
"flex min-w-0 flex-wrap items-baseline justify-center gap-x-1.5 rounded-md px-2 py-2 text-center text-sm disabled:opacity-50",
|
|
458
|
+
selected
|
|
459
|
+
? "bg-indigo-600 font-semibold text-white hover:bg-indigo-500"
|
|
460
|
+
: "bg-white font-medium text-slate-900 ring-1 ring-slate-300 hover:bg-slate-50",
|
|
461
|
+
o.muted && !selected && "text-slate-400 ring-slate-200",
|
|
462
|
+
focus,
|
|
463
|
+
)}
|
|
464
|
+
>
|
|
465
|
+
{o.label}
|
|
466
|
+
{o.detail && (
|
|
467
|
+
<span className={cx("text-xs font-normal", selected ? "text-indigo-100" : "text-slate-500")}>
|
|
468
|
+
{o.detail}
|
|
469
|
+
</span>
|
|
470
|
+
)}
|
|
471
|
+
</button>
|
|
472
|
+
);
|
|
473
|
+
})}
|
|
474
|
+
</div>
|
|
475
|
+
</div>
|
|
476
|
+
);
|
|
477
|
+
},
|
|
478
|
+
Alert: ({ tone = "info", title, description, onDismiss }) => (
|
|
479
|
+
<div
|
|
480
|
+
role={tone === "warning" || tone === "critical" ? "alert" : "status"}
|
|
481
|
+
className={cx("flex items-start justify-between gap-3 rounded-md border px-4 py-3 text-sm", alertTone[tone])}
|
|
482
|
+
>
|
|
483
|
+
<div>
|
|
484
|
+
<p className="font-semibold">{title}</p>
|
|
485
|
+
{description && <div className="mt-1">{description}</div>}
|
|
486
|
+
</div>
|
|
487
|
+
{onDismiss && (
|
|
488
|
+
<button
|
|
489
|
+
type="button"
|
|
490
|
+
onClick={onDismiss}
|
|
491
|
+
aria-label="Dismiss"
|
|
492
|
+
className={cx("rounded px-1 opacity-70 hover:opacity-100", focus)}
|
|
493
|
+
>
|
|
494
|
+
<Icon name="close" className="size-3.5" />
|
|
495
|
+
</button>
|
|
496
|
+
)}
|
|
497
|
+
</div>
|
|
498
|
+
),
|
|
499
|
+
Badge: ({ tone = "neutral", children, icon, onRemove, removeLabel = "Remove" }) => (
|
|
500
|
+
<span
|
|
501
|
+
className={cx(
|
|
502
|
+
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium ring-1 ring-inset",
|
|
503
|
+
badgeTone[tone],
|
|
504
|
+
)}
|
|
505
|
+
>
|
|
506
|
+
{icon && <Icon name={icon} className="size-3" />}
|
|
507
|
+
{children}
|
|
508
|
+
{onRemove && (
|
|
509
|
+
<button
|
|
510
|
+
type="button"
|
|
511
|
+
aria-label={removeLabel}
|
|
512
|
+
onClick={onRemove}
|
|
513
|
+
className={cx("-mr-1 rounded-full px-1 opacity-60 hover:opacity-100", focus)}
|
|
514
|
+
>
|
|
515
|
+
<Icon name="close" className="size-3.5" />
|
|
516
|
+
</button>
|
|
517
|
+
)}
|
|
518
|
+
</span>
|
|
519
|
+
),
|
|
520
|
+
Disclosure: ({ summary, open, onOpenChange, children }) => {
|
|
521
|
+
const id = useId();
|
|
522
|
+
return (
|
|
523
|
+
<div className="flex flex-col gap-3">
|
|
524
|
+
<button
|
|
525
|
+
type="button"
|
|
526
|
+
aria-expanded={open}
|
|
527
|
+
aria-controls={id}
|
|
528
|
+
onClick={() => onOpenChange(!open)}
|
|
529
|
+
className={cx(
|
|
530
|
+
"flex w-full items-center gap-1.5 rounded-md text-left text-sm text-slate-600 hover:text-slate-900",
|
|
531
|
+
focus,
|
|
532
|
+
)}
|
|
533
|
+
>
|
|
534
|
+
<Icon
|
|
535
|
+
name="chevron"
|
|
536
|
+
className={cx("size-4 shrink-0 transition-transform motion-reduce:transition-none", open && "rotate-90")}
|
|
537
|
+
/>
|
|
538
|
+
<span>{summary}</span>
|
|
539
|
+
</button>
|
|
540
|
+
{open && <div id={id}>{children}</div>}
|
|
541
|
+
</div>
|
|
542
|
+
);
|
|
543
|
+
},
|
|
544
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useComponents } from "../primitives/index.ts";
|
|
2
|
+
import type { ChangeOption, ClassifiedChanges } from "@photonhealth/client";
|
|
3
|
+
import { orderedOptions } from "./display.ts";
|
|
4
|
+
import { SearchResults, type SearchHandle } from "./search.tsx";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Renders any ChangeSet the same way in every component:
|
|
9
|
+
* needsChoice → the server's options as search results (closest first; onChoose re-sends)
|
|
10
|
+
* blocking → critical, with the server's reason
|
|
11
|
+
* advisories → dismissible info (COST_SAVINGS, PRODUCT_PREFERENCE, …)
|
|
12
|
+
* Applied INFO changes are not shown — they already took effect. `handleRef` reaches the first choice's
|
|
13
|
+
* results — from the field that asked (e.g. Add allergy), so its keys work on them.
|
|
14
|
+
*/
|
|
15
|
+
export function ChangeList({
|
|
16
|
+
changes,
|
|
17
|
+
onChoose,
|
|
18
|
+
busy,
|
|
19
|
+
handleRef,
|
|
20
|
+
onBack,
|
|
21
|
+
}: {
|
|
22
|
+
changes: ClassifiedChanges;
|
|
23
|
+
onChoose?: (option: ChangeOption) => void;
|
|
24
|
+
busy?: boolean;
|
|
25
|
+
handleRef?: { current: SearchHandle | null };
|
|
26
|
+
/** Esc in the first choice's results: back to the field that asked. */
|
|
27
|
+
onBack?: () => void;
|
|
28
|
+
}) {
|
|
29
|
+
const { Alert, Stack } = useComponents();
|
|
30
|
+
const [dismissed, setDismissed] = useState<Set<string>>(new Set());
|
|
31
|
+
// The server can report the same problem once per affected field; show it once.
|
|
32
|
+
const unique = <T extends { key: string; label: string; reason: string | null }>(list: T[]) => {
|
|
33
|
+
const seen = new Set<string>();
|
|
34
|
+
return list.filter((c) => {
|
|
35
|
+
const id = `${c.label}|${c.reason ?? ""}`;
|
|
36
|
+
return seen.has(id) ? false : (seen.add(id), true);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const needsChoice = unique(changes.needsChoice);
|
|
40
|
+
const blocking = unique(changes.blocking);
|
|
41
|
+
const advisories = unique(changes.advisories).filter((c) => !dismissed.has(c.key));
|
|
42
|
+
if (!needsChoice.length && !blocking.length && !advisories.length) return null;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Stack gap="2">
|
|
46
|
+
{needsChoice.map((change, i) => {
|
|
47
|
+
// Only options that say where their pick goes can be sent back.
|
|
48
|
+
const options = orderedOptions({ options: change.options.filter((o) => o.path) }, change.inputText);
|
|
49
|
+
return (
|
|
50
|
+
<SearchResults
|
|
51
|
+
key={`${change.key}-${i}`}
|
|
52
|
+
label={change.label}
|
|
53
|
+
busy={busy}
|
|
54
|
+
disabled={!onChoose}
|
|
55
|
+
results={options.map((o, j) => ({
|
|
56
|
+
key: String(j),
|
|
57
|
+
label: o.displayName,
|
|
58
|
+
description: o.reason ?? undefined,
|
|
59
|
+
}))}
|
|
60
|
+
onPick={(key) => onChoose?.(options[Number(key)]!)}
|
|
61
|
+
handleRef={i === 0 ? handleRef : undefined}
|
|
62
|
+
onBack={i === 0 ? onBack : undefined}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
})}
|
|
66
|
+
{blocking.map((change, i) => (
|
|
67
|
+
<Alert
|
|
68
|
+
key={`${change.key}-${i}`}
|
|
69
|
+
tone="critical"
|
|
70
|
+
title={change.label}
|
|
71
|
+
description={change.reason ?? undefined}
|
|
72
|
+
/>
|
|
73
|
+
))}
|
|
74
|
+
{advisories.map((change) => (
|
|
75
|
+
<Alert
|
|
76
|
+
key={change.key}
|
|
77
|
+
tone="info"
|
|
78
|
+
title={change.label}
|
|
79
|
+
description={change.reason ?? undefined}
|
|
80
|
+
onDismiss={() => setDismissed((d) => new Set(d).add(change.key))}
|
|
81
|
+
/>
|
|
82
|
+
))}
|
|
83
|
+
</Stack>
|
|
84
|
+
);
|
|
85
|
+
}
|