@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,409 @@
|
|
|
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, children }) => (
|
|
79
|
+
<section className="prx-card" data-divided={divided || undefined}>
|
|
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, ...rest }) => (
|
|
128
|
+
<Field label={label} helper={helper} invalid={invalid} errorMessage={errorMessage}>
|
|
129
|
+
{({ id, describedBy }) => (
|
|
130
|
+
<span className="prx-input-wrap">
|
|
131
|
+
<input
|
|
132
|
+
{...rest}
|
|
133
|
+
id={id}
|
|
134
|
+
className={cx("prx-input", className)}
|
|
135
|
+
aria-invalid={invalid || undefined}
|
|
136
|
+
aria-describedby={describedBy}
|
|
137
|
+
aria-busy={loading || undefined}
|
|
138
|
+
/>
|
|
139
|
+
{loading && <span className="prx-spinner" aria-hidden="true" />}
|
|
140
|
+
</span>
|
|
141
|
+
)}
|
|
142
|
+
</Field>
|
|
143
|
+
),
|
|
144
|
+
Textarea: ({ label, helper, invalid, errorMessage, className, ...rest }) => (
|
|
145
|
+
<Field label={label} helper={helper} invalid={invalid} errorMessage={errorMessage}>
|
|
146
|
+
{({ id, describedBy }) => (
|
|
147
|
+
<textarea
|
|
148
|
+
{...rest}
|
|
149
|
+
id={id}
|
|
150
|
+
className={cx("prx-input", className)}
|
|
151
|
+
aria-invalid={invalid || undefined}
|
|
152
|
+
aria-describedby={describedBy}
|
|
153
|
+
/>
|
|
154
|
+
)}
|
|
155
|
+
</Field>
|
|
156
|
+
),
|
|
157
|
+
Checkbox: ({ label, checked, onChange, disabled }) => (
|
|
158
|
+
<label className="prx-check">
|
|
159
|
+
<input type="checkbox" checked={checked} disabled={disabled} onChange={(e) => onChange(e.target.checked)} />
|
|
160
|
+
<span>{label}</span>
|
|
161
|
+
</label>
|
|
162
|
+
),
|
|
163
|
+
Select: ({ label, options, value, onChange, placeholder = "Select…", helper, disabled, invalid, errorMessage }) => (
|
|
164
|
+
<Field label={label} helper={helper} invalid={invalid} errorMessage={errorMessage}>
|
|
165
|
+
{({ id, describedBy }) => (
|
|
166
|
+
<select
|
|
167
|
+
id={id}
|
|
168
|
+
className="prx-input prx-select"
|
|
169
|
+
value={value ?? ""}
|
|
170
|
+
disabled={disabled}
|
|
171
|
+
aria-invalid={invalid || undefined}
|
|
172
|
+
aria-describedby={describedBy}
|
|
173
|
+
onChange={(e) => e.target.value && onChange(e.target.value as never)}
|
|
174
|
+
onKeyDown={openOnEnter}
|
|
175
|
+
>
|
|
176
|
+
<option value="" disabled>
|
|
177
|
+
{placeholder}
|
|
178
|
+
</option>
|
|
179
|
+
{options.map((o) => (
|
|
180
|
+
<option key={o.value} value={o.value}>
|
|
181
|
+
{o.label}
|
|
182
|
+
</option>
|
|
183
|
+
))}
|
|
184
|
+
</select>
|
|
185
|
+
)}
|
|
186
|
+
</Field>
|
|
187
|
+
),
|
|
188
|
+
RadioGroup: ({ label, options, value, onChange, horizontal }) => {
|
|
189
|
+
const name = useId();
|
|
190
|
+
return (
|
|
191
|
+
<fieldset className="prx-radio-group" data-horizontal={horizontal || undefined}>
|
|
192
|
+
<legend className="prx-label">{label}</legend>
|
|
193
|
+
{options.map((o) => (
|
|
194
|
+
<label key={o.value} className="prx-check">
|
|
195
|
+
<input type="radio" name={name} checked={value === o.value} onChange={() => onChange(o.value)} />
|
|
196
|
+
<span>{o.label}</span>
|
|
197
|
+
</label>
|
|
198
|
+
))}
|
|
199
|
+
</fieldset>
|
|
200
|
+
);
|
|
201
|
+
},
|
|
202
|
+
ChoiceList: ({ label, choices, onChoose, disabled, pendingKey, action, activeKey, id }) => {
|
|
203
|
+
// A field that keeps the cursor drives this list, so its rows are options it points at rather than
|
|
204
|
+
// buttons the keys move between.
|
|
205
|
+
const inField = activeKey !== undefined;
|
|
206
|
+
const row = (key: string, active: boolean, onPick: () => void, body: ReactNode) =>
|
|
207
|
+
inField ? (
|
|
208
|
+
<li
|
|
209
|
+
key={key}
|
|
210
|
+
id={id ? `${id}-${key}` : undefined}
|
|
211
|
+
role="option"
|
|
212
|
+
aria-selected={active}
|
|
213
|
+
aria-busy={key === pendingKey || undefined}
|
|
214
|
+
className={`prx-choice${key === CHOICE_ACTION ? " prx-choice-action" : ""}${active ? " prx-choice-active" : ""}`}
|
|
215
|
+
onClick={disabled ? undefined : onPick}
|
|
216
|
+
>
|
|
217
|
+
{body}
|
|
218
|
+
</li>
|
|
219
|
+
) : (
|
|
220
|
+
<li key={key}>
|
|
221
|
+
<button
|
|
222
|
+
type="button"
|
|
223
|
+
className={`prx-choice${key === CHOICE_ACTION ? " prx-choice-action" : ""}`}
|
|
224
|
+
disabled={disabled}
|
|
225
|
+
aria-busy={key === pendingKey || undefined}
|
|
226
|
+
onClick={onPick}
|
|
227
|
+
>
|
|
228
|
+
{body}
|
|
229
|
+
</button>
|
|
230
|
+
</li>
|
|
231
|
+
);
|
|
232
|
+
return (
|
|
233
|
+
<ul className="prx-choices" aria-label={label} role={inField ? "listbox" : undefined}>
|
|
234
|
+
{choices.map((c) =>
|
|
235
|
+
row(
|
|
236
|
+
c.key,
|
|
237
|
+
c.key === activeKey,
|
|
238
|
+
() => onChoose(c.key),
|
|
239
|
+
<>
|
|
240
|
+
<span className="prx-choice-text">
|
|
241
|
+
<span className="prx-choice-line">
|
|
242
|
+
<span>{c.label}</span>
|
|
243
|
+
{c.meta && <span className="prx-choice-description">{c.meta}</span>}
|
|
244
|
+
</span>
|
|
245
|
+
{c.description && <span className="prx-choice-description">{c.description}</span>}
|
|
246
|
+
</span>
|
|
247
|
+
<Icon name="return" className="prx-choice-return" />
|
|
248
|
+
</>,
|
|
249
|
+
),
|
|
250
|
+
)}
|
|
251
|
+
{action &&
|
|
252
|
+
row(
|
|
253
|
+
CHOICE_ACTION,
|
|
254
|
+
activeKey === CHOICE_ACTION,
|
|
255
|
+
action.onChoose,
|
|
256
|
+
<>
|
|
257
|
+
{action.icon && <Icon name={action.icon} className="prx-icon" />}
|
|
258
|
+
<span className="prx-choice-text">{action.label}</span>
|
|
259
|
+
<Icon name="return" className="prx-choice-return" />
|
|
260
|
+
</>,
|
|
261
|
+
)}
|
|
262
|
+
</ul>
|
|
263
|
+
);
|
|
264
|
+
},
|
|
265
|
+
OptionList: ({ label, options, activeKey, activeSelected, onSelect, onKeyDown, disabled, children }) => {
|
|
266
|
+
return (
|
|
267
|
+
<div className="prx-options" tabIndex={0} aria-label={label} onKeyDown={onKeyDown}>
|
|
268
|
+
<ul className="prx-options-list" aria-label={label}>
|
|
269
|
+
{options.map((o) => {
|
|
270
|
+
const text = (
|
|
271
|
+
<span className="prx-option-text">
|
|
272
|
+
<span className="prx-option-label">{o.label}</span>
|
|
273
|
+
{o.description && <span className="prx-choice-description">{o.description}</span>}
|
|
274
|
+
</span>
|
|
275
|
+
);
|
|
276
|
+
const active = o.key === activeKey;
|
|
277
|
+
return (
|
|
278
|
+
<li key={o.key}>
|
|
279
|
+
{active && !o.direct ? (
|
|
280
|
+
<div
|
|
281
|
+
className="prx-option"
|
|
282
|
+
data-active=""
|
|
283
|
+
data-selected={activeSelected || undefined}
|
|
284
|
+
aria-current="true"
|
|
285
|
+
aria-busy={o.loading || undefined}
|
|
286
|
+
>
|
|
287
|
+
<div className="prx-option-row">
|
|
288
|
+
{text}
|
|
289
|
+
{o.loading && <span className="prx-spinner prx-option-chevron" aria-hidden="true" />}
|
|
290
|
+
</div>
|
|
291
|
+
{children}
|
|
292
|
+
</div>
|
|
293
|
+
) : (
|
|
294
|
+
<button
|
|
295
|
+
type="button"
|
|
296
|
+
className="prx-option"
|
|
297
|
+
data-active={active ? "" : undefined}
|
|
298
|
+
data-selected={(active && activeSelected) || undefined}
|
|
299
|
+
aria-current={active || undefined}
|
|
300
|
+
aria-busy={o.loading || undefined}
|
|
301
|
+
disabled={disabled}
|
|
302
|
+
aria-label={o.ariaLabel}
|
|
303
|
+
onClick={() => onSelect(o.key)}
|
|
304
|
+
>
|
|
305
|
+
<span className="prx-option-row">
|
|
306
|
+
{text}
|
|
307
|
+
{o.loading ? (
|
|
308
|
+
<span className="prx-spinner prx-option-chevron" aria-hidden="true" />
|
|
309
|
+
) : (
|
|
310
|
+
!o.direct && <Icon name="chevron" className="prx-icon prx-option-chevron" />
|
|
311
|
+
)}
|
|
312
|
+
</span>
|
|
313
|
+
</button>
|
|
314
|
+
)}
|
|
315
|
+
</li>
|
|
316
|
+
);
|
|
317
|
+
})}
|
|
318
|
+
</ul>
|
|
319
|
+
</div>
|
|
320
|
+
);
|
|
321
|
+
},
|
|
322
|
+
ActionBar: ({ children }) => <div className="prx-action-bar">{children}</div>,
|
|
323
|
+
ToggleGroup: ({ label, options, value, onChange, disabled }) => {
|
|
324
|
+
const id = useId();
|
|
325
|
+
return (
|
|
326
|
+
<div className="prx-toggle-group">
|
|
327
|
+
<div className="prx-toggle-label" id={id}>
|
|
328
|
+
<strong>{label}</strong>
|
|
329
|
+
</div>
|
|
330
|
+
<div className="prx-toggles" role="group" aria-labelledby={id}>
|
|
331
|
+
{options.map((o) => (
|
|
332
|
+
<button
|
|
333
|
+
key={o.value}
|
|
334
|
+
type="button"
|
|
335
|
+
className="prx-toggle"
|
|
336
|
+
aria-pressed={o.value === value}
|
|
337
|
+
aria-label={o.ariaLabel}
|
|
338
|
+
data-muted={o.muted || undefined}
|
|
339
|
+
disabled={disabled}
|
|
340
|
+
onClick={() => onChange(o.value)}
|
|
341
|
+
>
|
|
342
|
+
{o.label}
|
|
343
|
+
{o.detail && <span className="prx-choice-description">{o.detail}</span>}
|
|
344
|
+
</button>
|
|
345
|
+
))}
|
|
346
|
+
</div>
|
|
347
|
+
</div>
|
|
348
|
+
);
|
|
349
|
+
},
|
|
350
|
+
Alert: ({ tone = "info", title, description, onDismiss }) => (
|
|
351
|
+
<div className="prx-alert" data-tone={tone} role={tone === "warning" || tone === "critical" ? "alert" : "status"}>
|
|
352
|
+
<div>
|
|
353
|
+
<strong className="prx-alert-title">{title}</strong>
|
|
354
|
+
{description && <div className="prx-alert-description">{description}</div>}
|
|
355
|
+
</div>
|
|
356
|
+
{onDismiss && (
|
|
357
|
+
<button
|
|
358
|
+
type="button"
|
|
359
|
+
className="prx-button"
|
|
360
|
+
data-variant="ghost"
|
|
361
|
+
data-size="sm"
|
|
362
|
+
onClick={onDismiss}
|
|
363
|
+
aria-label="Dismiss"
|
|
364
|
+
>
|
|
365
|
+
<Icon name="close" className="prx-icon" />
|
|
366
|
+
</button>
|
|
367
|
+
)}
|
|
368
|
+
</div>
|
|
369
|
+
),
|
|
370
|
+
Badge: ({ tone = "neutral", children, icon, onRemove, removeLabel = "Remove" }) => (
|
|
371
|
+
<span className="prx-badge" data-tone={tone}>
|
|
372
|
+
{icon && <Icon name={icon} className="prx-icon" />}
|
|
373
|
+
{children}
|
|
374
|
+
{onRemove && (
|
|
375
|
+
<button type="button" className="prx-badge-remove" aria-label={removeLabel} onClick={onRemove}>
|
|
376
|
+
<Icon name="close" className="prx-icon" />
|
|
377
|
+
</button>
|
|
378
|
+
)}
|
|
379
|
+
</span>
|
|
380
|
+
),
|
|
381
|
+
Spinner: ({ label }) => (
|
|
382
|
+
<span className="prx-spinner-status" role="status">
|
|
383
|
+
<span className="prx-spinner" aria-hidden="true" />
|
|
384
|
+
{label}
|
|
385
|
+
</span>
|
|
386
|
+
),
|
|
387
|
+
Disclosure: ({ summary, open, onOpenChange, children }) => {
|
|
388
|
+
const id = useId();
|
|
389
|
+
return (
|
|
390
|
+
<div className="prx-disclosure" data-open={open || undefined}>
|
|
391
|
+
<button
|
|
392
|
+
type="button"
|
|
393
|
+
className="prx-disclosure-toggle"
|
|
394
|
+
aria-expanded={open}
|
|
395
|
+
aria-controls={id}
|
|
396
|
+
onClick={() => onOpenChange(!open)}
|
|
397
|
+
>
|
|
398
|
+
<Icon name="chevron" className="prx-icon prx-disclosure-chevron" />
|
|
399
|
+
<span>{summary}</span>
|
|
400
|
+
</button>
|
|
401
|
+
{open && (
|
|
402
|
+
<div className="prx-disclosure-body" id={id}>
|
|
403
|
+
{children}
|
|
404
|
+
</div>
|
|
405
|
+
)}
|
|
406
|
+
</div>
|
|
407
|
+
);
|
|
408
|
+
},
|
|
409
|
+
};
|
|
@@ -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,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
|
+
}
|