@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.
- package/LICENSE +15 -0
- package/README.md +111 -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 +126 -0
- package/dist/adapters/tailwind.js.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts +16 -0
- package/dist/analytics/PhotonAnalyticsProvider.d.ts.map +1 -0
- package/dist/analytics/PhotonAnalyticsProvider.js +57 -0
- package/dist/analytics/PhotonAnalyticsProvider.js.map +1 -0
- package/dist/analytics/fieldInteraction.d.ts +18 -0
- package/dist/analytics/fieldInteraction.d.ts.map +1 -0
- package/dist/analytics/fieldInteraction.js +102 -0
- package/dist/analytics/fieldInteraction.js.map +1 -0
- package/dist/analytics/tracker.d.ts +17 -0
- package/dist/analytics/tracker.d.ts.map +1 -0
- package/dist/analytics/tracker.js +36 -0
- package/dist/analytics/tracker.js.map +1 -0
- package/dist/analytics/viewed.d.ts +11 -0
- package/dist/analytics/viewed.d.ts.map +1 -0
- package/dist/analytics/viewed.js +16 -0
- package/dist/analytics/viewed.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 +274 -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 +85 -0
- package/dist/components/PhotonPatient.js.map +1 -0
- package/dist/components/PhotonPrescription.d.ts +32 -0
- package/dist/components/PhotonPrescription.d.ts.map +1 -0
- package/dist/components/PhotonPrescription.js +11 -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/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/order/DraftOrderPrompt.d.ts +18 -0
- package/dist/components/order/DraftOrderPrompt.d.ts.map +1 -0
- package/dist/components/order/DraftOrderPrompt.js +26 -0
- package/dist/components/order/DraftOrderPrompt.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 +48 -0
- package/dist/components/patient/Benefits.js.map +1 -0
- package/dist/components/patient/Clinical.d.ts +56 -0
- package/dist/components/patient/Clinical.d.ts.map +1 -0
- package/dist/components/patient/Clinical.js +118 -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 +333 -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 +90 -0
- package/dist/components/patient/Summary.js.map +1 -0
- package/dist/components/patient/fields.d.ts +42 -0
- package/dist/components/patient/fields.d.ts.map +1 -0
- package/dist/components/patient/fields.js +72 -0
- package/dist/components/patient/fields.js.map +1 -0
- package/dist/components/patient/query.d.ts +37 -0
- package/dist/components/patient/query.d.ts.map +1 -0
- package/dist/components/patient/query.js +70 -0
- package/dist/components/patient/query.js.map +1 -0
- package/dist/components/prescription/PrescriptionCard.d.ts +45 -0
- package/dist/components/prescription/PrescriptionCard.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionCard.js +179 -0
- package/dist/components/prescription/PrescriptionCard.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts +15 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js +18 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DirectionsInput.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts +23 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js +42 -0
- package/dist/components/prescription/PrescriptionDetailsForm/DispenseInputs.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts +27 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js +169 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts +8 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js +12 -0
- package/dist/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.js.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts +11 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.d.ts.map +1 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js +25 -0
- package/dist/components/prescription/PrescriptionDetailsForm/TemplatePicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts +50 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js +287 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentPicker.js.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts +28 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.d.ts.map +1 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js +146 -0
- package/dist/components/prescription/TreatmentSearch/TreatmentSearch.js.map +1 -0
- package/dist/components/schemaErrors.d.ts +12 -0
- package/dist/components/schemaErrors.d.ts.map +1 -0
- package/dist/components/schemaErrors.js +24 -0
- package/dist/components/schemaErrors.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 +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/meta/version.d.ts +5 -0
- package/dist/meta/version.d.ts.map +1 -0
- package/dist/meta/version.js +5 -0
- package/dist/meta/version.js.map +1 -0
- package/dist/primitives/PhotonProvider.d.ts +60 -0
- package/dist/primitives/PhotonProvider.d.ts.map +1 -0
- package/dist/primitives/PhotonProvider.js +103 -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 +70 -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/photonContext.d.ts +3 -0
- package/dist/primitives/photonContext.d.ts.map +1 -0
- package/dist/primitives/photonContext.js +3 -0
- package/dist/primitives/photonContext.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 +288 -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/primitives/useProvidedPhoton.d.ts +8 -0
- package/dist/primitives/useProvidedPhoton.d.ts.map +1 -0
- package/dist/primitives/useProvidedPhoton.js +8 -0
- package/dist/primitives/useProvidedPhoton.js.map +1 -0
- package/dist/styles.css +653 -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 +282 -0
- package/dist/test-utils/contract.js.map +1 -0
- package/package.json +76 -4
- package/src/adapters/index.ts +1 -0
- package/src/adapters/tailwind.tsx +572 -0
- package/src/analytics/PhotonAnalyticsProvider.test.tsx +191 -0
- package/src/analytics/PhotonAnalyticsProvider.tsx +96 -0
- package/src/analytics/fieldInteraction.test.tsx +184 -0
- package/src/analytics/fieldInteraction.tsx +148 -0
- package/src/analytics/tracker.test.ts +52 -0
- package/src/analytics/tracker.ts +42 -0
- package/src/analytics/viewed.ts +27 -0
- package/src/components/ChangeList.tsx +85 -0
- package/src/components/PhotonOrder.test.tsx +256 -0
- package/src/components/PhotonOrder.tsx +508 -0
- package/src/components/PhotonPatient.tsx +188 -0
- package/src/components/PhotonPrescription.test.tsx +116 -0
- package/src/components/PhotonPrescription.tsx +45 -0
- package/src/components/ScreeningAlerts.tsx +28 -0
- package/src/components/SignedIn.tsx +144 -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/order/DraftOrderPrompt.test.tsx +80 -0
- package/src/components/order/DraftOrderPrompt.tsx +81 -0
- package/src/components/patient/Benefits.tsx +133 -0
- package/src/components/patient/Clinical.tsx +215 -0
- package/src/components/patient/IntakeForm.test.tsx +89 -0
- package/src/components/patient/IntakeForm.tsx +564 -0
- package/src/components/patient/Summary.test.tsx +106 -0
- package/src/components/patient/Summary.tsx +330 -0
- package/src/components/patient/fields.tsx +158 -0
- package/src/components/patient/query.ts +83 -0
- package/src/components/prescription/PrescriptionCard.test.tsx +85 -0
- package/src/components/prescription/PrescriptionCard.tsx +347 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.test.tsx +85 -0
- package/src/components/prescription/PrescriptionDetailsForm/DirectionsInput.tsx +41 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.test.tsx +209 -0
- package/src/components/prescription/PrescriptionDetailsForm/DispenseInputs.tsx +99 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.test.tsx +456 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsForm.tsx +238 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.test.ts +63 -0
- package/src/components/prescription/PrescriptionDetailsForm/PrescriptionDetailsSchema.ts +15 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.test.tsx +75 -0
- package/src/components/prescription/PrescriptionDetailsForm/TemplatePicker.tsx +41 -0
- package/src/components/prescription/TreatmentSearch/TreatmentPicker.tsx +375 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.test.tsx +699 -0
- package/src/components/prescription/TreatmentSearch/TreatmentSearch.tsx +220 -0
- package/src/components/schemaErrors.test.ts +49 -0
- package/src/components/schemaErrors.ts +33 -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 +21 -0
- package/src/meta/version.test.ts +10 -0
- package/src/meta/version.ts +4 -0
- package/src/primitives/PhotonProvider.tsx +168 -0
- package/src/primitives/defaults.tsx +432 -0
- package/src/primitives/icons.tsx +37 -0
- package/src/primitives/index.ts +4 -0
- package/src/primitives/photonContext.ts +4 -0
- package/src/primitives/select.ts +15 -0
- package/src/primitives/types.ts +288 -0
- package/src/primitives/useProvidedPhoton.ts +21 -0
- package/src/styles.css +653 -0
- package/src/test-utils/contract.tsx +453 -0
|
@@ -0,0 +1,572 @@
|
|
|
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, label, children }) => (
|
|
110
|
+
<section
|
|
111
|
+
aria-label={label}
|
|
112
|
+
className={cx("rounded-lg bg-white shadow-sm ring-1", "ring-slate-200", divided && "divide-y divide-slate-200")}
|
|
113
|
+
>
|
|
114
|
+
{children}
|
|
115
|
+
</section>
|
|
116
|
+
),
|
|
117
|
+
CardHeader: ({ title, description, action }) => (
|
|
118
|
+
<div className="flex items-start justify-between gap-4 px-4 py-3">
|
|
119
|
+
<div>
|
|
120
|
+
<h2 className="text-base font-semibold text-slate-900">{title}</h2>
|
|
121
|
+
{description && <p className="mt-0.5 text-sm text-slate-600">{description}</p>}
|
|
122
|
+
</div>
|
|
123
|
+
{action && <div className="shrink-0">{action}</div>}
|
|
124
|
+
</div>
|
|
125
|
+
),
|
|
126
|
+
CardBody: ({ children }) => <div className="px-4 py-4">{children}</div>,
|
|
127
|
+
CardFooter: ({ start, children }) => (
|
|
128
|
+
<div className="flex flex-wrap items-center justify-end gap-2 px-4 py-3">
|
|
129
|
+
{start && <div className="mr-auto">{start}</div>}
|
|
130
|
+
{children}
|
|
131
|
+
</div>
|
|
132
|
+
),
|
|
133
|
+
Spinner: ({ label }) => (
|
|
134
|
+
<span role="status" className="inline-flex items-center gap-2 text-sm text-slate-500">
|
|
135
|
+
<span
|
|
136
|
+
aria-hidden
|
|
137
|
+
className="size-4 animate-spin rounded-full border-2 border-slate-300 border-t-indigo-600 motion-reduce:animate-none"
|
|
138
|
+
/>
|
|
139
|
+
{label}
|
|
140
|
+
</span>
|
|
141
|
+
),
|
|
142
|
+
Button: ({
|
|
143
|
+
variant = "primary",
|
|
144
|
+
size = "md",
|
|
145
|
+
loading,
|
|
146
|
+
disabled,
|
|
147
|
+
className,
|
|
148
|
+
type = "button",
|
|
149
|
+
children,
|
|
150
|
+
icon,
|
|
151
|
+
tone,
|
|
152
|
+
...rest
|
|
153
|
+
}) => (
|
|
154
|
+
<button
|
|
155
|
+
{...rest}
|
|
156
|
+
type={type}
|
|
157
|
+
disabled={disabled || loading}
|
|
158
|
+
aria-busy={loading || undefined}
|
|
159
|
+
className={cx(
|
|
160
|
+
"inline-flex items-center justify-center gap-2 rounded-md font-semibold disabled:cursor-not-allowed disabled:opacity-50",
|
|
161
|
+
buttonVariant[variant],
|
|
162
|
+
tone === "critical" && "text-red-600 hover:bg-red-50 active:bg-red-100",
|
|
163
|
+
icon && !children ? "size-9 p-0" : buttonSize[size],
|
|
164
|
+
focus,
|
|
165
|
+
className,
|
|
166
|
+
)}
|
|
167
|
+
>
|
|
168
|
+
{loading && (
|
|
169
|
+
<span
|
|
170
|
+
className="size-3 animate-spin rounded-full border-2 border-current border-t-transparent motion-reduce:animate-none"
|
|
171
|
+
aria-hidden
|
|
172
|
+
/>
|
|
173
|
+
)}
|
|
174
|
+
{icon && !children ? (
|
|
175
|
+
<Icon name={icon} className="size-5" />
|
|
176
|
+
) : (
|
|
177
|
+
<>
|
|
178
|
+
{icon && <Icon name={icon} className="size-4 shrink-0" />}
|
|
179
|
+
{children}
|
|
180
|
+
</>
|
|
181
|
+
)}
|
|
182
|
+
</button>
|
|
183
|
+
),
|
|
184
|
+
Input: ({ label, helper, invalid, errorMessage, className, loading, onClear, clearLabel = "Clear", ...rest }) => {
|
|
185
|
+
const clearable = Boolean(onClear) && !loading && String(rest.value ?? "") !== "";
|
|
186
|
+
return (
|
|
187
|
+
<Field label={label} note={invalid && errorMessage ? errorMessage : helper} invalid={invalid}>
|
|
188
|
+
{(id, noteId) => (
|
|
189
|
+
<span className="relative block">
|
|
190
|
+
<input
|
|
191
|
+
{...rest}
|
|
192
|
+
id={id}
|
|
193
|
+
aria-invalid={invalid || undefined}
|
|
194
|
+
aria-describedby={noteId}
|
|
195
|
+
aria-busy={loading || undefined}
|
|
196
|
+
className={cx(control, invalid && "ring-red-500", (loading || clearable) && "pr-9", className)}
|
|
197
|
+
/>
|
|
198
|
+
{loading && (
|
|
199
|
+
<span
|
|
200
|
+
aria-hidden
|
|
201
|
+
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"
|
|
202
|
+
/>
|
|
203
|
+
)}
|
|
204
|
+
{clearable && (
|
|
205
|
+
<button
|
|
206
|
+
type="button"
|
|
207
|
+
aria-label={clearLabel}
|
|
208
|
+
title={clearLabel}
|
|
209
|
+
disabled={rest.disabled}
|
|
210
|
+
onClick={onClear}
|
|
211
|
+
className={cx(
|
|
212
|
+
"absolute top-1/2 right-2 grid -translate-y-1/2 place-items-center rounded-sm p-1 text-slate-400 hover:text-slate-600",
|
|
213
|
+
focus,
|
|
214
|
+
)}
|
|
215
|
+
>
|
|
216
|
+
<Icon name="close" className="size-4" />
|
|
217
|
+
</button>
|
|
218
|
+
)}
|
|
219
|
+
</span>
|
|
220
|
+
)}
|
|
221
|
+
</Field>
|
|
222
|
+
);
|
|
223
|
+
},
|
|
224
|
+
Textarea: ({ label, helper, invalid, errorMessage, className, ...rest }) => (
|
|
225
|
+
<Field label={label} note={invalid && errorMessage ? errorMessage : helper} invalid={invalid}>
|
|
226
|
+
{(id, noteId) => (
|
|
227
|
+
<textarea
|
|
228
|
+
{...rest}
|
|
229
|
+
id={id}
|
|
230
|
+
aria-invalid={invalid || undefined}
|
|
231
|
+
aria-describedby={noteId}
|
|
232
|
+
className={cx(control, "resize-y", className)}
|
|
233
|
+
/>
|
|
234
|
+
)}
|
|
235
|
+
</Field>
|
|
236
|
+
),
|
|
237
|
+
Checkbox: ({ label, checked, onChange, disabled }) => (
|
|
238
|
+
<label className="inline-flex items-center gap-2 text-sm text-slate-900">
|
|
239
|
+
<input
|
|
240
|
+
type="checkbox"
|
|
241
|
+
className="size-4 rounded border-slate-300 accent-indigo-600"
|
|
242
|
+
checked={checked}
|
|
243
|
+
disabled={disabled}
|
|
244
|
+
onChange={(e) => onChange(e.target.checked)}
|
|
245
|
+
/>
|
|
246
|
+
{label}
|
|
247
|
+
</label>
|
|
248
|
+
),
|
|
249
|
+
// Safari draws a native <select> itself and ignores the ring / padding below.
|
|
250
|
+
Select: ({ label, options, value, onChange, placeholder = "Select…", helper, disabled, invalid, errorMessage }) => (
|
|
251
|
+
<Field label={label} note={invalid && errorMessage ? errorMessage : helper} invalid={invalid}>
|
|
252
|
+
{(id, noteId) => (
|
|
253
|
+
<select
|
|
254
|
+
id={id}
|
|
255
|
+
value={value ?? ""}
|
|
256
|
+
disabled={disabled}
|
|
257
|
+
aria-invalid={invalid || undefined}
|
|
258
|
+
aria-describedby={noteId}
|
|
259
|
+
onChange={(e) => e.target.value && onChange(e.target.value as never)}
|
|
260
|
+
onKeyDown={openOnEnter}
|
|
261
|
+
className={cx(control, "pr-8")}
|
|
262
|
+
>
|
|
263
|
+
<option value="" disabled>
|
|
264
|
+
{placeholder}
|
|
265
|
+
</option>
|
|
266
|
+
{options.map((o) => (
|
|
267
|
+
<option key={o.value} value={o.value}>
|
|
268
|
+
{o.label}
|
|
269
|
+
</option>
|
|
270
|
+
))}
|
|
271
|
+
</select>
|
|
272
|
+
)}
|
|
273
|
+
</Field>
|
|
274
|
+
),
|
|
275
|
+
RadioGroup: ({ label, options, value, onChange, horizontal }) => {
|
|
276
|
+
const name = useId();
|
|
277
|
+
return (
|
|
278
|
+
<fieldset>
|
|
279
|
+
<legend className="text-sm font-medium text-slate-900">{label}</legend>
|
|
280
|
+
<div className={cx("mt-2 flex gap-4", horizontal ? "flex-row flex-wrap" : "flex-col")}>
|
|
281
|
+
{options.map((o) => (
|
|
282
|
+
<label key={o.value} className="inline-flex items-center gap-2 text-sm text-slate-900">
|
|
283
|
+
<input
|
|
284
|
+
type="radio"
|
|
285
|
+
name={name}
|
|
286
|
+
className="size-4 accent-indigo-600"
|
|
287
|
+
checked={value === o.value}
|
|
288
|
+
onChange={() => onChange(o.value)}
|
|
289
|
+
/>
|
|
290
|
+
{o.label}
|
|
291
|
+
</label>
|
|
292
|
+
))}
|
|
293
|
+
</div>
|
|
294
|
+
</fieldset>
|
|
295
|
+
);
|
|
296
|
+
},
|
|
297
|
+
// Rows like OptionList's: separate cards; keyboard focus reads as its selected row (inset indigo ring).
|
|
298
|
+
ChoiceList: ({ label, choices, onChoose, disabled, pendingKey, action, activeKey, id }) => {
|
|
299
|
+
// A field that keeps the cursor drives this list: its rows are options it points at, not buttons.
|
|
300
|
+
const inField = activeKey !== undefined;
|
|
301
|
+
const base = "group flex w-full items-center gap-3 rounded-md px-4 py-3 text-left";
|
|
302
|
+
const choiceRest = "bg-white ring-1 ring-slate-200 ring-inset hover:bg-slate-50 disabled:opacity-50";
|
|
303
|
+
const actionRest = "text-sm font-medium text-indigo-600 hover:bg-slate-50 disabled:opacity-50";
|
|
304
|
+
const lit = "bg-indigo-50 ring-2 ring-indigo-600 ring-inset";
|
|
305
|
+
const focus =
|
|
306
|
+
"focus-visible:bg-indigo-50 focus-visible:ring-2 focus-visible:ring-indigo-600 focus-visible:ring-inset focus-visible:outline-none";
|
|
307
|
+
const row = (key: string, active: boolean, onPick: () => void, body: ReactNode) => {
|
|
308
|
+
const rest = key === CHOICE_ACTION ? actionRest : choiceRest;
|
|
309
|
+
return inField ? (
|
|
310
|
+
<li
|
|
311
|
+
key={key}
|
|
312
|
+
id={id ? `${id}-${key}` : undefined}
|
|
313
|
+
role="option"
|
|
314
|
+
aria-selected={active}
|
|
315
|
+
aria-busy={key === pendingKey || undefined}
|
|
316
|
+
className={`${base} ${rest} cursor-pointer ${active ? lit : ""}`}
|
|
317
|
+
onClick={disabled ? undefined : onPick}
|
|
318
|
+
>
|
|
319
|
+
{body}
|
|
320
|
+
</li>
|
|
321
|
+
) : (
|
|
322
|
+
<li key={key}>
|
|
323
|
+
<button
|
|
324
|
+
type="button"
|
|
325
|
+
disabled={disabled}
|
|
326
|
+
aria-busy={key === pendingKey || undefined}
|
|
327
|
+
onClick={onPick}
|
|
328
|
+
className={`${base} ${rest} ${focus} aria-busy:bg-indigo-50 aria-busy:ring-2 aria-busy:ring-indigo-600`}
|
|
329
|
+
>
|
|
330
|
+
{body}
|
|
331
|
+
</button>
|
|
332
|
+
</li>
|
|
333
|
+
);
|
|
334
|
+
};
|
|
335
|
+
const glyph = (active: boolean) => (
|
|
336
|
+
<Icon
|
|
337
|
+
name="return"
|
|
338
|
+
className={`size-4 shrink-0 text-indigo-600 ${active ? "visible" : "invisible group-focus-visible:visible"}`}
|
|
339
|
+
/>
|
|
340
|
+
);
|
|
341
|
+
return (
|
|
342
|
+
<ul aria-label={label} role={inField ? "listbox" : undefined} className="flex flex-col gap-2">
|
|
343
|
+
{choices.map((c) =>
|
|
344
|
+
row(
|
|
345
|
+
c.key,
|
|
346
|
+
c.key === activeKey,
|
|
347
|
+
() => onChoose(c.key),
|
|
348
|
+
<>
|
|
349
|
+
<span className="flex min-w-0 flex-1 flex-col">
|
|
350
|
+
<span className="flex flex-wrap items-baseline gap-x-2">
|
|
351
|
+
<span className="text-sm text-slate-900">{c.label}</span>
|
|
352
|
+
{c.meta && <span className="text-xs text-slate-500">{c.meta}</span>}
|
|
353
|
+
</span>
|
|
354
|
+
{c.description && <span className="text-xs text-slate-500">{c.description}</span>}
|
|
355
|
+
</span>
|
|
356
|
+
{glyph(c.key === activeKey)}
|
|
357
|
+
</>,
|
|
358
|
+
),
|
|
359
|
+
)}
|
|
360
|
+
{action &&
|
|
361
|
+
row(
|
|
362
|
+
CHOICE_ACTION,
|
|
363
|
+
activeKey === CHOICE_ACTION,
|
|
364
|
+
action.onChoose,
|
|
365
|
+
<>
|
|
366
|
+
{action.icon && <Icon name={action.icon} className="size-4 shrink-0" />}
|
|
367
|
+
<span className="min-w-0 flex-1">{action.label}</span>
|
|
368
|
+
{glyph(activeKey === CHOICE_ACTION)}
|
|
369
|
+
</>,
|
|
370
|
+
)}
|
|
371
|
+
</ul>
|
|
372
|
+
);
|
|
373
|
+
},
|
|
374
|
+
OptionList: function TailwindOptionList({
|
|
375
|
+
label,
|
|
376
|
+
options,
|
|
377
|
+
activeKey,
|
|
378
|
+
activeSelected,
|
|
379
|
+
onSelect,
|
|
380
|
+
onKeyDown,
|
|
381
|
+
disabled,
|
|
382
|
+
children,
|
|
383
|
+
}) {
|
|
384
|
+
return (
|
|
385
|
+
<div tabIndex={0} aria-label={label} onKeyDown={onKeyDown} className="outline-none">
|
|
386
|
+
<ul aria-label={label} className="flex flex-col gap-2">
|
|
387
|
+
{options.map((o) => {
|
|
388
|
+
const active = o.key === activeKey;
|
|
389
|
+
// Top right: a spinner while its choice is saved, else (a row that opens) the chevron.
|
|
390
|
+
const trailing = o.loading ? (
|
|
391
|
+
<span
|
|
392
|
+
aria-hidden
|
|
393
|
+
className="ml-auto size-4 shrink-0 animate-spin rounded-full border-2 border-slate-300 border-t-indigo-600 motion-reduce:animate-none"
|
|
394
|
+
/>
|
|
395
|
+
) : active || o.direct ? null : (
|
|
396
|
+
<Icon name="chevron" className="ml-auto size-4 shrink-0 self-center text-slate-400" />
|
|
397
|
+
);
|
|
398
|
+
const row = (
|
|
399
|
+
<span className="flex w-full items-center gap-2.5">
|
|
400
|
+
<span className="flex min-w-0 flex-col">
|
|
401
|
+
<span className={cx("text-sm text-slate-900", active && "font-semibold")}>{o.label}</span>
|
|
402
|
+
{o.description && <span className="text-xs text-slate-500">{o.description}</span>}
|
|
403
|
+
</span>
|
|
404
|
+
{trailing}
|
|
405
|
+
</span>
|
|
406
|
+
);
|
|
407
|
+
return (
|
|
408
|
+
<li key={o.key}>
|
|
409
|
+
{active && !o.direct ? (
|
|
410
|
+
<div
|
|
411
|
+
aria-current="true"
|
|
412
|
+
aria-busy={o.loading || undefined}
|
|
413
|
+
className={cx(
|
|
414
|
+
"flex flex-col gap-3 rounded-md px-4 pt-3.5 pb-4",
|
|
415
|
+
activeSelected
|
|
416
|
+
? "bg-indigo-50 ring-2 ring-indigo-600 ring-inset"
|
|
417
|
+
: "bg-white ring-1 ring-slate-200",
|
|
418
|
+
)}
|
|
419
|
+
>
|
|
420
|
+
<button
|
|
421
|
+
type="button"
|
|
422
|
+
aria-expanded="true"
|
|
423
|
+
aria-label={o.ariaLabel}
|
|
424
|
+
disabled={disabled}
|
|
425
|
+
onClick={() => onSelect(o.key)}
|
|
426
|
+
className={cx("flex w-full rounded-sm text-left", focus)}
|
|
427
|
+
>
|
|
428
|
+
{row}
|
|
429
|
+
</button>
|
|
430
|
+
{children}
|
|
431
|
+
</div>
|
|
432
|
+
) : (
|
|
433
|
+
<button
|
|
434
|
+
type="button"
|
|
435
|
+
disabled={disabled}
|
|
436
|
+
aria-label={o.ariaLabel}
|
|
437
|
+
aria-current={active || undefined}
|
|
438
|
+
aria-busy={o.loading || undefined}
|
|
439
|
+
onClick={() => onSelect(o.key)}
|
|
440
|
+
className={cx(
|
|
441
|
+
"flex w-full rounded-md px-4 py-3 text-left hover:bg-slate-50 disabled:opacity-50",
|
|
442
|
+
active && activeSelected
|
|
443
|
+
? "bg-indigo-50 ring-2 ring-indigo-600 ring-inset"
|
|
444
|
+
: "bg-white ring-1 ring-slate-200",
|
|
445
|
+
focus,
|
|
446
|
+
)}
|
|
447
|
+
>
|
|
448
|
+
{row}
|
|
449
|
+
</button>
|
|
450
|
+
)}
|
|
451
|
+
</li>
|
|
452
|
+
);
|
|
453
|
+
})}
|
|
454
|
+
</ul>
|
|
455
|
+
</div>
|
|
456
|
+
);
|
|
457
|
+
},
|
|
458
|
+
ActionBar: ({ children }) => <div className="flex items-center justify-end gap-4">{children}</div>,
|
|
459
|
+
// In a narrow container (a phone, a dialog, a side panel) the chips share the row evenly, for thumbs.
|
|
460
|
+
// Chips in a grid of equal columns: every chip the same width, a partial last row too. How many across goes by
|
|
461
|
+
// the longest label (and its detail): short 3 (4 on a wider card), medium 2, longer 1 (2).
|
|
462
|
+
ToggleGroup: function TailwindToggleGroup({ label, options, value, onChange, disabled }) {
|
|
463
|
+
const id = useId();
|
|
464
|
+
const longest = Math.max(0, ...options.map((o) => o.label.length + (o.detail ? o.detail.length + 1 : 0)));
|
|
465
|
+
const columns =
|
|
466
|
+
longest <= 15 ? "grid-cols-3 @md:grid-cols-4" : longest <= 24 ? "grid-cols-2" : "grid-cols-1 @md:grid-cols-2";
|
|
467
|
+
return (
|
|
468
|
+
<div className="@container flex flex-col gap-2">
|
|
469
|
+
<div id={id} className="text-xs font-semibold text-slate-700">
|
|
470
|
+
{label}
|
|
471
|
+
</div>
|
|
472
|
+
<div role="group" aria-labelledby={id} className={cx("grid gap-2", columns)}>
|
|
473
|
+
{options.map((o) => {
|
|
474
|
+
const selected = o.value === value;
|
|
475
|
+
return (
|
|
476
|
+
<button
|
|
477
|
+
key={o.value}
|
|
478
|
+
type="button"
|
|
479
|
+
aria-pressed={selected}
|
|
480
|
+
aria-label={o.ariaLabel}
|
|
481
|
+
data-muted={o.muted || undefined}
|
|
482
|
+
disabled={disabled}
|
|
483
|
+
onClick={() => onChange(o.value)}
|
|
484
|
+
className={cx(
|
|
485
|
+
"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",
|
|
486
|
+
selected
|
|
487
|
+
? "bg-indigo-600 font-semibold text-white hover:bg-indigo-500"
|
|
488
|
+
: "bg-white font-medium text-slate-900 ring-1 ring-slate-300 hover:bg-slate-50",
|
|
489
|
+
o.muted && !selected && "text-slate-400 ring-slate-200",
|
|
490
|
+
focus,
|
|
491
|
+
)}
|
|
492
|
+
>
|
|
493
|
+
{o.label}
|
|
494
|
+
{o.detail && (
|
|
495
|
+
<span className={cx("text-xs font-normal", selected ? "text-indigo-100" : "text-slate-500")}>
|
|
496
|
+
{o.detail}
|
|
497
|
+
</span>
|
|
498
|
+
)}
|
|
499
|
+
</button>
|
|
500
|
+
);
|
|
501
|
+
})}
|
|
502
|
+
</div>
|
|
503
|
+
</div>
|
|
504
|
+
);
|
|
505
|
+
},
|
|
506
|
+
Alert: ({ tone = "info", title, description, onDismiss }) => (
|
|
507
|
+
<div
|
|
508
|
+
role={tone === "warning" || tone === "critical" ? "alert" : "status"}
|
|
509
|
+
className={cx("flex items-start justify-between gap-3 rounded-md border px-4 py-3 text-sm", alertTone[tone])}
|
|
510
|
+
>
|
|
511
|
+
<div>
|
|
512
|
+
<p className="font-semibold">{title}</p>
|
|
513
|
+
{description && <div className="mt-1">{description}</div>}
|
|
514
|
+
</div>
|
|
515
|
+
{onDismiss && (
|
|
516
|
+
<button
|
|
517
|
+
type="button"
|
|
518
|
+
onClick={onDismiss}
|
|
519
|
+
aria-label="Dismiss"
|
|
520
|
+
className={cx("rounded px-1 opacity-70 hover:opacity-100", focus)}
|
|
521
|
+
>
|
|
522
|
+
<Icon name="close" className="size-3.5" />
|
|
523
|
+
</button>
|
|
524
|
+
)}
|
|
525
|
+
</div>
|
|
526
|
+
),
|
|
527
|
+
Badge: ({ tone = "neutral", children, icon, onRemove, removeLabel = "Remove" }) => (
|
|
528
|
+
<span
|
|
529
|
+
className={cx(
|
|
530
|
+
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium ring-1 ring-inset",
|
|
531
|
+
badgeTone[tone],
|
|
532
|
+
)}
|
|
533
|
+
>
|
|
534
|
+
{icon && <Icon name={icon} className="size-3" />}
|
|
535
|
+
{children}
|
|
536
|
+
{onRemove && (
|
|
537
|
+
<button
|
|
538
|
+
type="button"
|
|
539
|
+
aria-label={removeLabel}
|
|
540
|
+
onClick={onRemove}
|
|
541
|
+
className={cx("-mr-1 rounded-full px-1 opacity-60 hover:opacity-100", focus)}
|
|
542
|
+
>
|
|
543
|
+
<Icon name="close" className="size-3.5" />
|
|
544
|
+
</button>
|
|
545
|
+
)}
|
|
546
|
+
</span>
|
|
547
|
+
),
|
|
548
|
+
Disclosure: ({ summary, open, onOpenChange, children }) => {
|
|
549
|
+
const id = useId();
|
|
550
|
+
return (
|
|
551
|
+
<div className="flex flex-col gap-3">
|
|
552
|
+
<button
|
|
553
|
+
type="button"
|
|
554
|
+
aria-expanded={open}
|
|
555
|
+
aria-controls={id}
|
|
556
|
+
onClick={() => onOpenChange(!open)}
|
|
557
|
+
className={cx(
|
|
558
|
+
"flex w-full items-center gap-1.5 rounded-md text-left text-sm text-slate-600 hover:text-slate-900",
|
|
559
|
+
focus,
|
|
560
|
+
)}
|
|
561
|
+
>
|
|
562
|
+
<Icon
|
|
563
|
+
name="chevron"
|
|
564
|
+
className={cx("size-4 shrink-0 transition-transform motion-reduce:transition-none", open && "rotate-90")}
|
|
565
|
+
/>
|
|
566
|
+
<span>{summary}</span>
|
|
567
|
+
</button>
|
|
568
|
+
{open && <div id={id}>{children}</div>}
|
|
569
|
+
</div>
|
|
570
|
+
);
|
|
571
|
+
},
|
|
572
|
+
};
|