@va-scheduling/ui 0.1.1 → 0.2.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/README.md +96 -0
- package/dist/cjs/index.css +1 -0
- package/dist/cjs/index.js +106 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/index.d.ts +2 -0
- package/dist/cjs/types/components/spl-dialog/SplAlertDialog.d.ts +27 -0
- package/dist/cjs/types/components/spl-dialog/SplDeleteAlertDialog.d.ts +15 -0
- package/dist/cjs/types/components/spl-dialog/SplDialog.d.ts +27 -0
- package/dist/cjs/types/components/spl-dialog/SplDialogFooter.d.ts +34 -0
- package/dist/cjs/types/components/spl-dialog/SplWarningAlertDialog.d.ts +12 -0
- package/dist/cjs/types/components/spl-dialog/index.d.ts +10 -0
- package/dist/cjs/types/components/spl-dialog/splDialogSize.d.ts +8 -0
- package/dist/esm/index.css +1 -0
- package/dist/esm/index.js +104 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/index.d.ts +2 -0
- package/dist/esm/types/components/spl-dialog/SplAlertDialog.d.ts +27 -0
- package/dist/esm/types/components/spl-dialog/SplDeleteAlertDialog.d.ts +15 -0
- package/dist/esm/types/components/spl-dialog/SplDialog.d.ts +27 -0
- package/dist/esm/types/components/spl-dialog/SplDialogFooter.d.ts +34 -0
- package/dist/esm/types/components/spl-dialog/SplWarningAlertDialog.d.ts +12 -0
- package/dist/esm/types/components/spl-dialog/index.d.ts +10 -0
- package/dist/esm/types/components/spl-dialog/splDialogSize.d.ts +8 -0
- package/dist/index.d.ts +105 -2
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -112,6 +112,102 @@ applyInitialSplTheme(() => readMyStoredPreference()); // returns 'light' | 'dark
|
|
|
112
112
|
|
|
113
113
|
Other exports: `applySplTheme`, `resolveSplTheme`, `getSystemTheme`, `isSplThemePreference`, and the `SplTheme` / `SplThemePreference` types.
|
|
114
114
|
|
|
115
|
+
## Dialogs
|
|
116
|
+
|
|
117
|
+
Built on Radix Themes dialogs, so they inherit its sizing, radius and shadow. They must render inside `SplThemeProvider`'s Radix `Theme` (or create their own root) and style themselves with `--spl-*` tokens. Their CSS ships as `index.css` beside each JS entry and loads with the package entry, so there are no runtime `<style>` tags (safe under a strict CSP and SSR).
|
|
118
|
+
|
|
119
|
+
| Component | Use for |
|
|
120
|
+
| --- | --- |
|
|
121
|
+
| `SplDialog` | Content and form dialogs. Has an X button, a Cancel/primary footer (or a close-only footer), and closes on Escape or outside click. |
|
|
122
|
+
| `SplAlertDialog` | Confirmations that must be answered. No X, no outside-click close, focuses Cancel. Optional `status` icon. |
|
|
123
|
+
| `SplDeleteAlertDialog` | `SplAlertDialog` preset: red trash icon, destructive button, "Please confirm deletion of: **itemName**". |
|
|
124
|
+
| `SplWarningAlertDialog` | `SplAlertDialog` preset: amber warning icon, standard Continue button. |
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
<SplDeleteAlertDialog
|
|
128
|
+
id="delete-queue"
|
|
129
|
+
title="Delete Queue"
|
|
130
|
+
itemName={queueName}
|
|
131
|
+
isOpen={isOpen}
|
|
132
|
+
onOpenChange={setIsOpen}
|
|
133
|
+
onPrimaryAction={deleteQueue} // a returned promise shows the loading state
|
|
134
|
+
/>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Footer buttons get ids `{id}-primary-btn`, `-secondary-btn` and `-tertiary-btn`, and the X is `{id}-close-btn`.
|
|
138
|
+
|
|
139
|
+
### Content dialog (`SplDialog`)
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
import { SplDialog } from "@va-scheduling/ui";
|
|
143
|
+
|
|
144
|
+
<SplDialog
|
|
145
|
+
id="edit-queue"
|
|
146
|
+
title="Edit Queue"
|
|
147
|
+
description="Change the queue name." // optional, announced by screen readers
|
|
148
|
+
isOpen={isOpen}
|
|
149
|
+
onOpenChange={setIsOpen}
|
|
150
|
+
primaryLabel="Save"
|
|
151
|
+
primaryLoadingLabel="Saving..."
|
|
152
|
+
onPrimaryAction={saveQueue}
|
|
153
|
+
>
|
|
154
|
+
<QueueForm />
|
|
155
|
+
</SplDialog>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
- **Close-only footer:** pass `secondaryLabel="Close"` and no `primaryLabel`.
|
|
159
|
+
- **Custom footer:** pass `footer={<MyButtons />}` to replace the built-in one (for example, when a form owns its submit button).
|
|
160
|
+
- **No dismissal:** `isDismissDisabled` blocks Escape and outside click and hides the X. Cancel still closes the dialog; use `isSecondaryDisabled` to prevent that while saving.
|
|
161
|
+
- **X button:** `hasCloseButton={false}` hides it; Escape and outside click still close the dialog.
|
|
162
|
+
- **Width override:** `contentClassName` adds a class to the content panel.
|
|
163
|
+
|
|
164
|
+
### Confirmation dialogs
|
|
165
|
+
|
|
166
|
+
`SplAlertDialog` requires `description` and `primaryLabel`. It cannot be dismissed by outside click, has no X, and focuses Cancel first.
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
<SplAlertDialog
|
|
170
|
+
id="discard-changes"
|
|
171
|
+
title="Discard changes?"
|
|
172
|
+
description="Your unsaved changes will be lost."
|
|
173
|
+
status="warning" // optional: 'warning' | 'destructive'
|
|
174
|
+
isOpen={isOpen}
|
|
175
|
+
onOpenChange={setIsOpen}
|
|
176
|
+
primaryLabel="Discard"
|
|
177
|
+
primaryVariant="destructive"
|
|
178
|
+
onPrimaryAction={discard}
|
|
179
|
+
/>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Extra content (for example an error message) can be passed as `children` and renders below the description.
|
|
183
|
+
|
|
184
|
+
The presets fill in sensible defaults:
|
|
185
|
+
|
|
186
|
+
| Preset | Required | Defaults |
|
|
187
|
+
| --- | --- | --- |
|
|
188
|
+
| `SplDeleteAlertDialog` | `itemName` | `primaryLabel="Delete"`, `primaryLoadingLabel="Deleting..."`, `secondaryLabel="Cancel"`; the item name element has id `{id}-item-name` (override with `itemNameId`) |
|
|
189
|
+
| `SplWarningAlertDialog` | `description` | `primaryLabel="Continue"`, `secondaryLabel="Cancel"` |
|
|
190
|
+
|
|
191
|
+
### Shared props
|
|
192
|
+
|
|
193
|
+
| Prop | Description |
|
|
194
|
+
| --- | --- |
|
|
195
|
+
| `id` | Required. Set on the dialog content; footer button ids derive from it. |
|
|
196
|
+
| `title` | Required. |
|
|
197
|
+
| `isOpen`, `onOpenChange` | Required. You own the open state. |
|
|
198
|
+
| `primaryLabel`, `primaryLoadingLabel` | Accept button text, and its text while loading. |
|
|
199
|
+
| `secondaryLabel` | Cancel/close button text. Defaults to "Cancel" when a primary button is shown. |
|
|
200
|
+
| `tertiaryLabel`, `onTertiaryAction` | Optional extra button between secondary and primary. |
|
|
201
|
+
| `onPrimaryAction` | Called on accept. A returned promise shows the loading state until it settles; rejections are swallowed, so handle errors yourself. |
|
|
202
|
+
| `onSecondaryAction` | Called on cancel. The dialog also closes through `onOpenChange(false)`. |
|
|
203
|
+
| `isPrimaryLoading` | Force the loading state when it is driven by a store or parent. |
|
|
204
|
+
| `isPrimaryDisabled`, `isSecondaryDisabled`, `isTertiaryDisabled` | Disable the respective button. |
|
|
205
|
+
| `primaryVariant` | `'default'` or `'destructive'`. |
|
|
206
|
+
| `size` | `'1'`–`'4'` Radix padding preset. Default `'3'`. |
|
|
207
|
+
| `maxWidth` | Any CSS length. Default `544px` (`450px` for alert dialogs). |
|
|
208
|
+
|
|
209
|
+
Accepting does not close a dialog automatically. Close it from your `onPrimaryAction` (or in response to it succeeding) by setting `isOpen` to `false`.
|
|
210
|
+
|
|
115
211
|
## Testing (Jest)
|
|
116
212
|
|
|
117
213
|
Jest can't process CSS imports. Map them to a stub:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.splDialog-module_dialog__content__t-Zwr:focus{outline:none}.splDialog-module_dialog__content__t-Zwr.splDialog-module_dialog__content__t-Zwr{font-family:var(--default-font-family);font-size:var(--font-size-2);font-weight:var(--font-weight-regular);line-height:var(--line-height-2)}.splDialog-module_dialog__title__hQwUq.splDialog-module_dialog__title__hQwUq{font-family:var(--default-font-family);font-size:var(--font-size-5);font-weight:var(--font-weight-bold);line-height:var(--heading-line-height-5);margin:0 0 var(--space-4)}.splDialog-module_dialog__description__akkml.splDialog-module_dialog__description__akkml{font-size:var(--font-size-2);line-height:var(--line-height-2);margin:0 0 var(--space-1)}.splDialog-module_dialog__header__4evfq .splDialog-module_dialog__title__hQwUq.splDialog-module_dialog__title__hQwUq{margin:0}.splDialog-module_dialog__header__4evfq{align-items:center;display:flex;gap:12px;margin-bottom:var(--space-3)}.splDialog-module_dialog__statusIcon__xY8Y4{display:inline-flex;margin:0 -2px;position:relative;top:-2px}.splDialog-module_dialog__statusIcon__xY8Y4 svg{height:20px;width:20px}.splDialog-module_dialog__statusIcon--destructive__gZagF{color:var(--spl-colors-error)}.splDialog-module_dialog__statusIcon--warning__53s2a{color:var(--spl-colors-warning)}.splDialog-module_dialog__body__AwXEL{margin-bottom:1rem}.splDialog-module_dialog__footer__nOkmx{display:flex;gap:.5rem;justify-content:flex-end;margin-top:1.5rem}.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT{border-radius:100%;box-sizing:border-box;height:32px;margin:0;padding:0;position:absolute;right:8px;top:8px;width:32px}.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT svg{height:20px;width:20px}.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT,.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT:active,.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT:focus,.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT:hover{background-color:transparent;color:var(--spl-colors-text-default)}.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT:active,.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT:hover{background-color:var(--spl-colors-bg-secondary)}.splDialog-module_button__8fRnT.splDialog-module_button__8fRnT{align-items:center;border:none;border-radius:var(--radius-2);box-sizing:border-box;cursor:pointer;display:inline-flex;font-family:var(--default-font-family);font-size:var(--font-size-2);font-weight:var(--font-weight-medium);gap:var(--space-2);height:var(--space-6);justify-content:center;line-height:var(--line-height-2);padding:0 var(--space-3)}.splDialog-module_button--primary__n3DCG.splDialog-module_button--primary__n3DCG,.splDialog-module_button--primary__n3DCG.splDialog-module_button--primary__n3DCG:focus{background-color:var(--spl-colors-button-bg-primary);color:var(--spl-colors-button-text-primary)}.splDialog-module_button--primary__n3DCG.splDialog-module_button--primary__n3DCG:active,.splDialog-module_button--primary__n3DCG.splDialog-module_button--primary__n3DCG:hover{background-color:var(--spl-colors-button-bg-primary-hover-pressed);color:var(--spl-colors-button-text-primary-hover-pressed)}.splDialog-module_button--destructive__Ig1Az.splDialog-module_button--destructive__Ig1Az,.splDialog-module_button--destructive__Ig1Az.splDialog-module_button--destructive__Ig1Az:active,.splDialog-module_button--destructive__Ig1Az.splDialog-module_button--destructive__Ig1Az:focus,.splDialog-module_button--destructive__Ig1Az.splDialog-module_button--destructive__Ig1Az:hover{background-color:var(--spl-colors-error);color:var(--spl-colors-base-white)}.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3,.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:focus{background-color:var(--spl-colors-button-bg-secondary);box-shadow:inset 0 0 0 1px var(--spl-colors-button-border-secondary);color:var(--spl-colors-button-text-secondary)}.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:active,.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:hover{background-color:var(--spl-colors-button-bg-secondary-hover-pressed);box-shadow:inset 0 0 0 1px var(--spl-colors-button-border-secondary);color:var(--spl-colors-button-text-secondary)}.splDialog-module_button__8fRnT.splDialog-module_button__8fRnT:disabled,.splDialog-module_button__8fRnT.splDialog-module_button__8fRnT:disabled:active,.splDialog-module_button__8fRnT.splDialog-module_button__8fRnT:disabled:focus,.splDialog-module_button__8fRnT.splDialog-module_button__8fRnT:disabled:hover{background-color:var(--spl-colors-button-bg-primary-disabled);box-shadow:none;color:var(--spl-colors-button-text-primary-disabled);cursor:not-allowed}.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:disabled,.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:disabled:active,.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:disabled:focus,.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:disabled:hover{background-color:var(--spl-colors-button-bg-secondary-disabled);box-shadow:inset 0 0 0 1px var(--spl-colors-button-border-secondary-disabled);color:var(--spl-colors-button-text-secondary-disabled)}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,9 +1,110 @@
|
|
|
1
|
+
require("./index.css");
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
require('@radix-ui/themes/styles.css');
|
|
4
5
|
require('@va-scheduling/design-tokens/css');
|
|
5
|
-
var
|
|
6
|
+
var reactIcons = require('@radix-ui/react-icons');
|
|
6
7
|
var themes = require('@radix-ui/themes');
|
|
8
|
+
var React = require('react');
|
|
9
|
+
|
|
10
|
+
var styles = {"dialog__content":"splDialog-module_dialog__content__t-Zwr","dialog__title":"splDialog-module_dialog__title__hQwUq","dialog__description":"splDialog-module_dialog__description__akkml","dialog__header":"splDialog-module_dialog__header__4evfq","dialog__statusIcon":"splDialog-module_dialog__statusIcon__xY8Y4","dialog__statusIcon--destructive":"splDialog-module_dialog__statusIcon--destructive__gZagF","dialog__statusIcon--warning":"splDialog-module_dialog__statusIcon--warning__53s2a","dialog__body":"splDialog-module_dialog__body__AwXEL","dialog__footer":"splDialog-module_dialog__footer__nOkmx","dialog__close":"splDialog-module_dialog__close__RyLWT","button":"splDialog-module_button__8fRnT","button--primary":"splDialog-module_button--primary__n3DCG","button--destructive":"splDialog-module_button--destructive__Ig1Az","button--secondary":"splDialog-module_button--secondary__heKg3"};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Footer buttons shared by SplDialog and SplAlertDialog.
|
|
14
|
+
* Button ids are `{dialogId}-secondary-btn`, `-tertiary-btn` and `-primary-btn`.
|
|
15
|
+
*/
|
|
16
|
+
const SplDialogFooter = ({ dialogId, secondaryLabel, primaryLabel, primaryLoadingLabel, isPrimaryLoading = false, onPrimaryAction, onSecondaryAction, isPrimaryDisabled = false, isSecondaryDisabled = false, primaryVariant = 'default', tertiaryLabel, onTertiaryAction, isTertiaryDisabled = false, wrapSecondary = (button) => button, }) => {
|
|
17
|
+
const [isPending, setIsPending] = React.useState(false);
|
|
18
|
+
const isMounted = React.useRef(true);
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
isMounted.current = true;
|
|
21
|
+
return () => { isMounted.current = false; };
|
|
22
|
+
}, []);
|
|
23
|
+
// Cancel is the default secondary label next to a primary button; a close-only footer must opt in via secondaryLabel.
|
|
24
|
+
const secondaryText = secondaryLabel ?? (primaryLabel ? 'Cancel' : undefined);
|
|
25
|
+
if (!primaryLabel && !secondaryText)
|
|
26
|
+
return null;
|
|
27
|
+
const isLoading = isPending || isPrimaryLoading;
|
|
28
|
+
const handlePrimary = async () => {
|
|
29
|
+
setIsPending(true);
|
|
30
|
+
try {
|
|
31
|
+
await onPrimaryAction?.();
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// Callers own error handling (e.g. the error store); a rejection only needs to end the loading state.
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
if (isMounted.current)
|
|
38
|
+
setIsPending(false);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const secondaryButton = (React.createElement(themes.Button, { type: "button", variant: "outline", className: `${styles.button} ${styles['button--secondary']}`, id: `${dialogId}-secondary-btn`, disabled: isLoading || isSecondaryDisabled, onClick: onSecondaryAction }, secondaryText));
|
|
42
|
+
return (React.createElement("div", { className: styles.dialog__footer },
|
|
43
|
+
secondaryText && wrapSecondary(secondaryButton),
|
|
44
|
+
tertiaryLabel && onTertiaryAction && (React.createElement(themes.Button, { type: "button", variant: "outline", className: `${styles.button} ${styles['button--secondary']}`, id: `${dialogId}-tertiary-btn`, disabled: isLoading || isTertiaryDisabled, onClick: () => void onTertiaryAction() }, tertiaryLabel)),
|
|
45
|
+
primaryLabel && (React.createElement(themes.Button, { type: "button", id: `${dialogId}-primary-btn`, className: `${styles.button} ${primaryVariant === 'destructive' ? styles['button--destructive'] : styles['button--primary']}`, ...(primaryVariant === 'destructive' ? { color: 'red' } : {}), disabled: isLoading || isPrimaryDisabled, "aria-busy": isLoading, onClick: () => void handlePrimary() },
|
|
46
|
+
isLoading && React.createElement(themes.Spinner, { size: "1" }),
|
|
47
|
+
isLoading && primaryLoadingLabel ? primaryLoadingLabel : primaryLabel))));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* General purpose modal built on Radix Dialog for content and form dialogs.
|
|
52
|
+
* Use SplAlertDialog instead for confirmations that must be answered.
|
|
53
|
+
*/
|
|
54
|
+
const SplDialog = ({ id, title, description, isOpen, onOpenChange, children, footer, isDismissDisabled = false, hasCloseButton = true, contentClassName, size = '3', maxWidth = '544px', onSecondaryAction, ...actions }) => {
|
|
55
|
+
const preventIfDisabled = (event) => {
|
|
56
|
+
if (isDismissDisabled)
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
};
|
|
59
|
+
return (React.createElement(themes.Dialog.Root, { open: isOpen, onOpenChange: onOpenChange },
|
|
60
|
+
React.createElement(themes.Dialog.Content, { id: id, size: size, maxWidth: maxWidth, className: [styles.dialog__content, contentClassName].filter(Boolean).join(' '), onEscapeKeyDown: preventIfDisabled, onInteractOutside: preventIfDisabled, ...(description ? {} : { 'aria-describedby': undefined }) },
|
|
61
|
+
React.createElement(themes.Dialog.Title, { className: styles.dialog__title }, title),
|
|
62
|
+
!isDismissDisabled && hasCloseButton && (React.createElement(themes.Dialog.Close, null,
|
|
63
|
+
React.createElement(themes.IconButton, { type: "button", id: `${id}-close-btn`, variant: "ghost", color: "gray", className: styles.dialog__close, "aria-label": "Close" },
|
|
64
|
+
React.createElement(reactIcons.Cross2Icon, { "aria-hidden": "true" })))),
|
|
65
|
+
description && (React.createElement(themes.Dialog.Description, { className: styles.dialog__description }, description)),
|
|
66
|
+
React.createElement("div", { className: styles.dialog__body }, children),
|
|
67
|
+
footer ?? (React.createElement(SplDialogFooter, { dialogId: id,
|
|
68
|
+
// Cancel always closes the dialog, even when dismissal is disabled; onSecondaryAction is an extra hook, and actions can't override this handler.
|
|
69
|
+
onSecondaryAction: () => {
|
|
70
|
+
onSecondaryAction?.();
|
|
71
|
+
onOpenChange(false);
|
|
72
|
+
}, ...actions })))));
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const statusIconClass = {
|
|
76
|
+
destructive: styles['dialog__statusIcon--destructive'],
|
|
77
|
+
warning: styles['dialog__statusIcon--warning'],
|
|
78
|
+
};
|
|
79
|
+
const wrapInCancel = (button) => React.createElement(themes.AlertDialog.Cancel, null, button);
|
|
80
|
+
/**
|
|
81
|
+
* Confirmation dialog built on Radix AlertDialog, for interruptions that need an explicit answer
|
|
82
|
+
* (delete confirmations, unsaved changes, etc.). Unlike SplDialog it cannot be dismissed by clicking
|
|
83
|
+
* outside, has no X button, and focuses Cancel first so the safe choice is the default.
|
|
84
|
+
* Cancel closes it through `onOpenChange`. It does not auto-close on accept; the caller closes it
|
|
85
|
+
* through `isOpen` once the action succeeds.
|
|
86
|
+
*/
|
|
87
|
+
const SplAlertDialog = ({ id, title, description, isOpen, onOpenChange, children, status, size = '3', maxWidth = '450px', ...actions }) => (React.createElement(themes.AlertDialog.Root, { open: isOpen, onOpenChange: onOpenChange },
|
|
88
|
+
React.createElement(themes.AlertDialog.Content, { id: id, size: size, maxWidth: maxWidth, className: styles.dialog__content },
|
|
89
|
+
React.createElement("div", { className: styles.dialog__header },
|
|
90
|
+
status && (React.createElement("span", { id: `${id}-status-icon`, "aria-hidden": "true", className: `${styles.dialog__statusIcon} ${statusIconClass[status]}` }, status === 'warning' ? React.createElement(reactIcons.ExclamationTriangleIcon, null) : React.createElement(reactIcons.TrashIcon, null))),
|
|
91
|
+
React.createElement(themes.AlertDialog.Title, { className: styles.dialog__title }, title)),
|
|
92
|
+
React.createElement(themes.AlertDialog.Description, { className: styles.dialog__description }, description),
|
|
93
|
+
children && React.createElement("div", { className: styles.dialog__body }, children),
|
|
94
|
+
React.createElement(SplDialogFooter, { dialogId: id, wrapSecondary: wrapInCancel, ...actions }))));
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Delete confirmation: SplAlertDialog with the red trash icon and destructive primary button.
|
|
98
|
+
*/
|
|
99
|
+
const SplDeleteAlertDialog = ({ id, itemName, itemNameId = `${id}-item-name`, primaryLabel = 'Delete', primaryLoadingLabel = 'Deleting...', secondaryLabel = 'Cancel', ...rest }) => (React.createElement(SplAlertDialog, { id: id, status: "destructive", primaryVariant: "destructive", primaryLabel: primaryLabel, primaryLoadingLabel: primaryLoadingLabel, secondaryLabel: secondaryLabel, description: React.createElement(React.Fragment, null,
|
|
100
|
+
"Please confirm deletion of: ",
|
|
101
|
+
React.createElement("strong", { id: itemNameId }, itemName)), ...rest }));
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Warning confirmation (e.g. sensitive record access): SplAlertDialog with the amber warning icon
|
|
105
|
+
* and the standard primary button.
|
|
106
|
+
*/
|
|
107
|
+
const SplWarningAlertDialog = ({ primaryLabel = 'Continue', secondaryLabel = 'Cancel', ...rest }) => (React.createElement(SplAlertDialog, { status: "warning", primaryLabel: primaryLabel, secondaryLabel: secondaryLabel, ...rest }));
|
|
7
108
|
|
|
8
109
|
const DEFAULT_SPL_THEME = "light";
|
|
9
110
|
const DARK_SCHEME_QUERY = "(prefers-color-scheme: dark)";
|
|
@@ -95,7 +196,11 @@ const SplThemeProvider = ({ children, preference: controlledPreference, defaultP
|
|
|
95
196
|
React.createElement(themes.Theme, { appearance: "inherit", grayColor: "slate", hasBackground: false }, children)));
|
|
96
197
|
};
|
|
97
198
|
|
|
199
|
+
exports.SplAlertDialog = SplAlertDialog;
|
|
200
|
+
exports.SplDeleteAlertDialog = SplDeleteAlertDialog;
|
|
201
|
+
exports.SplDialog = SplDialog;
|
|
98
202
|
exports.SplThemeProvider = SplThemeProvider;
|
|
203
|
+
exports.SplWarningAlertDialog = SplWarningAlertDialog;
|
|
99
204
|
exports.applyInitialSplTheme = applyInitialSplTheme;
|
|
100
205
|
exports.applySplTheme = applySplTheme;
|
|
101
206
|
exports.getSystemTheme = getSystemTheme;
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/theme/themeUtils.ts","../../src/components/spl-theme-provider/SplThemeProvider.tsx"],"sourcesContent":["export type SplTheme = \"light\" | \"dark\";\r\nexport type SplThemePreference = SplTheme | \"system\";\r\n\r\nexport const DEFAULT_SPL_THEME: SplTheme = \"light\";\r\nexport const DARK_SCHEME_QUERY = \"(prefers-color-scheme: dark)\";\r\n\r\nexport function isSplThemePreference(value: unknown): value is SplThemePreference {\r\n return value === \"light\" || value === \"dark\" || value === \"system\";\r\n}\r\n\r\nexport function themeFromMatches(matches: boolean): SplTheme {\r\n return matches ? \"dark\" : \"light\";\r\n}\r\n\r\n/** OS/browser color scheme, falling back to light when matchMedia is unavailable. */\r\nexport function getSystemTheme(): SplTheme {\r\n try {\r\n return themeFromMatches(Boolean(window.matchMedia?.(DARK_SCHEME_QUERY)?.matches));\r\n } catch {\r\n return DEFAULT_SPL_THEME;\r\n }\r\n}\r\n\r\nexport function resolveSplTheme(preference: SplThemePreference): SplTheme {\r\n return preference === \"system\" ? getSystemTheme() : preference;\r\n}\r\n\r\n/**\r\n * Applies a theme to the root element: [data-theme] for app styles and the `dark` class that\r\n * @va-scheduling/design-tokens and the Radix dark scales key off of. `color-scheme` is not set.\r\n */\r\nexport function applySplTheme(theme: SplTheme, root: HTMLElement = document.documentElement) {\r\n const safeTheme: SplTheme = theme === \"dark\" ? \"dark\" : DEFAULT_SPL_THEME;\r\n root.setAttribute(\"data-theme\", safeTheme);\r\n root.classList.toggle(\"dark\", safeTheme === \"dark\");\r\n}\r\n\r\n/**\r\n * Applies the stored theme before React renders, to avoid a flash. The app supplies how to read its\r\n * stored preference, since storage differs between apps.\r\n */\r\nexport function applyInitialSplTheme(\r\n readPreference: () => SplThemePreference | undefined = () => undefined,\r\n) {\r\n let preference: SplThemePreference | undefined;\r\n try {\r\n preference = readPreference();\r\n } catch {\r\n preference = undefined;\r\n }\r\n applySplTheme(resolveSplTheme(isSplThemePreference(preference) ? preference : DEFAULT_SPL_THEME));\r\n}\r\n","import React, {\r\n createContext,\r\n useContext,\r\n useEffect,\r\n useLayoutEffect,\r\n useMemo,\r\n useState,\r\n} from \"react\";\r\nimport { Theme } from \"@radix-ui/themes\";\r\nimport {\r\n applySplTheme,\r\n DARK_SCHEME_QUERY,\r\n DEFAULT_SPL_THEME,\r\n getSystemTheme,\r\n SplTheme,\r\n SplThemePreference,\r\n themeFromMatches,\r\n} from \"../../theme/themeUtils\";\r\n\r\nexport interface SplThemeContextValue {\r\n /** The stored preference: 'light', 'dark', or 'system' (follow the OS/browser). */\r\n preference: SplThemePreference;\r\n /** The theme currently applied to the root element. */\r\n theme: SplTheme;\r\n setPreference: (preference: SplThemePreference) => void;\r\n}\r\n\r\nexport interface SplThemeProviderProps {\r\n children?: React.ReactNode;\r\n /** Controlled preference. When set, the app owns storage and must update it in onPreferenceChange. */\r\n preference?: SplThemePreference;\r\n /** Initial preference when uncontrolled. Defaults to light. */\r\n defaultPreference?: SplThemePreference;\r\n onPreferenceChange?: (preference: SplThemePreference) => void;\r\n}\r\n\r\nconst SplThemeContext = createContext<SplThemeContextValue | undefined>(undefined);\r\n\r\nexport function useSplTheme(): SplThemeContextValue {\r\n const context = useContext(SplThemeContext);\r\n if (context === undefined) {\r\n throw new Error(\"useSplTheme must be used within SplThemeProvider\");\r\n }\r\n return context;\r\n}\r\n\r\n/**\r\n * Applies the light/dark theme to the root element and wraps children in a Radix <Theme>\r\n * (appearance=\"inherit\" follows the .dark class; grayColor=\"slate\" matches the design-tokens base scale).\r\n * The OS/browser scheme is only followed, with live updates, when the preference is 'system'.\r\n */\r\nconst SplThemeProvider = ({\r\n children,\r\n preference: controlledPreference,\r\n defaultPreference = DEFAULT_SPL_THEME,\r\n onPreferenceChange,\r\n}: SplThemeProviderProps) => {\r\n const [internalPreference, setInternalPreference] = useState<SplThemePreference>(defaultPreference);\r\n const preference = controlledPreference ?? internalPreference;\r\n const [systemTheme, setSystemTheme] = useState<SplTheme>(getSystemTheme);\r\n\r\n useEffect(() => {\r\n if (preference !== \"system\" || typeof window.matchMedia !== \"function\") {\r\n return undefined;\r\n }\r\n\r\n const mediaQuery = window.matchMedia(DARK_SCHEME_QUERY);\r\n const handleChange = () => setSystemTheme(getSystemTheme());\r\n\r\n // systemTheme goes stale while an explicit preference is set (no listener), so resync here\r\n setSystemTheme(themeFromMatches(mediaQuery.matches));\r\n mediaQuery.addEventListener?.(\"change\", handleChange);\r\n return () => mediaQuery.removeEventListener?.(\"change\", handleChange);\r\n }, [preference]);\r\n\r\n const theme: SplTheme = preference === \"system\" ? systemTheme : preference;\r\n\r\n useLayoutEffect(() => {\r\n applySplTheme(theme);\r\n }, [theme]);\r\n\r\n const value = useMemo<SplThemeContextValue>(\r\n () => ({\r\n preference,\r\n theme,\r\n setPreference: (next: SplThemePreference) => {\r\n if (controlledPreference === undefined) {\r\n setInternalPreference(next);\r\n }\r\n onPreferenceChange?.(next);\r\n },\r\n }),\r\n [preference, theme, controlledPreference, onPreferenceChange],\r\n );\r\n\r\n return (\r\n <SplThemeContext.Provider value={value}>\r\n <Theme appearance=\"inherit\" grayColor=\"slate\" hasBackground={false}>\r\n {children}\r\n </Theme>\r\n </SplThemeContext.Provider>\r\n );\r\n};\r\n\r\nexport default SplThemeProvider;\r\n"],"names":["createContext","useContext","useState","useEffect","useLayoutEffect","useMemo","Theme"],"mappings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tB,IAAA,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AAEX,IAAA,MAAM,KAAK,GAAGC,aAAO,CACnB,OAAO;QACL,UAAU;QACV,KAAK;AACL,QAAA,aAAa,EAAE,CAAC,IAAwB,KAAI;AAC1C,YAAA,IAAI,oBAAoB,KAAK,SAAS,EAAE;gBACtC,qBAAqB,CAAC,IAAI,CAAC;YAC7B;AACA,YAAA,kBAAkB,GAAG,IAAI,CAAC;QAC5B,CAAC;KACF,CAAC,EACF,CAAC,UAAU,EAAE,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,CAAC,CAC9D;IAED,QACE,oBAAC,eAAe,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAAA;AACpC,QAAA,KAAA,CAAA,aAAA,CAACC,YAAK,EAAA,EAAC,UAAU,EAAC,SAAS,EAAC,SAAS,EAAC,OAAO,EAAC,aAAa,EAAE,KAAK,EAAA,EAC/D,QAAQ,CACH,CACiB;AAE/B;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/components/spl-dialog/SplDialogFooter.tsx","../../src/components/spl-dialog/SplDialog.tsx","../../src/components/spl-dialog/SplAlertDialog.tsx","../../src/components/spl-dialog/SplDeleteAlertDialog.tsx","../../src/components/spl-dialog/SplWarningAlertDialog.tsx","../../src/theme/themeUtils.ts","../../src/components/spl-theme-provider/SplThemeProvider.tsx"],"sourcesContent":["import { Button, Spinner } from '@radix-ui/themes';\r\nimport React, { ReactNode, useEffect, useRef, useState } from 'react';\r\n\r\nimport styles from './splDialog.module.css';\r\n\r\nexport type SplDialogActionsProps = {\r\n /** Text for the cancel/close button. Defaults to \"Cancel\" when a primary button is shown. Provide it alone (e.g. \"Close\") for a close-only footer. */\r\n secondaryLabel?: string;\r\n /** Text for the accept button. */\r\n primaryLabel?: string;\r\n /** Text for the accept button while it is loading. */\r\n primaryLoadingLabel?: string;\r\n /** Forces the primary button into its loading state, for loading driven by a store or parent. Loading from `onPrimaryAction` promises is tracked automatically. */\r\n isPrimaryLoading?: boolean;\r\n /** Called on accept. If it returns a promise the primary button shows a loading state until it settles. */\r\n onPrimaryAction?: () => void | Promise<void>;\r\n /** Called on cancel. The dialog also closes through `onOpenChange`. */\r\n onSecondaryAction?: () => void;\r\n isPrimaryDisabled?: boolean;\r\n isSecondaryDisabled?: boolean;\r\n /** Visual treatment of the primary button. `destructive` is for deletions. */\r\n primaryVariant?: 'default' | 'destructive';\r\n /** Optional extra button between secondary and primary. */\r\n tertiaryLabel?: string;\r\n onTertiaryAction?: () => void | Promise<void>;\r\n isTertiaryDisabled?: boolean;\r\n};\r\n\r\ntype SplDialogFooterProps = SplDialogActionsProps & {\r\n dialogId: string;\r\n /** Wraps the secondary button so Radix primitives (e.g. AlertDialog.Cancel) can own it. */\r\n wrapSecondary?: (button: ReactNode) => ReactNode;\r\n};\r\n\r\n/**\r\n * Footer buttons shared by SplDialog and SplAlertDialog.\r\n * Button ids are `{dialogId}-secondary-btn`, `-tertiary-btn` and `-primary-btn`.\r\n */\r\nconst SplDialogFooter = ({\r\n dialogId,\r\n secondaryLabel,\r\n primaryLabel,\r\n primaryLoadingLabel,\r\n isPrimaryLoading = false,\r\n onPrimaryAction,\r\n onSecondaryAction,\r\n isPrimaryDisabled = false,\r\n isSecondaryDisabled = false,\r\n primaryVariant = 'default',\r\n tertiaryLabel,\r\n onTertiaryAction,\r\n isTertiaryDisabled = false,\r\n wrapSecondary = (button) => button,\r\n}: SplDialogFooterProps) => {\r\n const [isPending, setIsPending] = useState(false);\r\n const isMounted = useRef(true);\r\n\r\n useEffect(() => {\r\n isMounted.current = true;\r\n return () => { isMounted.current = false; };\r\n }, []);\r\n\r\n // Cancel is the default secondary label next to a primary button; a close-only footer must opt in via secondaryLabel.\r\n const secondaryText = secondaryLabel ?? (primaryLabel ? 'Cancel' : undefined);\r\n if (!primaryLabel && !secondaryText) return null;\r\n\r\n const isLoading = isPending || isPrimaryLoading;\r\n\r\n const handlePrimary = async () => {\r\n setIsPending(true);\r\n try {\r\n await onPrimaryAction?.();\r\n } catch {\r\n // Callers own error handling (e.g. the error store); a rejection only needs to end the loading state.\r\n } finally {\r\n if (isMounted.current) setIsPending(false);\r\n }\r\n };\r\n\r\n const secondaryButton = (\r\n <Button\r\n type=\"button\"\r\n variant=\"outline\"\r\n className={`${styles.button} ${styles['button--secondary']}`}\r\n id={`${dialogId}-secondary-btn`}\r\n disabled={isLoading || isSecondaryDisabled}\r\n onClick={onSecondaryAction}\r\n >\r\n {secondaryText}\r\n </Button>\r\n );\r\n\r\n return (\r\n <div className={styles.dialog__footer}>\r\n {secondaryText && wrapSecondary(secondaryButton)}\r\n {tertiaryLabel && onTertiaryAction && (\r\n <Button\r\n type=\"button\"\r\n variant=\"outline\"\r\n className={`${styles.button} ${styles['button--secondary']}`}\r\n id={`${dialogId}-tertiary-btn`}\r\n disabled={isLoading || isTertiaryDisabled}\r\n onClick={() => void onTertiaryAction()}\r\n >\r\n {tertiaryLabel}\r\n </Button>\r\n )}\r\n {primaryLabel && (\r\n <Button\r\n type=\"button\"\r\n id={`${dialogId}-primary-btn`}\r\n className={`${styles.button} ${primaryVariant === 'destructive' ? styles['button--destructive'] : styles['button--primary']}`}\r\n {...(primaryVariant === 'destructive' ? { color: 'red' as const } : {})}\r\n disabled={isLoading || isPrimaryDisabled}\r\n aria-busy={isLoading}\r\n onClick={() => void handlePrimary()}\r\n >\r\n {/* Radix's `loading` prop hides the label; render the spinner beside it instead. */}\r\n {isLoading && <Spinner size=\"1\" />}\r\n {isLoading && primaryLoadingLabel ? primaryLoadingLabel : primaryLabel}\r\n </Button>\r\n )}\r\n </div>\r\n );\r\n};\r\n\r\nexport default SplDialogFooter;\r\n","import { Cross2Icon } from '@radix-ui/react-icons';\r\nimport { Dialog, IconButton } from '@radix-ui/themes';\r\nimport React, { ReactNode } from 'react';\r\n\r\nimport SplDialogFooter, { SplDialogActionsProps } from './SplDialogFooter';\r\nimport { SplDialogSizeProps } from './splDialogSize';\r\nimport styles from './splDialog.module.css';\r\n\r\nexport type SplDialogProps = SplDialogActionsProps & SplDialogSizeProps & {\r\n /** Unique id; the content element gets this id and footer buttons derive theirs from it. */\r\n id: string;\r\n title: string;\r\n /** Optional description announced by screen readers. */\r\n description?: string;\r\n isOpen: boolean;\r\n onOpenChange: (isOpen: boolean) => void;\r\n children: ReactNode;\r\n /** Replace the built-in footer entirely (e.g. for forms that own their buttons). */\r\n footer?: ReactNode;\r\n /** Prevent closing via Escape, overlay click, or the X button. */\r\n isDismissDisabled?: boolean;\r\n /** Show the X button in the corner. Defaults to true; Escape and overlay click still close the dialog when false. */\r\n hasCloseButton?: boolean;\r\n /** Extra class on the content panel, for width overrides. */\r\n contentClassName?: string;\r\n};\r\n\r\n/**\r\n * General purpose modal built on Radix Dialog for content and form dialogs.\r\n * Use SplAlertDialog instead for confirmations that must be answered.\r\n */\r\nconst SplDialog = ({\r\n id,\r\n title,\r\n description,\r\n isOpen,\r\n onOpenChange,\r\n children,\r\n footer,\r\n isDismissDisabled = false,\r\n hasCloseButton = true,\r\n contentClassName,\r\n size = '3',\r\n maxWidth = '544px',\r\n onSecondaryAction,\r\n ...actions\r\n}: SplDialogProps) => {\r\n const preventIfDisabled = (event: Event) => {\r\n if (isDismissDisabled) event.preventDefault();\r\n };\r\n\r\n return (\r\n <Dialog.Root open={isOpen} onOpenChange={onOpenChange}>\r\n <Dialog.Content\r\n id={id}\r\n size={size}\r\n maxWidth={maxWidth}\r\n className={[styles.dialog__content, contentClassName].filter(Boolean).join(' ')}\r\n onEscapeKeyDown={preventIfDisabled}\r\n onInteractOutside={preventIfDisabled}\r\n {...(description ? {} : { 'aria-describedby': undefined })}\r\n >\r\n <Dialog.Title className={styles.dialog__title}>{title}</Dialog.Title>\r\n {!isDismissDisabled && hasCloseButton && (\r\n <Dialog.Close>\r\n <IconButton\r\n type=\"button\"\r\n id={`${id}-close-btn`}\r\n variant=\"ghost\"\r\n color=\"gray\"\r\n className={styles.dialog__close}\r\n aria-label=\"Close\"\r\n >\r\n <Cross2Icon aria-hidden=\"true\" />\r\n </IconButton>\r\n </Dialog.Close>\r\n )}\r\n {description && (\r\n <Dialog.Description className={styles.dialog__description}>{description}</Dialog.Description>\r\n )}\r\n <div className={styles.dialog__body}>{children}</div>\r\n {footer ?? (\r\n <SplDialogFooter\r\n dialogId={id}\r\n // Cancel always closes the dialog, even when dismissal is disabled; onSecondaryAction is an extra hook, and actions can't override this handler.\r\n onSecondaryAction={() => {\r\n onSecondaryAction?.();\r\n onOpenChange(false);\r\n }}\r\n {...actions}\r\n />\r\n )}\r\n </Dialog.Content>\r\n </Dialog.Root>\r\n );\r\n};\r\n\r\nexport default SplDialog;\r\n","import { ExclamationTriangleIcon, TrashIcon } from '@radix-ui/react-icons';\r\nimport { AlertDialog } from '@radix-ui/themes';\r\nimport React, { ReactNode } from 'react';\r\n\r\nimport SplDialogFooter, { SplDialogActionsProps } from './SplDialogFooter';\r\nimport { SplDialogSizeProps } from './splDialogSize';\r\nimport styles from './splDialog.module.css';\r\n\r\nexport type SplAlertDialogProps = Omit<SplDialogActionsProps, 'primaryLabel'> & SplDialogSizeProps & {\r\n /** Unique id; the content element gets this id and footer buttons derive theirs from it. */\r\n id: string;\r\n title: string;\r\n /** Required: alert dialogs must tell the user what they are confirming. May include inline markup. */\r\n description: ReactNode;\r\n isOpen: boolean;\r\n onOpenChange: (isOpen: boolean) => void;\r\n /** Required: an alert dialog always has an accept action. */\r\n primaryLabel: string;\r\n /** Optional extra content below the description (e.g. an error alert). */\r\n children?: ReactNode;\r\n /** Shows a leading icon before the title: a red trash can for 'destructive', an amber triangle for 'warning'. */\r\n status?: 'destructive' | 'warning';\r\n};\r\n\r\nconst statusIconClass = {\r\n destructive: styles['dialog__statusIcon--destructive'],\r\n warning: styles['dialog__statusIcon--warning'],\r\n};\r\n\r\nconst wrapInCancel = (button: ReactNode) => <AlertDialog.Cancel>{button}</AlertDialog.Cancel>;\r\n\r\n/**\r\n * Confirmation dialog built on Radix AlertDialog, for interruptions that need an explicit answer\r\n * (delete confirmations, unsaved changes, etc.). Unlike SplDialog it cannot be dismissed by clicking\r\n * outside, has no X button, and focuses Cancel first so the safe choice is the default.\r\n * Cancel closes it through `onOpenChange`. It does not auto-close on accept; the caller closes it\r\n * through `isOpen` once the action succeeds.\r\n */\r\nconst SplAlertDialog = ({\r\n id,\r\n title,\r\n description,\r\n isOpen,\r\n onOpenChange,\r\n children,\r\n status,\r\n size = '3',\r\n maxWidth = '450px',\r\n ...actions\r\n}: SplAlertDialogProps) => (\r\n <AlertDialog.Root open={isOpen} onOpenChange={onOpenChange}>\r\n <AlertDialog.Content\r\n id={id}\r\n size={size}\r\n maxWidth={maxWidth}\r\n className={styles.dialog__content}\r\n >\r\n <div className={styles.dialog__header}>\r\n {status && (\r\n <span\r\n id={`${id}-status-icon`}\r\n aria-hidden=\"true\"\r\n className={`${styles.dialog__statusIcon} ${statusIconClass[status]}`}\r\n >\r\n {status === 'warning' ? <ExclamationTriangleIcon /> : <TrashIcon />}\r\n </span>\r\n )}\r\n <AlertDialog.Title className={styles.dialog__title}>{title}</AlertDialog.Title>\r\n </div>\r\n <AlertDialog.Description className={styles.dialog__description}>\r\n {description}\r\n </AlertDialog.Description>\r\n {children && <div className={styles.dialog__body}>{children}</div>}\r\n <SplDialogFooter\r\n dialogId={id}\r\n wrapSecondary={wrapInCancel}\r\n {...actions}\r\n />\r\n </AlertDialog.Content>\r\n </AlertDialog.Root>\r\n);\r\n\r\nexport default SplAlertDialog;\r\n","import React from 'react';\r\n\r\nimport SplAlertDialog, { SplAlertDialogProps } from './SplAlertDialog';\r\n\r\nexport type SplDeleteAlertDialogProps = Omit<SplAlertDialogProps, 'status' | 'primaryVariant' | 'description' | 'primaryLabel'> & {\r\n /** Name of the item being deleted, shown in bold after \"Please confirm deletion of:\". */\r\n itemName: string;\r\n /** Id for the bold item name element. Defaults to `{id}-item-name`. */\r\n itemNameId?: string;\r\n /** Defaults to \"Delete\". */\r\n primaryLabel?: string;\r\n};\r\n\r\n/**\r\n * Delete confirmation: SplAlertDialog with the red trash icon and destructive primary button.\r\n */\r\nconst SplDeleteAlertDialog = ({\r\n id,\r\n itemName,\r\n itemNameId = `${id}-item-name`,\r\n primaryLabel = 'Delete',\r\n primaryLoadingLabel = 'Deleting...',\r\n secondaryLabel = 'Cancel',\r\n ...rest\r\n}: SplDeleteAlertDialogProps) => (\r\n <SplAlertDialog\r\n id={id}\r\n status=\"destructive\"\r\n primaryVariant=\"destructive\"\r\n primaryLabel={primaryLabel}\r\n primaryLoadingLabel={primaryLoadingLabel}\r\n secondaryLabel={secondaryLabel}\r\n description={\r\n <>\r\n Please confirm deletion of: <strong id={itemNameId}>{itemName}</strong>\r\n </>\r\n }\r\n {...rest}\r\n />\r\n);\r\n\r\nexport default SplDeleteAlertDialog;\r\n","import React from 'react';\r\n\r\nimport SplAlertDialog, { SplAlertDialogProps } from './SplAlertDialog';\r\n\r\nexport type SplWarningAlertDialogProps = Omit<SplAlertDialogProps, 'status' | 'primaryVariant' | 'primaryLabel'> & {\r\n /** Defaults to \"Continue\". */\r\n primaryLabel?: string;\r\n};\r\n\r\n/**\r\n * Warning confirmation (e.g. sensitive record access): SplAlertDialog with the amber warning icon\r\n * and the standard primary button.\r\n */\r\nconst SplWarningAlertDialog = ({\r\n primaryLabel = 'Continue',\r\n secondaryLabel = 'Cancel',\r\n ...rest\r\n}: SplWarningAlertDialogProps) => (\r\n <SplAlertDialog status=\"warning\" primaryLabel={primaryLabel} secondaryLabel={secondaryLabel} {...rest} />\r\n);\r\n\r\nexport default SplWarningAlertDialog;\r\n","export type SplTheme = \"light\" | \"dark\";\r\nexport type SplThemePreference = SplTheme | \"system\";\r\n\r\nexport const DEFAULT_SPL_THEME: SplTheme = \"light\";\r\nexport const DARK_SCHEME_QUERY = \"(prefers-color-scheme: dark)\";\r\n\r\nexport function isSplThemePreference(value: unknown): value is SplThemePreference {\r\n return value === \"light\" || value === \"dark\" || value === \"system\";\r\n}\r\n\r\nexport function themeFromMatches(matches: boolean): SplTheme {\r\n return matches ? \"dark\" : \"light\";\r\n}\r\n\r\n/** OS/browser color scheme, falling back to light when matchMedia is unavailable. */\r\nexport function getSystemTheme(): SplTheme {\r\n try {\r\n return themeFromMatches(Boolean(window.matchMedia?.(DARK_SCHEME_QUERY)?.matches));\r\n } catch {\r\n return DEFAULT_SPL_THEME;\r\n }\r\n}\r\n\r\nexport function resolveSplTheme(preference: SplThemePreference): SplTheme {\r\n return preference === \"system\" ? getSystemTheme() : preference;\r\n}\r\n\r\n/**\r\n * Applies a theme to the root element: [data-theme] for app styles and the `dark` class that\r\n * @va-scheduling/design-tokens and the Radix dark scales key off of. `color-scheme` is not set.\r\n */\r\nexport function applySplTheme(theme: SplTheme, root: HTMLElement = document.documentElement) {\r\n const safeTheme: SplTheme = theme === \"dark\" ? \"dark\" : DEFAULT_SPL_THEME;\r\n root.setAttribute(\"data-theme\", safeTheme);\r\n root.classList.toggle(\"dark\", safeTheme === \"dark\");\r\n}\r\n\r\n/**\r\n * Applies the stored theme before React renders, to avoid a flash. The app supplies how to read its\r\n * stored preference, since storage differs between apps.\r\n */\r\nexport function applyInitialSplTheme(\r\n readPreference: () => SplThemePreference | undefined = () => undefined,\r\n) {\r\n let preference: SplThemePreference | undefined;\r\n try {\r\n preference = readPreference();\r\n } catch {\r\n preference = undefined;\r\n }\r\n applySplTheme(resolveSplTheme(isSplThemePreference(preference) ? preference : DEFAULT_SPL_THEME));\r\n}\r\n","import React, {\r\n createContext,\r\n useContext,\r\n useEffect,\r\n useLayoutEffect,\r\n useMemo,\r\n useState,\r\n} from \"react\";\r\nimport { Theme } from \"@radix-ui/themes\";\r\nimport {\r\n applySplTheme,\r\n DARK_SCHEME_QUERY,\r\n DEFAULT_SPL_THEME,\r\n getSystemTheme,\r\n SplTheme,\r\n SplThemePreference,\r\n themeFromMatches,\r\n} from \"../../theme/themeUtils\";\r\n\r\nexport interface SplThemeContextValue {\r\n /** The stored preference: 'light', 'dark', or 'system' (follow the OS/browser). */\r\n preference: SplThemePreference;\r\n /** The theme currently applied to the root element. */\r\n theme: SplTheme;\r\n setPreference: (preference: SplThemePreference) => void;\r\n}\r\n\r\nexport interface SplThemeProviderProps {\r\n children?: React.ReactNode;\r\n /** Controlled preference. When set, the app owns storage and must update it in onPreferenceChange. */\r\n preference?: SplThemePreference;\r\n /** Initial preference when uncontrolled. Defaults to light. */\r\n defaultPreference?: SplThemePreference;\r\n onPreferenceChange?: (preference: SplThemePreference) => void;\r\n}\r\n\r\nconst SplThemeContext = createContext<SplThemeContextValue | undefined>(undefined);\r\n\r\nexport function useSplTheme(): SplThemeContextValue {\r\n const context = useContext(SplThemeContext);\r\n if (context === undefined) {\r\n throw new Error(\"useSplTheme must be used within SplThemeProvider\");\r\n }\r\n return context;\r\n}\r\n\r\n/**\r\n * Applies the light/dark theme to the root element and wraps children in a Radix <Theme>\r\n * (appearance=\"inherit\" follows the .dark class; grayColor=\"slate\" matches the design-tokens base scale).\r\n * The OS/browser scheme is only followed, with live updates, when the preference is 'system'.\r\n */\r\nconst SplThemeProvider = ({\r\n children,\r\n preference: controlledPreference,\r\n defaultPreference = DEFAULT_SPL_THEME,\r\n onPreferenceChange,\r\n}: SplThemeProviderProps) => {\r\n const [internalPreference, setInternalPreference] = useState<SplThemePreference>(defaultPreference);\r\n const preference = controlledPreference ?? internalPreference;\r\n const [systemTheme, setSystemTheme] = useState<SplTheme>(getSystemTheme);\r\n\r\n useEffect(() => {\r\n if (preference !== \"system\" || typeof window.matchMedia !== \"function\") {\r\n return undefined;\r\n }\r\n\r\n const mediaQuery = window.matchMedia(DARK_SCHEME_QUERY);\r\n const handleChange = () => setSystemTheme(getSystemTheme());\r\n\r\n // systemTheme goes stale while an explicit preference is set (no listener), so resync here\r\n setSystemTheme(themeFromMatches(mediaQuery.matches));\r\n mediaQuery.addEventListener?.(\"change\", handleChange);\r\n return () => mediaQuery.removeEventListener?.(\"change\", handleChange);\r\n }, [preference]);\r\n\r\n const theme: SplTheme = preference === \"system\" ? systemTheme : preference;\r\n\r\n useLayoutEffect(() => {\r\n applySplTheme(theme);\r\n }, [theme]);\r\n\r\n const value = useMemo<SplThemeContextValue>(\r\n () => ({\r\n preference,\r\n theme,\r\n setPreference: (next: SplThemePreference) => {\r\n if (controlledPreference === undefined) {\r\n setInternalPreference(next);\r\n }\r\n onPreferenceChange?.(next);\r\n },\r\n }),\r\n [preference, theme, controlledPreference, onPreferenceChange],\r\n );\r\n\r\n return (\r\n <SplThemeContext.Provider value={value}>\r\n <Theme appearance=\"inherit\" grayColor=\"slate\" hasBackground={false}>\r\n {children}\r\n </Theme>\r\n </SplThemeContext.Provider>\r\n );\r\n};\r\n\r\nexport default SplThemeProvider;\r\n"],"names":["useState","useRef","useEffect","Button","Spinner","Dialog","IconButton","Cross2Icon","AlertDialog","ExclamationTriangleIcon","TrashIcon","createContext","useContext","useLayoutEffect","useMemo","Theme"],"mappings":";;;;;;;;;;;AAkCA;;;AAGG;AACH,MAAM,eAAe,GAAG,CAAC,EACvB,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,GAAG,KAAK,EACxB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,GAAG,KAAK,EACzB,mBAAmB,GAAG,KAAK,EAC3B,cAAc,GAAG,SAAS,EAC1B,aAAa,EACb,gBAAgB,EAChB,kBAAkB,GAAG,KAAK,EAC1B,aAAa,GAAG,CAAC,MAAM,KAAK,MAAM,GACb,KAAI;IACzB,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC;AACjD,IAAA,MAAM,SAAS,GAAGC,YAAM,CAAC,IAAI,CAAC;IAE9BC,eAAS,CAAC,MAAK;AACb,QAAA,SAAS,CAAC,OAAO,GAAG,IAAI;QACxB,OAAO,MAAK,EAAG,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC,EAAE,EAAE,CAAC;;AAGN,IAAA,MAAM,aAAa,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AAmB,GAAG,QAAQ,EAAE,YAAY,CAAC;AACvE,IAAA,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;AAEhB,IAAA,MAAM,KAAK,GAAa,UAAU,KAAK,QAAQ,GAAG,WAAW,GAAG,UAAU;IAE1EW,qBAAe,CAAC,MAAK;QACnB,aAAa,CAAC,KAAK,CAAC;AACtB,IAAA,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;AAEX,IAAA,MAAM,KAAK,GAAGC,aAAO,CACnB,OAAO;QACL,UAAU;QACV,KAAK;AACL,QAAA,aAAa,EAAE,CAAC,IAAwB,KAAI;AAC1C,YAAA,IAAI,oBAAoB,KAAK,SAAS,EAAE;gBACtC,qBAAqB,CAAC,IAAI,CAAC;YAC7B;AACA,YAAA,kBAAkB,GAAG,IAAI,CAAC;QAC5B,CAAC;KACF,CAAC,EACF,CAAC,UAAU,EAAE,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,CAAC,CAC9D;IAED,QACE,oBAAC,eAAe,CAAC,QAAQ,EAAA,EAAC,KAAK,EAAE,KAAK,EAAA;AACpC,QAAA,KAAA,CAAA,aAAA,CAACC,YAAK,EAAA,EAAC,UAAU,EAAC,SAAS,EAAC,SAAS,EAAC,OAAO,EAAC,aAAa,EAAE,KAAK,EAAA,EAC/D,QAAQ,CACH,CACiB;AAE/B;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
export { SplDialog, SplAlertDialog, SplDeleteAlertDialog, SplWarningAlertDialog, } from "./spl-dialog";
|
|
2
|
+
export type { SplDialogProps, SplAlertDialogProps, SplDeleteAlertDialogProps, SplWarningAlertDialogProps, SplDialogActionsProps, SplDialogSize, SplDialogSizeProps, } from "./spl-dialog";
|
|
1
3
|
export { default as SplThemeProvider, useSplTheme } from "./spl-theme-provider";
|
|
2
4
|
export type { SplThemeProviderProps, SplThemeContextValue } from "./spl-theme-provider";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { SplDialogActionsProps } from './SplDialogFooter';
|
|
3
|
+
import { SplDialogSizeProps } from './splDialogSize';
|
|
4
|
+
export type SplAlertDialogProps = Omit<SplDialogActionsProps, 'primaryLabel'> & SplDialogSizeProps & {
|
|
5
|
+
/** Unique id; the content element gets this id and footer buttons derive theirs from it. */
|
|
6
|
+
id: string;
|
|
7
|
+
title: string;
|
|
8
|
+
/** Required: alert dialogs must tell the user what they are confirming. May include inline markup. */
|
|
9
|
+
description: ReactNode;
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
onOpenChange: (isOpen: boolean) => void;
|
|
12
|
+
/** Required: an alert dialog always has an accept action. */
|
|
13
|
+
primaryLabel: string;
|
|
14
|
+
/** Optional extra content below the description (e.g. an error alert). */
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
/** Shows a leading icon before the title: a red trash can for 'destructive', an amber triangle for 'warning'. */
|
|
17
|
+
status?: 'destructive' | 'warning';
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Confirmation dialog built on Radix AlertDialog, for interruptions that need an explicit answer
|
|
21
|
+
* (delete confirmations, unsaved changes, etc.). Unlike SplDialog it cannot be dismissed by clicking
|
|
22
|
+
* outside, has no X button, and focuses Cancel first so the safe choice is the default.
|
|
23
|
+
* Cancel closes it through `onOpenChange`. It does not auto-close on accept; the caller closes it
|
|
24
|
+
* through `isOpen` once the action succeeds.
|
|
25
|
+
*/
|
|
26
|
+
declare const SplAlertDialog: ({ id, title, description, isOpen, onOpenChange, children, status, size, maxWidth, ...actions }: SplAlertDialogProps) => React.JSX.Element;
|
|
27
|
+
export default SplAlertDialog;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SplAlertDialogProps } from './SplAlertDialog';
|
|
3
|
+
export type SplDeleteAlertDialogProps = Omit<SplAlertDialogProps, 'status' | 'primaryVariant' | 'description' | 'primaryLabel'> & {
|
|
4
|
+
/** Name of the item being deleted, shown in bold after "Please confirm deletion of:". */
|
|
5
|
+
itemName: string;
|
|
6
|
+
/** Id for the bold item name element. Defaults to `{id}-item-name`. */
|
|
7
|
+
itemNameId?: string;
|
|
8
|
+
/** Defaults to "Delete". */
|
|
9
|
+
primaryLabel?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Delete confirmation: SplAlertDialog with the red trash icon and destructive primary button.
|
|
13
|
+
*/
|
|
14
|
+
declare const SplDeleteAlertDialog: ({ id, itemName, itemNameId, primaryLabel, primaryLoadingLabel, secondaryLabel, ...rest }: SplDeleteAlertDialogProps) => React.JSX.Element;
|
|
15
|
+
export default SplDeleteAlertDialog;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { SplDialogActionsProps } from './SplDialogFooter';
|
|
3
|
+
import { SplDialogSizeProps } from './splDialogSize';
|
|
4
|
+
export type SplDialogProps = SplDialogActionsProps & SplDialogSizeProps & {
|
|
5
|
+
/** Unique id; the content element gets this id and footer buttons derive theirs from it. */
|
|
6
|
+
id: string;
|
|
7
|
+
title: string;
|
|
8
|
+
/** Optional description announced by screen readers. */
|
|
9
|
+
description?: string;
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
onOpenChange: (isOpen: boolean) => void;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
/** Replace the built-in footer entirely (e.g. for forms that own their buttons). */
|
|
14
|
+
footer?: ReactNode;
|
|
15
|
+
/** Prevent closing via Escape, overlay click, or the X button. */
|
|
16
|
+
isDismissDisabled?: boolean;
|
|
17
|
+
/** Show the X button in the corner. Defaults to true; Escape and overlay click still close the dialog when false. */
|
|
18
|
+
hasCloseButton?: boolean;
|
|
19
|
+
/** Extra class on the content panel, for width overrides. */
|
|
20
|
+
contentClassName?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* General purpose modal built on Radix Dialog for content and form dialogs.
|
|
24
|
+
* Use SplAlertDialog instead for confirmations that must be answered.
|
|
25
|
+
*/
|
|
26
|
+
declare const SplDialog: ({ id, title, description, isOpen, onOpenChange, children, footer, isDismissDisabled, hasCloseButton, contentClassName, size, maxWidth, onSecondaryAction, ...actions }: SplDialogProps) => React.JSX.Element;
|
|
27
|
+
export default SplDialog;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
export type SplDialogActionsProps = {
|
|
3
|
+
/** Text for the cancel/close button. Defaults to "Cancel" when a primary button is shown. Provide it alone (e.g. "Close") for a close-only footer. */
|
|
4
|
+
secondaryLabel?: string;
|
|
5
|
+
/** Text for the accept button. */
|
|
6
|
+
primaryLabel?: string;
|
|
7
|
+
/** Text for the accept button while it is loading. */
|
|
8
|
+
primaryLoadingLabel?: string;
|
|
9
|
+
/** Forces the primary button into its loading state, for loading driven by a store or parent. Loading from `onPrimaryAction` promises is tracked automatically. */
|
|
10
|
+
isPrimaryLoading?: boolean;
|
|
11
|
+
/** Called on accept. If it returns a promise the primary button shows a loading state until it settles. */
|
|
12
|
+
onPrimaryAction?: () => void | Promise<void>;
|
|
13
|
+
/** Called on cancel. The dialog also closes through `onOpenChange`. */
|
|
14
|
+
onSecondaryAction?: () => void;
|
|
15
|
+
isPrimaryDisabled?: boolean;
|
|
16
|
+
isSecondaryDisabled?: boolean;
|
|
17
|
+
/** Visual treatment of the primary button. `destructive` is for deletions. */
|
|
18
|
+
primaryVariant?: 'default' | 'destructive';
|
|
19
|
+
/** Optional extra button between secondary and primary. */
|
|
20
|
+
tertiaryLabel?: string;
|
|
21
|
+
onTertiaryAction?: () => void | Promise<void>;
|
|
22
|
+
isTertiaryDisabled?: boolean;
|
|
23
|
+
};
|
|
24
|
+
type SplDialogFooterProps = SplDialogActionsProps & {
|
|
25
|
+
dialogId: string;
|
|
26
|
+
/** Wraps the secondary button so Radix primitives (e.g. AlertDialog.Cancel) can own it. */
|
|
27
|
+
wrapSecondary?: (button: ReactNode) => ReactNode;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Footer buttons shared by SplDialog and SplAlertDialog.
|
|
31
|
+
* Button ids are `{dialogId}-secondary-btn`, `-tertiary-btn` and `-primary-btn`.
|
|
32
|
+
*/
|
|
33
|
+
declare const SplDialogFooter: ({ dialogId, secondaryLabel, primaryLabel, primaryLoadingLabel, isPrimaryLoading, onPrimaryAction, onSecondaryAction, isPrimaryDisabled, isSecondaryDisabled, primaryVariant, tertiaryLabel, onTertiaryAction, isTertiaryDisabled, wrapSecondary, }: SplDialogFooterProps) => React.JSX.Element | null;
|
|
34
|
+
export default SplDialogFooter;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SplAlertDialogProps } from './SplAlertDialog';
|
|
3
|
+
export type SplWarningAlertDialogProps = Omit<SplAlertDialogProps, 'status' | 'primaryVariant' | 'primaryLabel'> & {
|
|
4
|
+
/** Defaults to "Continue". */
|
|
5
|
+
primaryLabel?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Warning confirmation (e.g. sensitive record access): SplAlertDialog with the amber warning icon
|
|
9
|
+
* and the standard primary button.
|
|
10
|
+
*/
|
|
11
|
+
declare const SplWarningAlertDialog: ({ primaryLabel, secondaryLabel, ...rest }: SplWarningAlertDialogProps) => React.JSX.Element;
|
|
12
|
+
export default SplWarningAlertDialog;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as SplDialog } from "./SplDialog";
|
|
2
|
+
export type { SplDialogProps } from "./SplDialog";
|
|
3
|
+
export { default as SplAlertDialog } from "./SplAlertDialog";
|
|
4
|
+
export type { SplAlertDialogProps } from "./SplAlertDialog";
|
|
5
|
+
export { default as SplDeleteAlertDialog } from "./SplDeleteAlertDialog";
|
|
6
|
+
export type { SplDeleteAlertDialogProps } from "./SplDeleteAlertDialog";
|
|
7
|
+
export { default as SplWarningAlertDialog } from "./SplWarningAlertDialog";
|
|
8
|
+
export type { SplWarningAlertDialogProps } from "./SplWarningAlertDialog";
|
|
9
|
+
export type { SplDialogActionsProps } from "./SplDialogFooter";
|
|
10
|
+
export type { SplDialogSize, SplDialogSizeProps } from "./splDialogSize";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Same size scale as Radix Themes dialogs: 1 = 12px padding, 2 = 16px, 3 = 24px (default), 4 = 32px. */
|
|
2
|
+
export type SplDialogSize = '1' | '2' | '3' | '4';
|
|
3
|
+
export type SplDialogSizeProps = {
|
|
4
|
+
/** Padding and corner radius preset, applied by Radix Themes. Defaults to '3'. */
|
|
5
|
+
size?: SplDialogSize;
|
|
6
|
+
/** Maximum width as any CSS length (e.g. `'450px'`, `'50rem'`). Defaults to 544px (450px for alert dialogs). */
|
|
7
|
+
maxWidth?: string;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.splDialog-module_dialog__content__t-Zwr:focus{outline:none}.splDialog-module_dialog__content__t-Zwr.splDialog-module_dialog__content__t-Zwr{font-family:var(--default-font-family);font-size:var(--font-size-2);font-weight:var(--font-weight-regular);line-height:var(--line-height-2)}.splDialog-module_dialog__title__hQwUq.splDialog-module_dialog__title__hQwUq{font-family:var(--default-font-family);font-size:var(--font-size-5);font-weight:var(--font-weight-bold);line-height:var(--heading-line-height-5);margin:0 0 var(--space-4)}.splDialog-module_dialog__description__akkml.splDialog-module_dialog__description__akkml{font-size:var(--font-size-2);line-height:var(--line-height-2);margin:0 0 var(--space-1)}.splDialog-module_dialog__header__4evfq .splDialog-module_dialog__title__hQwUq.splDialog-module_dialog__title__hQwUq{margin:0}.splDialog-module_dialog__header__4evfq{align-items:center;display:flex;gap:12px;margin-bottom:var(--space-3)}.splDialog-module_dialog__statusIcon__xY8Y4{display:inline-flex;margin:0 -2px;position:relative;top:-2px}.splDialog-module_dialog__statusIcon__xY8Y4 svg{height:20px;width:20px}.splDialog-module_dialog__statusIcon--destructive__gZagF{color:var(--spl-colors-error)}.splDialog-module_dialog__statusIcon--warning__53s2a{color:var(--spl-colors-warning)}.splDialog-module_dialog__body__AwXEL{margin-bottom:1rem}.splDialog-module_dialog__footer__nOkmx{display:flex;gap:.5rem;justify-content:flex-end;margin-top:1.5rem}.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT{border-radius:100%;box-sizing:border-box;height:32px;margin:0;padding:0;position:absolute;right:8px;top:8px;width:32px}.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT svg{height:20px;width:20px}.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT,.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT:active,.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT:focus,.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT:hover{background-color:transparent;color:var(--spl-colors-text-default)}.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT:active,.splDialog-module_dialog__close__RyLWT.splDialog-module_dialog__close__RyLWT:hover{background-color:var(--spl-colors-bg-secondary)}.splDialog-module_button__8fRnT.splDialog-module_button__8fRnT{align-items:center;border:none;border-radius:var(--radius-2);box-sizing:border-box;cursor:pointer;display:inline-flex;font-family:var(--default-font-family);font-size:var(--font-size-2);font-weight:var(--font-weight-medium);gap:var(--space-2);height:var(--space-6);justify-content:center;line-height:var(--line-height-2);padding:0 var(--space-3)}.splDialog-module_button--primary__n3DCG.splDialog-module_button--primary__n3DCG,.splDialog-module_button--primary__n3DCG.splDialog-module_button--primary__n3DCG:focus{background-color:var(--spl-colors-button-bg-primary);color:var(--spl-colors-button-text-primary)}.splDialog-module_button--primary__n3DCG.splDialog-module_button--primary__n3DCG:active,.splDialog-module_button--primary__n3DCG.splDialog-module_button--primary__n3DCG:hover{background-color:var(--spl-colors-button-bg-primary-hover-pressed);color:var(--spl-colors-button-text-primary-hover-pressed)}.splDialog-module_button--destructive__Ig1Az.splDialog-module_button--destructive__Ig1Az,.splDialog-module_button--destructive__Ig1Az.splDialog-module_button--destructive__Ig1Az:active,.splDialog-module_button--destructive__Ig1Az.splDialog-module_button--destructive__Ig1Az:focus,.splDialog-module_button--destructive__Ig1Az.splDialog-module_button--destructive__Ig1Az:hover{background-color:var(--spl-colors-error);color:var(--spl-colors-base-white)}.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3,.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:focus{background-color:var(--spl-colors-button-bg-secondary);box-shadow:inset 0 0 0 1px var(--spl-colors-button-border-secondary);color:var(--spl-colors-button-text-secondary)}.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:active,.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:hover{background-color:var(--spl-colors-button-bg-secondary-hover-pressed);box-shadow:inset 0 0 0 1px var(--spl-colors-button-border-secondary);color:var(--spl-colors-button-text-secondary)}.splDialog-module_button__8fRnT.splDialog-module_button__8fRnT:disabled,.splDialog-module_button__8fRnT.splDialog-module_button__8fRnT:disabled:active,.splDialog-module_button__8fRnT.splDialog-module_button__8fRnT:disabled:focus,.splDialog-module_button__8fRnT.splDialog-module_button__8fRnT:disabled:hover{background-color:var(--spl-colors-button-bg-primary-disabled);box-shadow:none;color:var(--spl-colors-button-text-primary-disabled);cursor:not-allowed}.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:disabled,.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:disabled:active,.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:disabled:focus,.splDialog-module_button--secondary__heKg3.splDialog-module_button--secondary__heKg3:disabled:hover{background-color:var(--spl-colors-button-bg-secondary-disabled);box-shadow:inset 0 0 0 1px var(--spl-colors-button-border-secondary-disabled);color:var(--spl-colors-button-text-secondary-disabled)}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,108 @@
|
|
|
1
|
+
import "./index.css";
|
|
1
2
|
import '@radix-ui/themes/styles.css';
|
|
2
3
|
import '@va-scheduling/design-tokens/css';
|
|
3
|
-
import
|
|
4
|
-
import { Theme } from '@radix-ui/themes';
|
|
4
|
+
import { Cross2Icon, ExclamationTriangleIcon, TrashIcon } from '@radix-ui/react-icons';
|
|
5
|
+
import { Button, Spinner, Dialog, IconButton, AlertDialog, Theme } from '@radix-ui/themes';
|
|
6
|
+
import React, { useState, useRef, useEffect, createContext, useLayoutEffect, useMemo, useContext } from 'react';
|
|
7
|
+
|
|
8
|
+
var styles = {"dialog__content":"splDialog-module_dialog__content__t-Zwr","dialog__title":"splDialog-module_dialog__title__hQwUq","dialog__description":"splDialog-module_dialog__description__akkml","dialog__header":"splDialog-module_dialog__header__4evfq","dialog__statusIcon":"splDialog-module_dialog__statusIcon__xY8Y4","dialog__statusIcon--destructive":"splDialog-module_dialog__statusIcon--destructive__gZagF","dialog__statusIcon--warning":"splDialog-module_dialog__statusIcon--warning__53s2a","dialog__body":"splDialog-module_dialog__body__AwXEL","dialog__footer":"splDialog-module_dialog__footer__nOkmx","dialog__close":"splDialog-module_dialog__close__RyLWT","button":"splDialog-module_button__8fRnT","button--primary":"splDialog-module_button--primary__n3DCG","button--destructive":"splDialog-module_button--destructive__Ig1Az","button--secondary":"splDialog-module_button--secondary__heKg3"};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Footer buttons shared by SplDialog and SplAlertDialog.
|
|
12
|
+
* Button ids are `{dialogId}-secondary-btn`, `-tertiary-btn` and `-primary-btn`.
|
|
13
|
+
*/
|
|
14
|
+
const SplDialogFooter = ({ dialogId, secondaryLabel, primaryLabel, primaryLoadingLabel, isPrimaryLoading = false, onPrimaryAction, onSecondaryAction, isPrimaryDisabled = false, isSecondaryDisabled = false, primaryVariant = 'default', tertiaryLabel, onTertiaryAction, isTertiaryDisabled = false, wrapSecondary = (button) => button, }) => {
|
|
15
|
+
const [isPending, setIsPending] = useState(false);
|
|
16
|
+
const isMounted = useRef(true);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
isMounted.current = true;
|
|
19
|
+
return () => { isMounted.current = false; };
|
|
20
|
+
}, []);
|
|
21
|
+
// Cancel is the default secondary label next to a primary button; a close-only footer must opt in via secondaryLabel.
|
|
22
|
+
const secondaryText = secondaryLabel ?? (primaryLabel ? 'Cancel' : undefined);
|
|
23
|
+
if (!primaryLabel && !secondaryText)
|
|
24
|
+
return null;
|
|
25
|
+
const isLoading = isPending || isPrimaryLoading;
|
|
26
|
+
const handlePrimary = async () => {
|
|
27
|
+
setIsPending(true);
|
|
28
|
+
try {
|
|
29
|
+
await onPrimaryAction?.();
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Callers own error handling (e.g. the error store); a rejection only needs to end the loading state.
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
if (isMounted.current)
|
|
36
|
+
setIsPending(false);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const secondaryButton = (React.createElement(Button, { type: "button", variant: "outline", className: `${styles.button} ${styles['button--secondary']}`, id: `${dialogId}-secondary-btn`, disabled: isLoading || isSecondaryDisabled, onClick: onSecondaryAction }, secondaryText));
|
|
40
|
+
return (React.createElement("div", { className: styles.dialog__footer },
|
|
41
|
+
secondaryText && wrapSecondary(secondaryButton),
|
|
42
|
+
tertiaryLabel && onTertiaryAction && (React.createElement(Button, { type: "button", variant: "outline", className: `${styles.button} ${styles['button--secondary']}`, id: `${dialogId}-tertiary-btn`, disabled: isLoading || isTertiaryDisabled, onClick: () => void onTertiaryAction() }, tertiaryLabel)),
|
|
43
|
+
primaryLabel && (React.createElement(Button, { type: "button", id: `${dialogId}-primary-btn`, className: `${styles.button} ${primaryVariant === 'destructive' ? styles['button--destructive'] : styles['button--primary']}`, ...(primaryVariant === 'destructive' ? { color: 'red' } : {}), disabled: isLoading || isPrimaryDisabled, "aria-busy": isLoading, onClick: () => void handlePrimary() },
|
|
44
|
+
isLoading && React.createElement(Spinner, { size: "1" }),
|
|
45
|
+
isLoading && primaryLoadingLabel ? primaryLoadingLabel : primaryLabel))));
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* General purpose modal built on Radix Dialog for content and form dialogs.
|
|
50
|
+
* Use SplAlertDialog instead for confirmations that must be answered.
|
|
51
|
+
*/
|
|
52
|
+
const SplDialog = ({ id, title, description, isOpen, onOpenChange, children, footer, isDismissDisabled = false, hasCloseButton = true, contentClassName, size = '3', maxWidth = '544px', onSecondaryAction, ...actions }) => {
|
|
53
|
+
const preventIfDisabled = (event) => {
|
|
54
|
+
if (isDismissDisabled)
|
|
55
|
+
event.preventDefault();
|
|
56
|
+
};
|
|
57
|
+
return (React.createElement(Dialog.Root, { open: isOpen, onOpenChange: onOpenChange },
|
|
58
|
+
React.createElement(Dialog.Content, { id: id, size: size, maxWidth: maxWidth, className: [styles.dialog__content, contentClassName].filter(Boolean).join(' '), onEscapeKeyDown: preventIfDisabled, onInteractOutside: preventIfDisabled, ...(description ? {} : { 'aria-describedby': undefined }) },
|
|
59
|
+
React.createElement(Dialog.Title, { className: styles.dialog__title }, title),
|
|
60
|
+
!isDismissDisabled && hasCloseButton && (React.createElement(Dialog.Close, null,
|
|
61
|
+
React.createElement(IconButton, { type: "button", id: `${id}-close-btn`, variant: "ghost", color: "gray", className: styles.dialog__close, "aria-label": "Close" },
|
|
62
|
+
React.createElement(Cross2Icon, { "aria-hidden": "true" })))),
|
|
63
|
+
description && (React.createElement(Dialog.Description, { className: styles.dialog__description }, description)),
|
|
64
|
+
React.createElement("div", { className: styles.dialog__body }, children),
|
|
65
|
+
footer ?? (React.createElement(SplDialogFooter, { dialogId: id,
|
|
66
|
+
// Cancel always closes the dialog, even when dismissal is disabled; onSecondaryAction is an extra hook, and actions can't override this handler.
|
|
67
|
+
onSecondaryAction: () => {
|
|
68
|
+
onSecondaryAction?.();
|
|
69
|
+
onOpenChange(false);
|
|
70
|
+
}, ...actions })))));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const statusIconClass = {
|
|
74
|
+
destructive: styles['dialog__statusIcon--destructive'],
|
|
75
|
+
warning: styles['dialog__statusIcon--warning'],
|
|
76
|
+
};
|
|
77
|
+
const wrapInCancel = (button) => React.createElement(AlertDialog.Cancel, null, button);
|
|
78
|
+
/**
|
|
79
|
+
* Confirmation dialog built on Radix AlertDialog, for interruptions that need an explicit answer
|
|
80
|
+
* (delete confirmations, unsaved changes, etc.). Unlike SplDialog it cannot be dismissed by clicking
|
|
81
|
+
* outside, has no X button, and focuses Cancel first so the safe choice is the default.
|
|
82
|
+
* Cancel closes it through `onOpenChange`. It does not auto-close on accept; the caller closes it
|
|
83
|
+
* through `isOpen` once the action succeeds.
|
|
84
|
+
*/
|
|
85
|
+
const SplAlertDialog = ({ id, title, description, isOpen, onOpenChange, children, status, size = '3', maxWidth = '450px', ...actions }) => (React.createElement(AlertDialog.Root, { open: isOpen, onOpenChange: onOpenChange },
|
|
86
|
+
React.createElement(AlertDialog.Content, { id: id, size: size, maxWidth: maxWidth, className: styles.dialog__content },
|
|
87
|
+
React.createElement("div", { className: styles.dialog__header },
|
|
88
|
+
status && (React.createElement("span", { id: `${id}-status-icon`, "aria-hidden": "true", className: `${styles.dialog__statusIcon} ${statusIconClass[status]}` }, status === 'warning' ? React.createElement(ExclamationTriangleIcon, null) : React.createElement(TrashIcon, null))),
|
|
89
|
+
React.createElement(AlertDialog.Title, { className: styles.dialog__title }, title)),
|
|
90
|
+
React.createElement(AlertDialog.Description, { className: styles.dialog__description }, description),
|
|
91
|
+
children && React.createElement("div", { className: styles.dialog__body }, children),
|
|
92
|
+
React.createElement(SplDialogFooter, { dialogId: id, wrapSecondary: wrapInCancel, ...actions }))));
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Delete confirmation: SplAlertDialog with the red trash icon and destructive primary button.
|
|
96
|
+
*/
|
|
97
|
+
const SplDeleteAlertDialog = ({ id, itemName, itemNameId = `${id}-item-name`, primaryLabel = 'Delete', primaryLoadingLabel = 'Deleting...', secondaryLabel = 'Cancel', ...rest }) => (React.createElement(SplAlertDialog, { id: id, status: "destructive", primaryVariant: "destructive", primaryLabel: primaryLabel, primaryLoadingLabel: primaryLoadingLabel, secondaryLabel: secondaryLabel, description: React.createElement(React.Fragment, null,
|
|
98
|
+
"Please confirm deletion of: ",
|
|
99
|
+
React.createElement("strong", { id: itemNameId }, itemName)), ...rest }));
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Warning confirmation (e.g. sensitive record access): SplAlertDialog with the amber warning icon
|
|
103
|
+
* and the standard primary button.
|
|
104
|
+
*/
|
|
105
|
+
const SplWarningAlertDialog = ({ primaryLabel = 'Continue', secondaryLabel = 'Cancel', ...rest }) => (React.createElement(SplAlertDialog, { status: "warning", primaryLabel: primaryLabel, secondaryLabel: secondaryLabel, ...rest }));
|
|
5
106
|
|
|
6
107
|
const DEFAULT_SPL_THEME = "light";
|
|
7
108
|
const DARK_SCHEME_QUERY = "(prefers-color-scheme: dark)";
|
|
@@ -93,5 +194,5 @@ const SplThemeProvider = ({ children, preference: controlledPreference, defaultP
|
|
|
93
194
|
React.createElement(Theme, { appearance: "inherit", grayColor: "slate", hasBackground: false }, children)));
|
|
94
195
|
};
|
|
95
196
|
|
|
96
|
-
export { SplThemeProvider, applyInitialSplTheme, applySplTheme, getSystemTheme, isSplThemePreference, resolveSplTheme, useSplTheme };
|
|
197
|
+
export { SplAlertDialog, SplDeleteAlertDialog, SplDialog, SplThemeProvider, SplWarningAlertDialog, applyInitialSplTheme, applySplTheme, getSystemTheme, isSplThemePreference, resolveSplTheme, useSplTheme };
|
|
97
198
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/theme/themeUtils.ts","../../src/components/spl-theme-provider/SplThemeProvider.tsx"],"sourcesContent":["export type SplTheme = \"light\" | \"dark\";\r\nexport type SplThemePreference = SplTheme | \"system\";\r\n\r\nexport const DEFAULT_SPL_THEME: SplTheme = \"light\";\r\nexport const DARK_SCHEME_QUERY = \"(prefers-color-scheme: dark)\";\r\n\r\nexport function isSplThemePreference(value: unknown): value is SplThemePreference {\r\n return value === \"light\" || value === \"dark\" || value === \"system\";\r\n}\r\n\r\nexport function themeFromMatches(matches: boolean): SplTheme {\r\n return matches ? \"dark\" : \"light\";\r\n}\r\n\r\n/** OS/browser color scheme, falling back to light when matchMedia is unavailable. */\r\nexport function getSystemTheme(): SplTheme {\r\n try {\r\n return themeFromMatches(Boolean(window.matchMedia?.(DARK_SCHEME_QUERY)?.matches));\r\n } catch {\r\n return DEFAULT_SPL_THEME;\r\n }\r\n}\r\n\r\nexport function resolveSplTheme(preference: SplThemePreference): SplTheme {\r\n return preference === \"system\" ? getSystemTheme() : preference;\r\n}\r\n\r\n/**\r\n * Applies a theme to the root element: [data-theme] for app styles and the `dark` class that\r\n * @va-scheduling/design-tokens and the Radix dark scales key off of. `color-scheme` is not set.\r\n */\r\nexport function applySplTheme(theme: SplTheme, root: HTMLElement = document.documentElement) {\r\n const safeTheme: SplTheme = theme === \"dark\" ? \"dark\" : DEFAULT_SPL_THEME;\r\n root.setAttribute(\"data-theme\", safeTheme);\r\n root.classList.toggle(\"dark\", safeTheme === \"dark\");\r\n}\r\n\r\n/**\r\n * Applies the stored theme before React renders, to avoid a flash. The app supplies how to read its\r\n * stored preference, since storage differs between apps.\r\n */\r\nexport function applyInitialSplTheme(\r\n readPreference: () => SplThemePreference | undefined = () => undefined,\r\n) {\r\n let preference: SplThemePreference | undefined;\r\n try {\r\n preference = readPreference();\r\n } catch {\r\n preference = undefined;\r\n }\r\n applySplTheme(resolveSplTheme(isSplThemePreference(preference) ? preference : DEFAULT_SPL_THEME));\r\n}\r\n","import React, {\r\n createContext,\r\n useContext,\r\n useEffect,\r\n useLayoutEffect,\r\n useMemo,\r\n useState,\r\n} from \"react\";\r\nimport { Theme } from \"@radix-ui/themes\";\r\nimport {\r\n applySplTheme,\r\n DARK_SCHEME_QUERY,\r\n DEFAULT_SPL_THEME,\r\n getSystemTheme,\r\n SplTheme,\r\n SplThemePreference,\r\n themeFromMatches,\r\n} from \"../../theme/themeUtils\";\r\n\r\nexport interface SplThemeContextValue {\r\n /** The stored preference: 'light', 'dark', or 'system' (follow the OS/browser). */\r\n preference: SplThemePreference;\r\n /** The theme currently applied to the root element. */\r\n theme: SplTheme;\r\n setPreference: (preference: SplThemePreference) => void;\r\n}\r\n\r\nexport interface SplThemeProviderProps {\r\n children?: React.ReactNode;\r\n /** Controlled preference. When set, the app owns storage and must update it in onPreferenceChange. */\r\n preference?: SplThemePreference;\r\n /** Initial preference when uncontrolled. Defaults to light. */\r\n defaultPreference?: SplThemePreference;\r\n onPreferenceChange?: (preference: SplThemePreference) => void;\r\n}\r\n\r\nconst SplThemeContext = createContext<SplThemeContextValue | undefined>(undefined);\r\n\r\nexport function useSplTheme(): SplThemeContextValue {\r\n const context = useContext(SplThemeContext);\r\n if (context === undefined) {\r\n throw new Error(\"useSplTheme must be used within SplThemeProvider\");\r\n }\r\n return context;\r\n}\r\n\r\n/**\r\n * Applies the light/dark theme to the root element and wraps children in a Radix <Theme>\r\n * (appearance=\"inherit\" follows the .dark class; grayColor=\"slate\" matches the design-tokens base scale).\r\n * The OS/browser scheme is only followed, with live updates, when the preference is 'system'.\r\n */\r\nconst SplThemeProvider = ({\r\n children,\r\n preference: controlledPreference,\r\n defaultPreference = DEFAULT_SPL_THEME,\r\n onPreferenceChange,\r\n}: SplThemeProviderProps) => {\r\n const [internalPreference, setInternalPreference] = useState<SplThemePreference>(defaultPreference);\r\n const preference = controlledPreference ?? internalPreference;\r\n const [systemTheme, setSystemTheme] = useState<SplTheme>(getSystemTheme);\r\n\r\n useEffect(() => {\r\n if (preference !== \"system\" || typeof window.matchMedia !== \"function\") {\r\n return undefined;\r\n }\r\n\r\n const mediaQuery = window.matchMedia(DARK_SCHEME_QUERY);\r\n const handleChange = () => setSystemTheme(getSystemTheme());\r\n\r\n // systemTheme goes stale while an explicit preference is set (no listener), so resync here\r\n setSystemTheme(themeFromMatches(mediaQuery.matches));\r\n mediaQuery.addEventListener?.(\"change\", handleChange);\r\n return () => mediaQuery.removeEventListener?.(\"change\", handleChange);\r\n }, [preference]);\r\n\r\n const theme: SplTheme = preference === \"system\" ? systemTheme : preference;\r\n\r\n useLayoutEffect(() => {\r\n applySplTheme(theme);\r\n }, [theme]);\r\n\r\n const value = useMemo<SplThemeContextValue>(\r\n () => ({\r\n preference,\r\n theme,\r\n setPreference: (next: SplThemePreference) => {\r\n if (controlledPreference === undefined) {\r\n setInternalPreference(next);\r\n }\r\n onPreferenceChange?.(next);\r\n },\r\n }),\r\n [preference, theme, controlledPreference, onPreferenceChange],\r\n );\r\n\r\n return (\r\n <SplThemeContext.Provider value={value}>\r\n <Theme appearance=\"inherit\" grayColor=\"slate\" hasBackground={false}>\r\n {children}\r\n </Theme>\r\n </SplThemeContext.Provider>\r\n );\r\n};\r\n\r\nexport default SplThemeProvider;\r\n"],"names":[],"mappings":";;;;;AAGO,MAAM,iBAAiB,GAAa,OAAO;AAC3C,MAAM,iBAAiB,GAAG,8BAA8B;AAEzD,SAAU,oBAAoB,CAAC,KAAc,EAAA;IACjD,OAAO,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,QAAQ;AACpE;AAEM,SAAU,gBAAgB,CAAC,OAAgB,EAAA;IAC/C,OAAO,OAAO,GAAG,MAAM,GAAG,OAAO;AACnC;AAEA;SACgB,cAAc,GAAA;AAC5B,IAAA,IAAI;AACF,QAAA,OAAO,gBAAgB,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,GAAG,iBAAiB,CAAC,EAAE,OAAO,CAAC,CAAC;IACnF;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,iBAAiB;IAC1B;AACF;AAEM,SAAU,eAAe,CAAC,UAA8B,EAAA;AAC5D,IAAA,OAAO,UAAU,KAAK,QAAQ,GAAG,cAAc,EAAE,GAAG,UAAU;AAChE;AAEA;;;AAGG;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","sources":["../../src/components/spl-dialog/SplDialogFooter.tsx","../../src/components/spl-dialog/SplDialog.tsx","../../src/components/spl-dialog/SplAlertDialog.tsx","../../src/components/spl-dialog/SplDeleteAlertDialog.tsx","../../src/components/spl-dialog/SplWarningAlertDialog.tsx","../../src/theme/themeUtils.ts","../../src/components/spl-theme-provider/SplThemeProvider.tsx"],"sourcesContent":["import { Button, Spinner } from '@radix-ui/themes';\r\nimport React, { ReactNode, useEffect, useRef, useState } from 'react';\r\n\r\nimport styles from './splDialog.module.css';\r\n\r\nexport type SplDialogActionsProps = {\r\n /** Text for the cancel/close button. Defaults to \"Cancel\" when a primary button is shown. Provide it alone (e.g. \"Close\") for a close-only footer. */\r\n secondaryLabel?: string;\r\n /** Text for the accept button. */\r\n primaryLabel?: string;\r\n /** Text for the accept button while it is loading. */\r\n primaryLoadingLabel?: string;\r\n /** Forces the primary button into its loading state, for loading driven by a store or parent. Loading from `onPrimaryAction` promises is tracked automatically. */\r\n isPrimaryLoading?: boolean;\r\n /** Called on accept. If it returns a promise the primary button shows a loading state until it settles. */\r\n onPrimaryAction?: () => void | Promise<void>;\r\n /** Called on cancel. The dialog also closes through `onOpenChange`. */\r\n onSecondaryAction?: () => void;\r\n isPrimaryDisabled?: boolean;\r\n isSecondaryDisabled?: boolean;\r\n /** Visual treatment of the primary button. `destructive` is for deletions. */\r\n primaryVariant?: 'default' | 'destructive';\r\n /** Optional extra button between secondary and primary. */\r\n tertiaryLabel?: string;\r\n onTertiaryAction?: () => void | Promise<void>;\r\n isTertiaryDisabled?: boolean;\r\n};\r\n\r\ntype SplDialogFooterProps = SplDialogActionsProps & {\r\n dialogId: string;\r\n /** Wraps the secondary button so Radix primitives (e.g. AlertDialog.Cancel) can own it. */\r\n wrapSecondary?: (button: ReactNode) => ReactNode;\r\n};\r\n\r\n/**\r\n * Footer buttons shared by SplDialog and SplAlertDialog.\r\n * Button ids are `{dialogId}-secondary-btn`, `-tertiary-btn` and `-primary-btn`.\r\n */\r\nconst SplDialogFooter = ({\r\n dialogId,\r\n secondaryLabel,\r\n primaryLabel,\r\n primaryLoadingLabel,\r\n isPrimaryLoading = false,\r\n onPrimaryAction,\r\n onSecondaryAction,\r\n isPrimaryDisabled = false,\r\n isSecondaryDisabled = false,\r\n primaryVariant = 'default',\r\n tertiaryLabel,\r\n onTertiaryAction,\r\n isTertiaryDisabled = false,\r\n wrapSecondary = (button) => button,\r\n}: SplDialogFooterProps) => {\r\n const [isPending, setIsPending] = useState(false);\r\n const isMounted = useRef(true);\r\n\r\n useEffect(() => {\r\n isMounted.current = true;\r\n return () => { isMounted.current = false; };\r\n }, []);\r\n\r\n // Cancel is the default secondary label next to a primary button; a close-only footer must opt in via secondaryLabel.\r\n const secondaryText = secondaryLabel ?? (primaryLabel ? 'Cancel' : undefined);\r\n if (!primaryLabel && !secondaryText) return null;\r\n\r\n const isLoading = isPending || isPrimaryLoading;\r\n\r\n const handlePrimary = async () => {\r\n setIsPending(true);\r\n try {\r\n await onPrimaryAction?.();\r\n } catch {\r\n // Callers own error handling (e.g. the error store); a rejection only needs to end the loading state.\r\n } finally {\r\n if (isMounted.current) setIsPending(false);\r\n }\r\n };\r\n\r\n const secondaryButton = (\r\n <Button\r\n type=\"button\"\r\n variant=\"outline\"\r\n className={`${styles.button} ${styles['button--secondary']}`}\r\n id={`${dialogId}-secondary-btn`}\r\n disabled={isLoading || isSecondaryDisabled}\r\n onClick={onSecondaryAction}\r\n >\r\n {secondaryText}\r\n </Button>\r\n );\r\n\r\n return (\r\n <div className={styles.dialog__footer}>\r\n {secondaryText && wrapSecondary(secondaryButton)}\r\n {tertiaryLabel && onTertiaryAction && (\r\n <Button\r\n type=\"button\"\r\n variant=\"outline\"\r\n className={`${styles.button} ${styles['button--secondary']}`}\r\n id={`${dialogId}-tertiary-btn`}\r\n disabled={isLoading || isTertiaryDisabled}\r\n onClick={() => void onTertiaryAction()}\r\n >\r\n {tertiaryLabel}\r\n </Button>\r\n )}\r\n {primaryLabel && (\r\n <Button\r\n type=\"button\"\r\n id={`${dialogId}-primary-btn`}\r\n className={`${styles.button} ${primaryVariant === 'destructive' ? styles['button--destructive'] : styles['button--primary']}`}\r\n {...(primaryVariant === 'destructive' ? { color: 'red' as const } : {})}\r\n disabled={isLoading || isPrimaryDisabled}\r\n aria-busy={isLoading}\r\n onClick={() => void handlePrimary()}\r\n >\r\n {/* Radix's `loading` prop hides the label; render the spinner beside it instead. */}\r\n {isLoading && <Spinner size=\"1\" />}\r\n {isLoading && primaryLoadingLabel ? primaryLoadingLabel : primaryLabel}\r\n </Button>\r\n )}\r\n </div>\r\n );\r\n};\r\n\r\nexport default SplDialogFooter;\r\n","import { Cross2Icon } from '@radix-ui/react-icons';\r\nimport { Dialog, IconButton } from '@radix-ui/themes';\r\nimport React, { ReactNode } from 'react';\r\n\r\nimport SplDialogFooter, { SplDialogActionsProps } from './SplDialogFooter';\r\nimport { SplDialogSizeProps } from './splDialogSize';\r\nimport styles from './splDialog.module.css';\r\n\r\nexport type SplDialogProps = SplDialogActionsProps & SplDialogSizeProps & {\r\n /** Unique id; the content element gets this id and footer buttons derive theirs from it. */\r\n id: string;\r\n title: string;\r\n /** Optional description announced by screen readers. */\r\n description?: string;\r\n isOpen: boolean;\r\n onOpenChange: (isOpen: boolean) => void;\r\n children: ReactNode;\r\n /** Replace the built-in footer entirely (e.g. for forms that own their buttons). */\r\n footer?: ReactNode;\r\n /** Prevent closing via Escape, overlay click, or the X button. */\r\n isDismissDisabled?: boolean;\r\n /** Show the X button in the corner. Defaults to true; Escape and overlay click still close the dialog when false. */\r\n hasCloseButton?: boolean;\r\n /** Extra class on the content panel, for width overrides. */\r\n contentClassName?: string;\r\n};\r\n\r\n/**\r\n * General purpose modal built on Radix Dialog for content and form dialogs.\r\n * Use SplAlertDialog instead for confirmations that must be answered.\r\n */\r\nconst SplDialog = ({\r\n id,\r\n title,\r\n description,\r\n isOpen,\r\n onOpenChange,\r\n children,\r\n footer,\r\n isDismissDisabled = false,\r\n hasCloseButton = true,\r\n contentClassName,\r\n size = '3',\r\n maxWidth = '544px',\r\n onSecondaryAction,\r\n ...actions\r\n}: SplDialogProps) => {\r\n const preventIfDisabled = (event: Event) => {\r\n if (isDismissDisabled) event.preventDefault();\r\n };\r\n\r\n return (\r\n <Dialog.Root open={isOpen} onOpenChange={onOpenChange}>\r\n <Dialog.Content\r\n id={id}\r\n size={size}\r\n maxWidth={maxWidth}\r\n className={[styles.dialog__content, contentClassName].filter(Boolean).join(' ')}\r\n onEscapeKeyDown={preventIfDisabled}\r\n onInteractOutside={preventIfDisabled}\r\n {...(description ? {} : { 'aria-describedby': undefined })}\r\n >\r\n <Dialog.Title className={styles.dialog__title}>{title}</Dialog.Title>\r\n {!isDismissDisabled && hasCloseButton && (\r\n <Dialog.Close>\r\n <IconButton\r\n type=\"button\"\r\n id={`${id}-close-btn`}\r\n variant=\"ghost\"\r\n color=\"gray\"\r\n className={styles.dialog__close}\r\n aria-label=\"Close\"\r\n >\r\n <Cross2Icon aria-hidden=\"true\" />\r\n </IconButton>\r\n </Dialog.Close>\r\n )}\r\n {description && (\r\n <Dialog.Description className={styles.dialog__description}>{description}</Dialog.Description>\r\n )}\r\n <div className={styles.dialog__body}>{children}</div>\r\n {footer ?? (\r\n <SplDialogFooter\r\n dialogId={id}\r\n // Cancel always closes the dialog, even when dismissal is disabled; onSecondaryAction is an extra hook, and actions can't override this handler.\r\n onSecondaryAction={() => {\r\n onSecondaryAction?.();\r\n onOpenChange(false);\r\n }}\r\n {...actions}\r\n />\r\n )}\r\n </Dialog.Content>\r\n </Dialog.Root>\r\n );\r\n};\r\n\r\nexport default SplDialog;\r\n","import { ExclamationTriangleIcon, TrashIcon } from '@radix-ui/react-icons';\r\nimport { AlertDialog } from '@radix-ui/themes';\r\nimport React, { ReactNode } from 'react';\r\n\r\nimport SplDialogFooter, { SplDialogActionsProps } from './SplDialogFooter';\r\nimport { SplDialogSizeProps } from './splDialogSize';\r\nimport styles from './splDialog.module.css';\r\n\r\nexport type SplAlertDialogProps = Omit<SplDialogActionsProps, 'primaryLabel'> & SplDialogSizeProps & {\r\n /** Unique id; the content element gets this id and footer buttons derive theirs from it. */\r\n id: string;\r\n title: string;\r\n /** Required: alert dialogs must tell the user what they are confirming. May include inline markup. */\r\n description: ReactNode;\r\n isOpen: boolean;\r\n onOpenChange: (isOpen: boolean) => void;\r\n /** Required: an alert dialog always has an accept action. */\r\n primaryLabel: string;\r\n /** Optional extra content below the description (e.g. an error alert). */\r\n children?: ReactNode;\r\n /** Shows a leading icon before the title: a red trash can for 'destructive', an amber triangle for 'warning'. */\r\n status?: 'destructive' | 'warning';\r\n};\r\n\r\nconst statusIconClass = {\r\n destructive: styles['dialog__statusIcon--destructive'],\r\n warning: styles['dialog__statusIcon--warning'],\r\n};\r\n\r\nconst wrapInCancel = (button: ReactNode) => <AlertDialog.Cancel>{button}</AlertDialog.Cancel>;\r\n\r\n/**\r\n * Confirmation dialog built on Radix AlertDialog, for interruptions that need an explicit answer\r\n * (delete confirmations, unsaved changes, etc.). Unlike SplDialog it cannot be dismissed by clicking\r\n * outside, has no X button, and focuses Cancel first so the safe choice is the default.\r\n * Cancel closes it through `onOpenChange`. It does not auto-close on accept; the caller closes it\r\n * through `isOpen` once the action succeeds.\r\n */\r\nconst SplAlertDialog = ({\r\n id,\r\n title,\r\n description,\r\n isOpen,\r\n onOpenChange,\r\n children,\r\n status,\r\n size = '3',\r\n maxWidth = '450px',\r\n ...actions\r\n}: SplAlertDialogProps) => (\r\n <AlertDialog.Root open={isOpen} onOpenChange={onOpenChange}>\r\n <AlertDialog.Content\r\n id={id}\r\n size={size}\r\n maxWidth={maxWidth}\r\n className={styles.dialog__content}\r\n >\r\n <div className={styles.dialog__header}>\r\n {status && (\r\n <span\r\n id={`${id}-status-icon`}\r\n aria-hidden=\"true\"\r\n className={`${styles.dialog__statusIcon} ${statusIconClass[status]}`}\r\n >\r\n {status === 'warning' ? <ExclamationTriangleIcon /> : <TrashIcon />}\r\n </span>\r\n )}\r\n <AlertDialog.Title className={styles.dialog__title}>{title}</AlertDialog.Title>\r\n </div>\r\n <AlertDialog.Description className={styles.dialog__description}>\r\n {description}\r\n </AlertDialog.Description>\r\n {children && <div className={styles.dialog__body}>{children}</div>}\r\n <SplDialogFooter\r\n dialogId={id}\r\n wrapSecondary={wrapInCancel}\r\n {...actions}\r\n />\r\n </AlertDialog.Content>\r\n </AlertDialog.Root>\r\n);\r\n\r\nexport default SplAlertDialog;\r\n","import React from 'react';\r\n\r\nimport SplAlertDialog, { SplAlertDialogProps } from './SplAlertDialog';\r\n\r\nexport type SplDeleteAlertDialogProps = Omit<SplAlertDialogProps, 'status' | 'primaryVariant' | 'description' | 'primaryLabel'> & {\r\n /** Name of the item being deleted, shown in bold after \"Please confirm deletion of:\". */\r\n itemName: string;\r\n /** Id for the bold item name element. Defaults to `{id}-item-name`. */\r\n itemNameId?: string;\r\n /** Defaults to \"Delete\". */\r\n primaryLabel?: string;\r\n};\r\n\r\n/**\r\n * Delete confirmation: SplAlertDialog with the red trash icon and destructive primary button.\r\n */\r\nconst SplDeleteAlertDialog = ({\r\n id,\r\n itemName,\r\n itemNameId = `${id}-item-name`,\r\n primaryLabel = 'Delete',\r\n primaryLoadingLabel = 'Deleting...',\r\n secondaryLabel = 'Cancel',\r\n ...rest\r\n}: SplDeleteAlertDialogProps) => (\r\n <SplAlertDialog\r\n id={id}\r\n status=\"destructive\"\r\n primaryVariant=\"destructive\"\r\n primaryLabel={primaryLabel}\r\n primaryLoadingLabel={primaryLoadingLabel}\r\n secondaryLabel={secondaryLabel}\r\n description={\r\n <>\r\n Please confirm deletion of: <strong id={itemNameId}>{itemName}</strong>\r\n </>\r\n }\r\n {...rest}\r\n />\r\n);\r\n\r\nexport default SplDeleteAlertDialog;\r\n","import React from 'react';\r\n\r\nimport SplAlertDialog, { SplAlertDialogProps } from './SplAlertDialog';\r\n\r\nexport type SplWarningAlertDialogProps = Omit<SplAlertDialogProps, 'status' | 'primaryVariant' | 'primaryLabel'> & {\r\n /** Defaults to \"Continue\". */\r\n primaryLabel?: string;\r\n};\r\n\r\n/**\r\n * Warning confirmation (e.g. sensitive record access): SplAlertDialog with the amber warning icon\r\n * and the standard primary button.\r\n */\r\nconst SplWarningAlertDialog = ({\r\n primaryLabel = 'Continue',\r\n secondaryLabel = 'Cancel',\r\n ...rest\r\n}: SplWarningAlertDialogProps) => (\r\n <SplAlertDialog status=\"warning\" primaryLabel={primaryLabel} secondaryLabel={secondaryLabel} {...rest} />\r\n);\r\n\r\nexport default SplWarningAlertDialog;\r\n","export type SplTheme = \"light\" | \"dark\";\r\nexport type SplThemePreference = SplTheme | \"system\";\r\n\r\nexport const DEFAULT_SPL_THEME: SplTheme = \"light\";\r\nexport const DARK_SCHEME_QUERY = \"(prefers-color-scheme: dark)\";\r\n\r\nexport function isSplThemePreference(value: unknown): value is SplThemePreference {\r\n return value === \"light\" || value === \"dark\" || value === \"system\";\r\n}\r\n\r\nexport function themeFromMatches(matches: boolean): SplTheme {\r\n return matches ? \"dark\" : \"light\";\r\n}\r\n\r\n/** OS/browser color scheme, falling back to light when matchMedia is unavailable. */\r\nexport function getSystemTheme(): SplTheme {\r\n try {\r\n return themeFromMatches(Boolean(window.matchMedia?.(DARK_SCHEME_QUERY)?.matches));\r\n } catch {\r\n return DEFAULT_SPL_THEME;\r\n }\r\n}\r\n\r\nexport function resolveSplTheme(preference: SplThemePreference): SplTheme {\r\n return preference === \"system\" ? getSystemTheme() : preference;\r\n}\r\n\r\n/**\r\n * Applies a theme to the root element: [data-theme] for app styles and the `dark` class that\r\n * @va-scheduling/design-tokens and the Radix dark scales key off of. `color-scheme` is not set.\r\n */\r\nexport function applySplTheme(theme: SplTheme, root: HTMLElement = document.documentElement) {\r\n const safeTheme: SplTheme = theme === \"dark\" ? \"dark\" : DEFAULT_SPL_THEME;\r\n root.setAttribute(\"data-theme\", safeTheme);\r\n root.classList.toggle(\"dark\", safeTheme === \"dark\");\r\n}\r\n\r\n/**\r\n * Applies the stored theme before React renders, to avoid a flash. The app supplies how to read its\r\n * stored preference, since storage differs between apps.\r\n */\r\nexport function applyInitialSplTheme(\r\n readPreference: () => SplThemePreference | undefined = () => undefined,\r\n) {\r\n let preference: SplThemePreference | undefined;\r\n try {\r\n preference = readPreference();\r\n } catch {\r\n preference = undefined;\r\n }\r\n applySplTheme(resolveSplTheme(isSplThemePreference(preference) ? preference : DEFAULT_SPL_THEME));\r\n}\r\n","import React, {\r\n createContext,\r\n useContext,\r\n useEffect,\r\n useLayoutEffect,\r\n useMemo,\r\n useState,\r\n} from \"react\";\r\nimport { Theme } from \"@radix-ui/themes\";\r\nimport {\r\n applySplTheme,\r\n DARK_SCHEME_QUERY,\r\n DEFAULT_SPL_THEME,\r\n getSystemTheme,\r\n SplTheme,\r\n SplThemePreference,\r\n themeFromMatches,\r\n} from \"../../theme/themeUtils\";\r\n\r\nexport interface SplThemeContextValue {\r\n /** The stored preference: 'light', 'dark', or 'system' (follow the OS/browser). */\r\n preference: SplThemePreference;\r\n /** The theme currently applied to the root element. */\r\n theme: SplTheme;\r\n setPreference: (preference: SplThemePreference) => void;\r\n}\r\n\r\nexport interface SplThemeProviderProps {\r\n children?: React.ReactNode;\r\n /** Controlled preference. When set, the app owns storage and must update it in onPreferenceChange. */\r\n preference?: SplThemePreference;\r\n /** Initial preference when uncontrolled. Defaults to light. */\r\n defaultPreference?: SplThemePreference;\r\n onPreferenceChange?: (preference: SplThemePreference) => void;\r\n}\r\n\r\nconst SplThemeContext = createContext<SplThemeContextValue | undefined>(undefined);\r\n\r\nexport function useSplTheme(): SplThemeContextValue {\r\n const context = useContext(SplThemeContext);\r\n if (context === undefined) {\r\n throw new Error(\"useSplTheme must be used within SplThemeProvider\");\r\n }\r\n return context;\r\n}\r\n\r\n/**\r\n * Applies the light/dark theme to the root element and wraps children in a Radix <Theme>\r\n * (appearance=\"inherit\" follows the .dark class; grayColor=\"slate\" matches the design-tokens base scale).\r\n * The OS/browser scheme is only followed, with live updates, when the preference is 'system'.\r\n */\r\nconst SplThemeProvider = ({\r\n children,\r\n preference: controlledPreference,\r\n defaultPreference = DEFAULT_SPL_THEME,\r\n onPreferenceChange,\r\n}: SplThemeProviderProps) => {\r\n const [internalPreference, setInternalPreference] = useState<SplThemePreference>(defaultPreference);\r\n const preference = controlledPreference ?? internalPreference;\r\n const [systemTheme, setSystemTheme] = useState<SplTheme>(getSystemTheme);\r\n\r\n useEffect(() => {\r\n if (preference !== \"system\" || typeof window.matchMedia !== \"function\") {\r\n return undefined;\r\n }\r\n\r\n const mediaQuery = window.matchMedia(DARK_SCHEME_QUERY);\r\n const handleChange = () => setSystemTheme(getSystemTheme());\r\n\r\n // systemTheme goes stale while an explicit preference is set (no listener), so resync here\r\n setSystemTheme(themeFromMatches(mediaQuery.matches));\r\n mediaQuery.addEventListener?.(\"change\", handleChange);\r\n return () => mediaQuery.removeEventListener?.(\"change\", handleChange);\r\n }, [preference]);\r\n\r\n const theme: SplTheme = preference === \"system\" ? systemTheme : preference;\r\n\r\n useLayoutEffect(() => {\r\n applySplTheme(theme);\r\n }, [theme]);\r\n\r\n const value = useMemo<SplThemeContextValue>(\r\n () => ({\r\n preference,\r\n theme,\r\n setPreference: (next: SplThemePreference) => {\r\n if (controlledPreference === undefined) {\r\n setInternalPreference(next);\r\n }\r\n onPreferenceChange?.(next);\r\n },\r\n }),\r\n [preference, theme, controlledPreference, onPreferenceChange],\r\n );\r\n\r\n return (\r\n <SplThemeContext.Provider value={value}>\r\n <Theme appearance=\"inherit\" grayColor=\"slate\" hasBackground={false}>\r\n {children}\r\n </Theme>\r\n </SplThemeContext.Provider>\r\n );\r\n};\r\n\r\nexport default SplThemeProvider;\r\n"],"names":[],"mappings":";;;;;;;;;AAkCA;;;AAGG;AACH,MAAM,eAAe,GAAG,CAAC,EACvB,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,GAAG,KAAK,EACxB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,GAAG,KAAK,EACzB,mBAAmB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AK,EAAA,EAC/D,QAAQ,CACH,CACiB;AAE/B;;"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
export { SplDialog, SplAlertDialog, SplDeleteAlertDialog, SplWarningAlertDialog, } from "./spl-dialog";
|
|
2
|
+
export type { SplDialogProps, SplAlertDialogProps, SplDeleteAlertDialogProps, SplWarningAlertDialogProps, SplDialogActionsProps, SplDialogSize, SplDialogSizeProps, } from "./spl-dialog";
|
|
1
3
|
export { default as SplThemeProvider, useSplTheme } from "./spl-theme-provider";
|
|
2
4
|
export type { SplThemeProviderProps, SplThemeContextValue } from "./spl-theme-provider";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { SplDialogActionsProps } from './SplDialogFooter';
|
|
3
|
+
import { SplDialogSizeProps } from './splDialogSize';
|
|
4
|
+
export type SplAlertDialogProps = Omit<SplDialogActionsProps, 'primaryLabel'> & SplDialogSizeProps & {
|
|
5
|
+
/** Unique id; the content element gets this id and footer buttons derive theirs from it. */
|
|
6
|
+
id: string;
|
|
7
|
+
title: string;
|
|
8
|
+
/** Required: alert dialogs must tell the user what they are confirming. May include inline markup. */
|
|
9
|
+
description: ReactNode;
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
onOpenChange: (isOpen: boolean) => void;
|
|
12
|
+
/** Required: an alert dialog always has an accept action. */
|
|
13
|
+
primaryLabel: string;
|
|
14
|
+
/** Optional extra content below the description (e.g. an error alert). */
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
/** Shows a leading icon before the title: a red trash can for 'destructive', an amber triangle for 'warning'. */
|
|
17
|
+
status?: 'destructive' | 'warning';
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Confirmation dialog built on Radix AlertDialog, for interruptions that need an explicit answer
|
|
21
|
+
* (delete confirmations, unsaved changes, etc.). Unlike SplDialog it cannot be dismissed by clicking
|
|
22
|
+
* outside, has no X button, and focuses Cancel first so the safe choice is the default.
|
|
23
|
+
* Cancel closes it through `onOpenChange`. It does not auto-close on accept; the caller closes it
|
|
24
|
+
* through `isOpen` once the action succeeds.
|
|
25
|
+
*/
|
|
26
|
+
declare const SplAlertDialog: ({ id, title, description, isOpen, onOpenChange, children, status, size, maxWidth, ...actions }: SplAlertDialogProps) => React.JSX.Element;
|
|
27
|
+
export default SplAlertDialog;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SplAlertDialogProps } from './SplAlertDialog';
|
|
3
|
+
export type SplDeleteAlertDialogProps = Omit<SplAlertDialogProps, 'status' | 'primaryVariant' | 'description' | 'primaryLabel'> & {
|
|
4
|
+
/** Name of the item being deleted, shown in bold after "Please confirm deletion of:". */
|
|
5
|
+
itemName: string;
|
|
6
|
+
/** Id for the bold item name element. Defaults to `{id}-item-name`. */
|
|
7
|
+
itemNameId?: string;
|
|
8
|
+
/** Defaults to "Delete". */
|
|
9
|
+
primaryLabel?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Delete confirmation: SplAlertDialog with the red trash icon and destructive primary button.
|
|
13
|
+
*/
|
|
14
|
+
declare const SplDeleteAlertDialog: ({ id, itemName, itemNameId, primaryLabel, primaryLoadingLabel, secondaryLabel, ...rest }: SplDeleteAlertDialogProps) => React.JSX.Element;
|
|
15
|
+
export default SplDeleteAlertDialog;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { SplDialogActionsProps } from './SplDialogFooter';
|
|
3
|
+
import { SplDialogSizeProps } from './splDialogSize';
|
|
4
|
+
export type SplDialogProps = SplDialogActionsProps & SplDialogSizeProps & {
|
|
5
|
+
/** Unique id; the content element gets this id and footer buttons derive theirs from it. */
|
|
6
|
+
id: string;
|
|
7
|
+
title: string;
|
|
8
|
+
/** Optional description announced by screen readers. */
|
|
9
|
+
description?: string;
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
onOpenChange: (isOpen: boolean) => void;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
/** Replace the built-in footer entirely (e.g. for forms that own their buttons). */
|
|
14
|
+
footer?: ReactNode;
|
|
15
|
+
/** Prevent closing via Escape, overlay click, or the X button. */
|
|
16
|
+
isDismissDisabled?: boolean;
|
|
17
|
+
/** Show the X button in the corner. Defaults to true; Escape and overlay click still close the dialog when false. */
|
|
18
|
+
hasCloseButton?: boolean;
|
|
19
|
+
/** Extra class on the content panel, for width overrides. */
|
|
20
|
+
contentClassName?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* General purpose modal built on Radix Dialog for content and form dialogs.
|
|
24
|
+
* Use SplAlertDialog instead for confirmations that must be answered.
|
|
25
|
+
*/
|
|
26
|
+
declare const SplDialog: ({ id, title, description, isOpen, onOpenChange, children, footer, isDismissDisabled, hasCloseButton, contentClassName, size, maxWidth, onSecondaryAction, ...actions }: SplDialogProps) => React.JSX.Element;
|
|
27
|
+
export default SplDialog;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
export type SplDialogActionsProps = {
|
|
3
|
+
/** Text for the cancel/close button. Defaults to "Cancel" when a primary button is shown. Provide it alone (e.g. "Close") for a close-only footer. */
|
|
4
|
+
secondaryLabel?: string;
|
|
5
|
+
/** Text for the accept button. */
|
|
6
|
+
primaryLabel?: string;
|
|
7
|
+
/** Text for the accept button while it is loading. */
|
|
8
|
+
primaryLoadingLabel?: string;
|
|
9
|
+
/** Forces the primary button into its loading state, for loading driven by a store or parent. Loading from `onPrimaryAction` promises is tracked automatically. */
|
|
10
|
+
isPrimaryLoading?: boolean;
|
|
11
|
+
/** Called on accept. If it returns a promise the primary button shows a loading state until it settles. */
|
|
12
|
+
onPrimaryAction?: () => void | Promise<void>;
|
|
13
|
+
/** Called on cancel. The dialog also closes through `onOpenChange`. */
|
|
14
|
+
onSecondaryAction?: () => void;
|
|
15
|
+
isPrimaryDisabled?: boolean;
|
|
16
|
+
isSecondaryDisabled?: boolean;
|
|
17
|
+
/** Visual treatment of the primary button. `destructive` is for deletions. */
|
|
18
|
+
primaryVariant?: 'default' | 'destructive';
|
|
19
|
+
/** Optional extra button between secondary and primary. */
|
|
20
|
+
tertiaryLabel?: string;
|
|
21
|
+
onTertiaryAction?: () => void | Promise<void>;
|
|
22
|
+
isTertiaryDisabled?: boolean;
|
|
23
|
+
};
|
|
24
|
+
type SplDialogFooterProps = SplDialogActionsProps & {
|
|
25
|
+
dialogId: string;
|
|
26
|
+
/** Wraps the secondary button so Radix primitives (e.g. AlertDialog.Cancel) can own it. */
|
|
27
|
+
wrapSecondary?: (button: ReactNode) => ReactNode;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Footer buttons shared by SplDialog and SplAlertDialog.
|
|
31
|
+
* Button ids are `{dialogId}-secondary-btn`, `-tertiary-btn` and `-primary-btn`.
|
|
32
|
+
*/
|
|
33
|
+
declare const SplDialogFooter: ({ dialogId, secondaryLabel, primaryLabel, primaryLoadingLabel, isPrimaryLoading, onPrimaryAction, onSecondaryAction, isPrimaryDisabled, isSecondaryDisabled, primaryVariant, tertiaryLabel, onTertiaryAction, isTertiaryDisabled, wrapSecondary, }: SplDialogFooterProps) => React.JSX.Element | null;
|
|
34
|
+
export default SplDialogFooter;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SplAlertDialogProps } from './SplAlertDialog';
|
|
3
|
+
export type SplWarningAlertDialogProps = Omit<SplAlertDialogProps, 'status' | 'primaryVariant' | 'primaryLabel'> & {
|
|
4
|
+
/** Defaults to "Continue". */
|
|
5
|
+
primaryLabel?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Warning confirmation (e.g. sensitive record access): SplAlertDialog with the amber warning icon
|
|
9
|
+
* and the standard primary button.
|
|
10
|
+
*/
|
|
11
|
+
declare const SplWarningAlertDialog: ({ primaryLabel, secondaryLabel, ...rest }: SplWarningAlertDialogProps) => React.JSX.Element;
|
|
12
|
+
export default SplWarningAlertDialog;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as SplDialog } from "./SplDialog";
|
|
2
|
+
export type { SplDialogProps } from "./SplDialog";
|
|
3
|
+
export { default as SplAlertDialog } from "./SplAlertDialog";
|
|
4
|
+
export type { SplAlertDialogProps } from "./SplAlertDialog";
|
|
5
|
+
export { default as SplDeleteAlertDialog } from "./SplDeleteAlertDialog";
|
|
6
|
+
export type { SplDeleteAlertDialogProps } from "./SplDeleteAlertDialog";
|
|
7
|
+
export { default as SplWarningAlertDialog } from "./SplWarningAlertDialog";
|
|
8
|
+
export type { SplWarningAlertDialogProps } from "./SplWarningAlertDialog";
|
|
9
|
+
export type { SplDialogActionsProps } from "./SplDialogFooter";
|
|
10
|
+
export type { SplDialogSize, SplDialogSizeProps } from "./splDialogSize";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Same size scale as Radix Themes dialogs: 1 = 12px padding, 2 = 16px, 3 = 24px (default), 4 = 32px. */
|
|
2
|
+
export type SplDialogSize = '1' | '2' | '3' | '4';
|
|
3
|
+
export type SplDialogSizeProps = {
|
|
4
|
+
/** Padding and corner radius preset, applied by Radix Themes. Defaults to '3'. */
|
|
5
|
+
size?: SplDialogSize;
|
|
6
|
+
/** Maximum width as any CSS length (e.g. `'450px'`, `'50rem'`). Defaults to 544px (450px for alert dialogs). */
|
|
7
|
+
maxWidth?: string;
|
|
8
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,107 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type SplDialogActionsProps = {
|
|
4
|
+
/** Text for the cancel/close button. Defaults to "Cancel" when a primary button is shown. Provide it alone (e.g. "Close") for a close-only footer. */
|
|
5
|
+
secondaryLabel?: string;
|
|
6
|
+
/** Text for the accept button. */
|
|
7
|
+
primaryLabel?: string;
|
|
8
|
+
/** Text for the accept button while it is loading. */
|
|
9
|
+
primaryLoadingLabel?: string;
|
|
10
|
+
/** Forces the primary button into its loading state, for loading driven by a store or parent. Loading from `onPrimaryAction` promises is tracked automatically. */
|
|
11
|
+
isPrimaryLoading?: boolean;
|
|
12
|
+
/** Called on accept. If it returns a promise the primary button shows a loading state until it settles. */
|
|
13
|
+
onPrimaryAction?: () => void | Promise<void>;
|
|
14
|
+
/** Called on cancel. The dialog also closes through `onOpenChange`. */
|
|
15
|
+
onSecondaryAction?: () => void;
|
|
16
|
+
isPrimaryDisabled?: boolean;
|
|
17
|
+
isSecondaryDisabled?: boolean;
|
|
18
|
+
/** Visual treatment of the primary button. `destructive` is for deletions. */
|
|
19
|
+
primaryVariant?: 'default' | 'destructive';
|
|
20
|
+
/** Optional extra button between secondary and primary. */
|
|
21
|
+
tertiaryLabel?: string;
|
|
22
|
+
onTertiaryAction?: () => void | Promise<void>;
|
|
23
|
+
isTertiaryDisabled?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Same size scale as Radix Themes dialogs: 1 = 12px padding, 2 = 16px, 3 = 24px (default), 4 = 32px. */
|
|
27
|
+
type SplDialogSize = '1' | '2' | '3' | '4';
|
|
28
|
+
type SplDialogSizeProps = {
|
|
29
|
+
/** Padding and corner radius preset, applied by Radix Themes. Defaults to '3'. */
|
|
30
|
+
size?: SplDialogSize;
|
|
31
|
+
/** Maximum width as any CSS length (e.g. `'450px'`, `'50rem'`). Defaults to 544px (450px for alert dialogs). */
|
|
32
|
+
maxWidth?: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type SplDialogProps = SplDialogActionsProps & SplDialogSizeProps & {
|
|
36
|
+
/** Unique id; the content element gets this id and footer buttons derive theirs from it. */
|
|
37
|
+
id: string;
|
|
38
|
+
title: string;
|
|
39
|
+
/** Optional description announced by screen readers. */
|
|
40
|
+
description?: string;
|
|
41
|
+
isOpen: boolean;
|
|
42
|
+
onOpenChange: (isOpen: boolean) => void;
|
|
43
|
+
children: ReactNode;
|
|
44
|
+
/** Replace the built-in footer entirely (e.g. for forms that own their buttons). */
|
|
45
|
+
footer?: ReactNode;
|
|
46
|
+
/** Prevent closing via Escape, overlay click, or the X button. */
|
|
47
|
+
isDismissDisabled?: boolean;
|
|
48
|
+
/** Show the X button in the corner. Defaults to true; Escape and overlay click still close the dialog when false. */
|
|
49
|
+
hasCloseButton?: boolean;
|
|
50
|
+
/** Extra class on the content panel, for width overrides. */
|
|
51
|
+
contentClassName?: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* General purpose modal built on Radix Dialog for content and form dialogs.
|
|
55
|
+
* Use SplAlertDialog instead for confirmations that must be answered.
|
|
56
|
+
*/
|
|
57
|
+
declare const SplDialog: ({ id, title, description, isOpen, onOpenChange, children, footer, isDismissDisabled, hasCloseButton, contentClassName, size, maxWidth, onSecondaryAction, ...actions }: SplDialogProps) => React.JSX.Element;
|
|
58
|
+
|
|
59
|
+
type SplAlertDialogProps = Omit<SplDialogActionsProps, 'primaryLabel'> & SplDialogSizeProps & {
|
|
60
|
+
/** Unique id; the content element gets this id and footer buttons derive theirs from it. */
|
|
61
|
+
id: string;
|
|
62
|
+
title: string;
|
|
63
|
+
/** Required: alert dialogs must tell the user what they are confirming. May include inline markup. */
|
|
64
|
+
description: ReactNode;
|
|
65
|
+
isOpen: boolean;
|
|
66
|
+
onOpenChange: (isOpen: boolean) => void;
|
|
67
|
+
/** Required: an alert dialog always has an accept action. */
|
|
68
|
+
primaryLabel: string;
|
|
69
|
+
/** Optional extra content below the description (e.g. an error alert). */
|
|
70
|
+
children?: ReactNode;
|
|
71
|
+
/** Shows a leading icon before the title: a red trash can for 'destructive', an amber triangle for 'warning'. */
|
|
72
|
+
status?: 'destructive' | 'warning';
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Confirmation dialog built on Radix AlertDialog, for interruptions that need an explicit answer
|
|
76
|
+
* (delete confirmations, unsaved changes, etc.). Unlike SplDialog it cannot be dismissed by clicking
|
|
77
|
+
* outside, has no X button, and focuses Cancel first so the safe choice is the default.
|
|
78
|
+
* Cancel closes it through `onOpenChange`. It does not auto-close on accept; the caller closes it
|
|
79
|
+
* through `isOpen` once the action succeeds.
|
|
80
|
+
*/
|
|
81
|
+
declare const SplAlertDialog: ({ id, title, description, isOpen, onOpenChange, children, status, size, maxWidth, ...actions }: SplAlertDialogProps) => React.JSX.Element;
|
|
82
|
+
|
|
83
|
+
type SplDeleteAlertDialogProps = Omit<SplAlertDialogProps, 'status' | 'primaryVariant' | 'description' | 'primaryLabel'> & {
|
|
84
|
+
/** Name of the item being deleted, shown in bold after "Please confirm deletion of:". */
|
|
85
|
+
itemName: string;
|
|
86
|
+
/** Id for the bold item name element. Defaults to `{id}-item-name`. */
|
|
87
|
+
itemNameId?: string;
|
|
88
|
+
/** Defaults to "Delete". */
|
|
89
|
+
primaryLabel?: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Delete confirmation: SplAlertDialog with the red trash icon and destructive primary button.
|
|
93
|
+
*/
|
|
94
|
+
declare const SplDeleteAlertDialog: ({ id, itemName, itemNameId, primaryLabel, primaryLoadingLabel, secondaryLabel, ...rest }: SplDeleteAlertDialogProps) => React.JSX.Element;
|
|
95
|
+
|
|
96
|
+
type SplWarningAlertDialogProps = Omit<SplAlertDialogProps, 'status' | 'primaryVariant' | 'primaryLabel'> & {
|
|
97
|
+
/** Defaults to "Continue". */
|
|
98
|
+
primaryLabel?: string;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Warning confirmation (e.g. sensitive record access): SplAlertDialog with the amber warning icon
|
|
102
|
+
* and the standard primary button.
|
|
103
|
+
*/
|
|
104
|
+
declare const SplWarningAlertDialog: ({ primaryLabel, secondaryLabel, ...rest }: SplWarningAlertDialogProps) => React.JSX.Element;
|
|
2
105
|
|
|
3
106
|
type SplTheme = "light" | "dark";
|
|
4
107
|
type SplThemePreference = SplTheme | "system";
|
|
@@ -40,4 +143,4 @@ declare function useSplTheme(): SplThemeContextValue;
|
|
|
40
143
|
*/
|
|
41
144
|
declare const SplThemeProvider: ({ children, preference: controlledPreference, defaultPreference, onPreferenceChange, }: SplThemeProviderProps) => React.JSX.Element;
|
|
42
145
|
|
|
43
|
-
export { type SplTheme, type SplThemeContextValue, type SplThemePreference, SplThemeProvider, type SplThemeProviderProps, applyInitialSplTheme, applySplTheme, getSystemTheme, isSplThemePreference, resolveSplTheme, useSplTheme };
|
|
146
|
+
export { SplAlertDialog, type SplAlertDialogProps, SplDeleteAlertDialog, type SplDeleteAlertDialogProps, SplDialog, type SplDialogActionsProps, type SplDialogProps, type SplDialogSize, type SplDialogSizeProps, type SplTheme, type SplThemeContextValue, type SplThemePreference, SplThemeProvider, type SplThemeProviderProps, SplWarningAlertDialog, type SplWarningAlertDialogProps, applyInitialSplTheme, applySplTheme, getSystemTheme, isSplThemePreference, resolveSplTheme, useSplTheme };
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@va-scheduling/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A simple template for a custom React component library",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"rollup": "rollup -c",
|
|
7
|
+
"test": "vitest run",
|
|
7
8
|
"prepublishOnly": "rollup -c"
|
|
8
9
|
},
|
|
9
10
|
"author": "Sean Afram",
|
|
@@ -12,12 +13,20 @@
|
|
|
12
13
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
13
14
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
14
15
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
16
|
+
"@testing-library/dom": "^10.4.2",
|
|
17
|
+
"@testing-library/jest-dom": "^8.0.0",
|
|
18
|
+
"@testing-library/react": "^16.3.3",
|
|
19
|
+
"@testing-library/user-event": "^14.6.13",
|
|
15
20
|
"@types/react": "^18.3.5",
|
|
21
|
+
"@types/react-dom": "^18.3.7",
|
|
22
|
+
"jsdom": "^29.1.1",
|
|
16
23
|
"react": "^18.3.1",
|
|
17
24
|
"react-dom": "^18.3.1",
|
|
18
25
|
"rollup": "^4.21.2",
|
|
19
26
|
"rollup-plugin-dts": "^6.1.1",
|
|
20
|
-
"
|
|
27
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
28
|
+
"typescript": "^5.6.2",
|
|
29
|
+
"vitest": "^5.1.2"
|
|
21
30
|
},
|
|
22
31
|
"main": "dist/cjs/index.js",
|
|
23
32
|
"module": "dist/esm/index.js",
|
|
@@ -41,6 +50,7 @@
|
|
|
41
50
|
"access": "public"
|
|
42
51
|
},
|
|
43
52
|
"dependencies": {
|
|
53
|
+
"@radix-ui/react-icons": "^1.3.2",
|
|
44
54
|
"@radix-ui/themes": "^3.3.0",
|
|
45
55
|
"@va-scheduling/design-tokens": "^0.7.0",
|
|
46
56
|
"tslib": "^2.7.0"
|