@cerberus-design/react 0.6.1-next-1315bf2 → 0.6.1-next-8062b70
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/build/legacy/_tsup-dts-rollup.d.ts +78 -0
- package/build/legacy/{chunk-5RA3ZIXA.js → chunk-5GEC53G7.js} +5 -5
- package/build/legacy/{chunk-3TYUA4C7.js → chunk-6TXQZ3PB.js} +2 -2
- package/build/legacy/{chunk-SCAVVE6E.js → chunk-C45DY4VE.js} +2 -1
- package/build/legacy/chunk-C45DY4VE.js.map +1 -0
- package/build/legacy/{chunk-JJGZRBIR.js → chunk-CU7HXAKM.js} +4 -4
- package/build/legacy/chunk-G3JEWPLM.js +29 -0
- package/build/legacy/chunk-G3JEWPLM.js.map +1 -0
- package/build/legacy/{chunk-VLVKNEA5.js → chunk-TAZI77TP.js} +2 -2
- package/build/legacy/{chunk-YRUUO4AP.js → chunk-UZIN7UOS.js} +19 -38
- package/build/legacy/chunk-UZIN7UOS.js.map +1 -0
- package/build/legacy/chunk-WKSC2WCV.js +202 -0
- package/build/legacy/chunk-WKSC2WCV.js.map +1 -0
- package/build/legacy/components/Input.js +4 -4
- package/build/legacy/components/Label.js +2 -2
- package/build/legacy/components/ModalIcon.js +7 -0
- package/build/legacy/components/ModalIcon.js.map +1 -0
- package/build/legacy/components/Toggle.js +3 -3
- package/build/legacy/config/cerbIcons.js +1 -1
- package/build/legacy/config/defineIcons.js +2 -2
- package/build/legacy/context/confirm-modal.js +4 -3
- package/build/legacy/context/prompt-modal.js +20 -0
- package/build/legacy/context/prompt-modal.js.map +1 -0
- package/build/legacy/index.js +24 -14
- package/build/modern/_tsup-dts-rollup.d.ts +78 -0
- package/build/modern/{chunk-5RA3ZIXA.js → chunk-5GEC53G7.js} +5 -5
- package/build/modern/{chunk-3TYUA4C7.js → chunk-6TXQZ3PB.js} +2 -2
- package/build/modern/{chunk-SCAVVE6E.js → chunk-C45DY4VE.js} +2 -1
- package/build/modern/chunk-C45DY4VE.js.map +1 -0
- package/build/modern/{chunk-JJGZRBIR.js → chunk-CU7HXAKM.js} +4 -4
- package/build/modern/chunk-G3JEWPLM.js +29 -0
- package/build/modern/chunk-G3JEWPLM.js.map +1 -0
- package/build/modern/{chunk-VLVKNEA5.js → chunk-TAZI77TP.js} +2 -2
- package/build/modern/{chunk-BVK6GEDZ.js → chunk-X2GKC3IU.js} +19 -38
- package/build/modern/chunk-X2GKC3IU.js.map +1 -0
- package/build/modern/chunk-YHJTKBVE.js +200 -0
- package/build/modern/chunk-YHJTKBVE.js.map +1 -0
- package/build/modern/components/Input.js +4 -4
- package/build/modern/components/Label.js +2 -2
- package/build/modern/components/ModalIcon.js +7 -0
- package/build/modern/components/ModalIcon.js.map +1 -0
- package/build/modern/components/Toggle.js +3 -3
- package/build/modern/config/cerbIcons.js +1 -1
- package/build/modern/config/defineIcons.js +2 -2
- package/build/modern/context/confirm-modal.js +4 -3
- package/build/modern/context/prompt-modal.js +20 -0
- package/build/modern/context/prompt-modal.js.map +1 -0
- package/build/modern/index.js +24 -14
- package/package.json +2 -2
- package/src/components/ModalIcon.tsx +28 -0
- package/src/config/cerbIcons.ts +2 -0
- package/src/context/confirm-modal.tsx +20 -43
- package/src/context/prompt-modal.tsx +231 -0
- package/src/index.ts +2 -0
- package/build/legacy/chunk-SCAVVE6E.js.map +0 -1
- package/build/legacy/chunk-YRUUO4AP.js.map +0 -1
- package/build/modern/chunk-BVK6GEDZ.js.map +0 -1
- package/build/modern/chunk-SCAVVE6E.js.map +0 -1
- /package/build/legacy/{chunk-5RA3ZIXA.js.map → chunk-5GEC53G7.js.map} +0 -0
- /package/build/legacy/{chunk-3TYUA4C7.js.map → chunk-6TXQZ3PB.js.map} +0 -0
- /package/build/legacy/{chunk-JJGZRBIR.js.map → chunk-CU7HXAKM.js.map} +0 -0
- /package/build/legacy/{chunk-VLVKNEA5.js.map → chunk-TAZI77TP.js.map} +0 -0
- /package/build/modern/{chunk-5RA3ZIXA.js.map → chunk-5GEC53G7.js.map} +0 -0
- /package/build/modern/{chunk-3TYUA4C7.js.map → chunk-6TXQZ3PB.js.map} +0 -0
- /package/build/modern/{chunk-JJGZRBIR.js.map → chunk-CU7HXAKM.js.map} +0 -0
- /package/build/modern/{chunk-VLVKNEA5.js.map → chunk-TAZI77TP.js.map} +0 -0
|
@@ -13,6 +13,7 @@ import type { InputHTMLAttributes } from 'react';
|
|
|
13
13
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
14
14
|
import type { KeyboardEventHandler } from 'react';
|
|
15
15
|
import { label } from '@cerberus/styled-system/recipes';
|
|
16
|
+
import { ModalIconVariantProps } from '@cerberus-design/styled-system/recipes';
|
|
16
17
|
import { MutableRefObject } from 'react';
|
|
17
18
|
import type { Pretty } from '@cerberus-design/styled-system/types';
|
|
18
19
|
import { PropsWithChildren } from 'react';
|
|
@@ -117,6 +118,7 @@ export { DefaultThemes as DefaultThemes_alias_1 }
|
|
|
117
118
|
|
|
118
119
|
export declare interface DefinedIcons {
|
|
119
120
|
confirmModal?: CarbonIconType | ElementType;
|
|
121
|
+
promptModal?: CarbonIconType | ElementType;
|
|
120
122
|
invalid: CarbonIconType | ElementType;
|
|
121
123
|
toggleChecked?: CarbonIconType | ElementType;
|
|
122
124
|
}
|
|
@@ -319,6 +321,18 @@ declare type LabelRecipeProps = RecipeVariantProps<typeof label>;
|
|
|
319
321
|
export { LabelRecipeProps }
|
|
320
322
|
export { LabelRecipeProps as LabelRecipeProps_alias_1 }
|
|
321
323
|
|
|
324
|
+
declare function ModalIcon(props: PropsWithChildren<ModalIconProps>): JSX_2.Element;
|
|
325
|
+
export { ModalIcon }
|
|
326
|
+
export { ModalIcon as ModalIcon_alias_1 }
|
|
327
|
+
|
|
328
|
+
declare type ModalIconBaseProps = HTMLAttributes<HTMLDivElement>;
|
|
329
|
+
export { ModalIconBaseProps }
|
|
330
|
+
export { ModalIconBaseProps as ModalIconBaseProps_alias_1 }
|
|
331
|
+
|
|
332
|
+
declare type ModalIconProps = ModalIconBaseProps & ModalIconVariantProps;
|
|
333
|
+
export { ModalIconProps }
|
|
334
|
+
export { ModalIconProps as ModalIconProps_alias_1 }
|
|
335
|
+
|
|
322
336
|
declare const MODE_KEY = "cerberus-mode";
|
|
323
337
|
export { MODE_KEY }
|
|
324
338
|
export { MODE_KEY as MODE_KEY_alias_1 }
|
|
@@ -436,6 +450,51 @@ declare type Positions = 'top' | 'right' | 'bottom' | 'left';
|
|
|
436
450
|
export { Positions }
|
|
437
451
|
export { Positions as Positions_alias_1 }
|
|
438
452
|
|
|
453
|
+
/**
|
|
454
|
+
* Provides a prompt modal to the app.
|
|
455
|
+
* @example
|
|
456
|
+
* ```tsx
|
|
457
|
+
* // Wrap the Provider around the root of the feature.
|
|
458
|
+
* <PromptModal>
|
|
459
|
+
* <SomeFeatureSection />
|
|
460
|
+
* </PromptModal>
|
|
461
|
+
*
|
|
462
|
+
* // Use the hook to show the prompt modal.
|
|
463
|
+
* const prompt = usePromptModal()
|
|
464
|
+
*
|
|
465
|
+
* const handleClick = useCallback(async () => {
|
|
466
|
+
* const accepted = await prompt.show({
|
|
467
|
+
* kind: 'destructive',
|
|
468
|
+
* heading: 'Delete channel?',
|
|
469
|
+
* description:
|
|
470
|
+
* 'This will permanently delete a channel on your account. There is no going back.',
|
|
471
|
+
* key: CHANNEL_NAME,
|
|
472
|
+
* actionText: 'Yes, delete channel',
|
|
473
|
+
* cancelText: 'No, cancel',
|
|
474
|
+
* })
|
|
475
|
+
* // do something with accepted
|
|
476
|
+
* }, [prompt])
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
declare function PromptModal(props: PropsWithChildren<PromptModalProviderProps>): JSX_2.Element;
|
|
480
|
+
export { PromptModal }
|
|
481
|
+
export { PromptModal as PromptModal_alias_1 }
|
|
482
|
+
|
|
483
|
+
declare interface PromptModalProviderProps {
|
|
484
|
+
}
|
|
485
|
+
export { PromptModalProviderProps }
|
|
486
|
+
export { PromptModalProviderProps as PromptModalProviderProps_alias_1 }
|
|
487
|
+
|
|
488
|
+
declare interface PromptModalValue {
|
|
489
|
+
show: (options: ShowPromptModalOptions) => Promise<string>;
|
|
490
|
+
}
|
|
491
|
+
export { PromptModalValue }
|
|
492
|
+
export { PromptModalValue as PromptModalValue_alias_1 }
|
|
493
|
+
|
|
494
|
+
declare type PromptShowResult = ((value: string | PromiseLike<string>) => void) | null;
|
|
495
|
+
export { PromptShowResult }
|
|
496
|
+
export { PromptShowResult as PromptShowResult_alias_1 }
|
|
497
|
+
|
|
439
498
|
declare function Radio(props: PropsWithChildren<RadioProps>): JSX_2.Element;
|
|
440
499
|
export { Radio }
|
|
441
500
|
export { Radio as Radio_alias_1 }
|
|
@@ -482,6 +541,21 @@ declare interface ShowConfirmModalOptions {
|
|
|
482
541
|
export { ShowConfirmModalOptions }
|
|
483
542
|
export { ShowConfirmModalOptions as ShowConfirmModalOptions_alias_1 }
|
|
484
543
|
|
|
544
|
+
/**
|
|
545
|
+
* This module provides a context and hook for the prompt modal.
|
|
546
|
+
* @module
|
|
547
|
+
*/
|
|
548
|
+
declare interface ShowPromptModalOptions {
|
|
549
|
+
kind?: 'destructive' | 'non-destructive';
|
|
550
|
+
heading: string;
|
|
551
|
+
description?: string;
|
|
552
|
+
key: string;
|
|
553
|
+
actionText: string;
|
|
554
|
+
cancelText: string;
|
|
555
|
+
}
|
|
556
|
+
export { ShowPromptModalOptions }
|
|
557
|
+
export { ShowPromptModalOptions as ShowPromptModalOptions_alias_1 }
|
|
558
|
+
|
|
485
559
|
declare interface ShowProps {
|
|
486
560
|
when: boolean | null | undefined;
|
|
487
561
|
fallback?: ReactNode;
|
|
@@ -739,6 +813,10 @@ declare function useNavMenuContext(): NavMenuContextValue;
|
|
|
739
813
|
export { useNavMenuContext }
|
|
740
814
|
export { useNavMenuContext as useNavMenuContext_alias_1 }
|
|
741
815
|
|
|
816
|
+
declare function usePromptModal(): PromptModalValue;
|
|
817
|
+
export { usePromptModal }
|
|
818
|
+
export { usePromptModal as usePromptModal_alias_1 }
|
|
819
|
+
|
|
742
820
|
declare function useTabsContext(): TabsContextValue;
|
|
743
821
|
export { useTabsContext }
|
|
744
822
|
export { useTabsContext as useTabsContext_alias_1 }
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useFieldContext
|
|
3
|
-
} from "./chunk-ZAU4JVLL.js";
|
|
4
1
|
import {
|
|
5
2
|
Show
|
|
6
3
|
} from "./chunk-4O4QFF4S.js";
|
|
4
|
+
import {
|
|
5
|
+
useFieldContext
|
|
6
|
+
} from "./chunk-ZAU4JVLL.js";
|
|
7
7
|
import {
|
|
8
8
|
$cerberusIcons
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-6TXQZ3PB.js";
|
|
10
10
|
|
|
11
11
|
// src/components/Input.tsx
|
|
12
12
|
import { input } from "@cerberus/styled-system/recipes";
|
|
@@ -39,4 +39,4 @@ function Input(props) {
|
|
|
39
39
|
export {
|
|
40
40
|
Input
|
|
41
41
|
};
|
|
42
|
-
//# sourceMappingURL=chunk-
|
|
42
|
+
//# sourceMappingURL=chunk-5GEC53G7.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defaultIcons
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-C45DY4VE.js";
|
|
4
4
|
|
|
5
5
|
// src/config/defineIcons.ts
|
|
6
6
|
function _validateIconsProperties(icons) {
|
|
@@ -24,4 +24,4 @@ export {
|
|
|
24
24
|
defineIcons,
|
|
25
25
|
$cerberusIcons
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
27
|
+
//# sourceMappingURL=chunk-6TXQZ3PB.js.map
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "@cerberus/icons";
|
|
7
7
|
var defaultIcons = {
|
|
8
8
|
confirmModal: Information,
|
|
9
|
+
promptModal: Information,
|
|
9
10
|
invalid: WarningFilled,
|
|
10
11
|
toggleChecked: Checkmark
|
|
11
12
|
};
|
|
@@ -13,4 +14,4 @@ var defaultIcons = {
|
|
|
13
14
|
export {
|
|
14
15
|
defaultIcons
|
|
15
16
|
};
|
|
16
|
-
//# sourceMappingURL=chunk-
|
|
17
|
+
//# sourceMappingURL=chunk-C45DY4VE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/config/cerbIcons.ts"],"sourcesContent":["import {\n Checkmark,\n Information,\n WarningFilled,\n type CarbonIconType,\n} from '@cerberus/icons'\nimport type { ElementType } from 'react'\n\nexport interface DefinedIcons {\n confirmModal?: CarbonIconType | ElementType\n promptModal?: CarbonIconType | ElementType\n invalid: CarbonIconType | ElementType\n toggleChecked?: CarbonIconType | ElementType\n}\n\nexport const defaultIcons: DefinedIcons = {\n confirmModal: Information,\n promptModal: Information,\n invalid: WarningFilled,\n toggleChecked: Checkmark,\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAUA,IAAM,eAA6B;AAAA,EACxC,cAAc;AAAA,EACd,aAAa;AAAA,EACb,SAAS;AAAA,EACT,eAAe;AACjB;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useFieldContext
|
|
3
|
-
} from "./chunk-ZAU4JVLL.js";
|
|
4
1
|
import {
|
|
5
2
|
Show
|
|
6
3
|
} from "./chunk-4O4QFF4S.js";
|
|
4
|
+
import {
|
|
5
|
+
useFieldContext
|
|
6
|
+
} from "./chunk-ZAU4JVLL.js";
|
|
7
7
|
|
|
8
8
|
// src/components/Label.tsx
|
|
9
9
|
import { label } from "@cerberus/styled-system/recipes";
|
|
@@ -46,4 +46,4 @@ function Label(props) {
|
|
|
46
46
|
export {
|
|
47
47
|
Label
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-CU7HXAKM.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/components/ModalIcon.tsx
|
|
2
|
+
import { cx } from "@cerberus-design/styled-system/css";
|
|
3
|
+
import { circle } from "@cerberus-design/styled-system/patterns";
|
|
4
|
+
import {
|
|
5
|
+
modalIcon
|
|
6
|
+
} from "@cerberus-design/styled-system/recipes";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
function ModalIcon(props) {
|
|
9
|
+
const { palette, ...nativeProps } = props;
|
|
10
|
+
return /* @__PURE__ */ jsx(
|
|
11
|
+
"div",
|
|
12
|
+
{
|
|
13
|
+
...nativeProps,
|
|
14
|
+
className: cx(
|
|
15
|
+
nativeProps.className,
|
|
16
|
+
modalIcon({
|
|
17
|
+
palette
|
|
18
|
+
}),
|
|
19
|
+
circle()
|
|
20
|
+
),
|
|
21
|
+
children: props.children
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
ModalIcon
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=chunk-G3JEWPLM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/ModalIcon.tsx"],"sourcesContent":["import { cx } from '@cerberus-design/styled-system/css'\nimport { circle } from '@cerberus-design/styled-system/patterns'\nimport {\n modalIcon,\n type ModalIconVariantProps,\n} from '@cerberus-design/styled-system/recipes'\nimport type { HTMLAttributes, PropsWithChildren } from 'react'\n\nexport type ModalIconBaseProps = HTMLAttributes<HTMLDivElement>\nexport type ModalIconProps = ModalIconBaseProps & ModalIconVariantProps\n\nexport function ModalIcon(props: PropsWithChildren<ModalIconProps>) {\n const { palette, ...nativeProps } = props\n return (\n <div\n {...nativeProps}\n className={cx(\n nativeProps.className,\n modalIcon({\n palette,\n }),\n circle(),\n )}\n >\n {props.children}\n </div>\n )\n}\n"],"mappings":";AAAA,SAAS,UAAU;AACnB,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,OAEK;AASH;AAHG,SAAS,UAAU,OAA0C;AAClE,QAAM,EAAE,SAAS,GAAG,YAAY,IAAI;AACpC,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,WAAW;AAAA,QACT,YAAY;AAAA,QACZ,UAAU;AAAA,UACR;AAAA,QACF,CAAC;AAAA,QACD,OAAO;AAAA,MACT;AAAA,MAEC,gBAAM;AAAA;AAAA,EACT;AAEJ;","names":[]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-ZAU4JVLL.js";
|
|
4
4
|
import {
|
|
5
5
|
$cerberusIcons
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-6TXQZ3PB.js";
|
|
7
7
|
|
|
8
8
|
// src/components/Toggle.tsx
|
|
9
9
|
import { cx } from "@cerberus-design/styled-system/css";
|
|
@@ -55,4 +55,4 @@ function Toggle(props) {
|
|
|
55
55
|
export {
|
|
56
56
|
Toggle
|
|
57
57
|
};
|
|
58
|
-
//# sourceMappingURL=chunk-
|
|
58
|
+
//# sourceMappingURL=chunk-TAZI77TP.js.map
|
|
@@ -7,12 +7,15 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
Show
|
|
9
9
|
} from "./chunk-4O4QFF4S.js";
|
|
10
|
+
import {
|
|
11
|
+
ModalIcon
|
|
12
|
+
} from "./chunk-G3JEWPLM.js";
|
|
10
13
|
import {
|
|
11
14
|
trapFocus
|
|
12
15
|
} from "./chunk-KESKDLX6.js";
|
|
13
16
|
import {
|
|
14
17
|
$cerberusIcons
|
|
15
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-6TXQZ3PB.js";
|
|
16
19
|
|
|
17
20
|
// src/context/confirm-modal.tsx
|
|
18
21
|
import {
|
|
@@ -23,11 +26,9 @@ import {
|
|
|
23
26
|
useRef,
|
|
24
27
|
useState
|
|
25
28
|
} from "react";
|
|
26
|
-
import { css
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
confirmModal
|
|
30
|
-
} from "@cerberus-design/styled-system/recipes";
|
|
29
|
+
import { css } from "@cerberus-design/styled-system/css";
|
|
30
|
+
import { hstack, vstack } from "@cerberus-design/styled-system/patterns";
|
|
31
|
+
import { modal } from "@cerberus-design/styled-system/recipes";
|
|
31
32
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
32
33
|
var ConfirmModalContext = createContext(null);
|
|
33
34
|
function ConfirmModal(props) {
|
|
@@ -35,11 +36,12 @@ function ConfirmModal(props) {
|
|
|
35
36
|
const resolveRef = useRef(null);
|
|
36
37
|
const [content, setContent] = useState(null);
|
|
37
38
|
const focusTrap = trapFocus(dialogRef);
|
|
39
|
+
const ConfirmIcon = $cerberusIcons.confirmModal;
|
|
38
40
|
const palette = useMemo(
|
|
39
41
|
() => (content == null ? void 0 : content.kind) === "destructive" ? "danger" : "action",
|
|
40
42
|
[content]
|
|
41
43
|
);
|
|
42
|
-
const styles =
|
|
44
|
+
const styles = modal();
|
|
43
45
|
const handleChoice = useCallback((e) => {
|
|
44
46
|
var _a, _b, _c;
|
|
45
47
|
const target = e.currentTarget;
|
|
@@ -67,7 +69,7 @@ function ConfirmModal(props) {
|
|
|
67
69
|
props.children,
|
|
68
70
|
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs("dialog", { className: styles.dialog, onKeyDown: focusTrap, ref: dialogRef, children: [
|
|
69
71
|
/* @__PURE__ */ jsxs(
|
|
70
|
-
"
|
|
72
|
+
"section",
|
|
71
73
|
{
|
|
72
74
|
className: vstack({
|
|
73
75
|
alignItems: "flex-start",
|
|
@@ -75,7 +77,14 @@ function ConfirmModal(props) {
|
|
|
75
77
|
mb: "8"
|
|
76
78
|
}),
|
|
77
79
|
children: [
|
|
78
|
-
/* @__PURE__ */ jsx(
|
|
80
|
+
/* @__PURE__ */ jsx(
|
|
81
|
+
Show,
|
|
82
|
+
{
|
|
83
|
+
when: palette === "danger",
|
|
84
|
+
fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) }),
|
|
85
|
+
children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) })
|
|
86
|
+
}
|
|
87
|
+
),
|
|
79
88
|
/* @__PURE__ */ jsx("h2", { className: styles.heading, children: content == null ? void 0 : content.heading }),
|
|
80
89
|
/* @__PURE__ */ jsx("p", { className: styles.description, children: content == null ? void 0 : content.description })
|
|
81
90
|
]
|
|
@@ -85,7 +94,6 @@ function ConfirmModal(props) {
|
|
|
85
94
|
"div",
|
|
86
95
|
{
|
|
87
96
|
className: hstack({
|
|
88
|
-
justifyContent: "stretch",
|
|
89
97
|
gap: "4"
|
|
90
98
|
}),
|
|
91
99
|
children: [
|
|
@@ -122,33 +130,6 @@ function ConfirmModal(props) {
|
|
|
122
130
|
] }) })
|
|
123
131
|
] });
|
|
124
132
|
}
|
|
125
|
-
function ConfirmModalIcon(props) {
|
|
126
|
-
const InfoIcon = $cerberusIcons.confirmModal;
|
|
127
|
-
return /* @__PURE__ */ jsx(
|
|
128
|
-
Show,
|
|
129
|
-
{
|
|
130
|
-
when: props.palette === "danger",
|
|
131
|
-
fallback: /* @__PURE__ */ jsx("div", { className: cx(confirmModal().icon, circle()), children: /* @__PURE__ */ jsx(InfoIcon, {}) }),
|
|
132
|
-
children: /* @__PURE__ */ jsx(
|
|
133
|
-
"div",
|
|
134
|
-
{
|
|
135
|
-
className: cx(
|
|
136
|
-
confirmModal({
|
|
137
|
-
palette: "danger"
|
|
138
|
-
}).icon,
|
|
139
|
-
circle({
|
|
140
|
-
bgColor: "danger.surface.initial"
|
|
141
|
-
})
|
|
142
|
-
),
|
|
143
|
-
style: {
|
|
144
|
-
color: "var(--cerberus-colors-danger-text-100)"
|
|
145
|
-
},
|
|
146
|
-
children: /* @__PURE__ */ jsx(InfoIcon, {})
|
|
147
|
-
}
|
|
148
|
-
)
|
|
149
|
-
}
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
133
|
function useConfirmModal() {
|
|
153
134
|
const context = useContext(ConfirmModalContext);
|
|
154
135
|
if (context === null) {
|
|
@@ -163,4 +144,4 @@ export {
|
|
|
163
144
|
ConfirmModal,
|
|
164
145
|
useConfirmModal
|
|
165
146
|
};
|
|
166
|
-
//# sourceMappingURL=chunk-
|
|
147
|
+
//# sourceMappingURL=chunk-UZIN7UOS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/confirm-modal.tsx"],"sourcesContent":["'use client'\n\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n type MouseEvent,\n type PropsWithChildren,\n} from 'react'\nimport { Portal } from '../components/Portal'\nimport { Button } from '../components/Button'\nimport { css } from '@cerberus-design/styled-system/css'\nimport { hstack, vstack } from '@cerberus-design/styled-system/patterns'\nimport { $cerberusIcons } from '../config/defineIcons'\nimport { modal } from '@cerberus-design/styled-system/recipes'\nimport { trapFocus } from '../aria-helpers/trap-focus.aria'\nimport { ModalIcon } from '../components/ModalIcon'\nimport { Show } from '../components/Show'\n\n/**\n * This module provides a context and hook for the confirm modal.\n * @module\n */\n\nexport interface ShowConfirmModalOptions {\n kind?: 'destructive' | 'non-destructive'\n heading: string\n description?: string\n actionText: string\n cancelText: string\n}\nexport type ShowResult =\n | ((value: boolean | PromiseLike<boolean>) => void)\n | null\n\nexport interface ConfirmModalValue {\n show: (options: ShowConfirmModalOptions) => Promise<boolean>\n}\n\nconst ConfirmModalContext = createContext<ConfirmModalValue | null>(null)\n\nexport interface ConfirmModalProviderProps {}\n\n/**\n * Provides a confirm modal to the app.\n * @example\n * ```tsx\n * // Wrap the Provider around the root of the feature.\n * <ConfirmModal>\n * <SomeFeatureSection />\n * </ConfirmModal>\n *\n * // Use the hook to show the confirm modal.\n * const confirm = useConfirmModal()\n *\n * const handleClick = useCallback(async () => {\n * const userConsent = await confirm.show({\n * heading: 'Add new payment method?',\n * description:\n * 'This will add a new payment method to your account to be billed for future purchases.',\n * actionText: 'Yes, add payment method',\n * cancelText: 'No, cancel',\n * })\n * setConsent(userConsent)\n * }, [confirm])\n * ```\n */\nexport function ConfirmModal(\n props: PropsWithChildren<ConfirmModalProviderProps>,\n) {\n const dialogRef = useRef<HTMLDialogElement>(null)\n const resolveRef = useRef<ShowResult>(null)\n const [content, setContent] = useState<ShowConfirmModalOptions | null>(null)\n const focusTrap = trapFocus(dialogRef)\n const ConfirmIcon = $cerberusIcons.confirmModal\n\n const palette = useMemo(\n () => (content?.kind === 'destructive' ? 'danger' : 'action'),\n [content],\n )\n const styles = modal()\n\n const handleChoice = useCallback((e: MouseEvent<HTMLButtonElement>) => {\n const target = e.currentTarget as HTMLButtonElement\n if (target.value === 'true') {\n resolveRef.current?.(true)\n }\n resolveRef.current?.(false)\n dialogRef?.current?.close()\n }, [])\n\n const handleShow = useCallback((options: ShowConfirmModalOptions) => {\n return new Promise<boolean>((resolve) => {\n setContent({ ...options, kind: options.kind || 'non-destructive' })\n dialogRef?.current?.showModal()\n resolveRef.current = resolve\n })\n }, [])\n\n const value = useMemo(\n () => ({\n show: handleShow,\n }),\n [handleShow],\n )\n\n return (\n <ConfirmModalContext.Provider value={value}>\n {props.children}\n\n <Portal>\n <dialog className={styles.dialog} onKeyDown={focusTrap} ref={dialogRef}>\n <section\n className={vstack({\n alignItems: 'flex-start',\n gap: '4',\n mb: '8',\n })}\n >\n <Show\n when={palette === 'danger'}\n fallback={\n <ModalIcon palette=\"action\">\n <ConfirmIcon size={24} />\n </ModalIcon>\n }\n >\n <ModalIcon palette=\"danger\">\n <ConfirmIcon size={24} />\n </ModalIcon>\n </Show>\n <h2 className={styles.heading}>{content?.heading}</h2>\n <p className={styles.description}>{content?.description}</p>\n </section>\n\n <div\n className={hstack({\n gap: '4',\n })}\n >\n <Button\n autoFocus\n className={css({\n w: '1/2',\n })}\n name=\"confirm\"\n onClick={handleChoice}\n palette={palette}\n value=\"true\"\n >\n {content?.actionText}\n </Button>\n <Button\n className={css({\n w: '1/2',\n })}\n name=\"cancel\"\n onClick={handleChoice}\n usage=\"outlined\"\n value=\"false\"\n >\n {content?.cancelText}\n </Button>\n </div>\n </dialog>\n </Portal>\n </ConfirmModalContext.Provider>\n )\n}\n\nexport function useConfirmModal(): ConfirmModalValue {\n const context = useContext(ConfirmModalContext)\n if (context === null) {\n throw new Error(\n 'useConfirmModal must be used within a ConfirmModal Provider',\n )\n }\n return context\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP,SAAS,WAAW;AACpB,SAAS,QAAQ,cAAc;AAE/B,SAAS,aAAa;AAkGZ,SAWQ,KAXR;AAzEV,IAAM,sBAAsB,cAAwC,IAAI;AA4BjE,SAAS,aACd,OACA;AACA,QAAM,YAAY,OAA0B,IAAI;AAChD,QAAM,aAAa,OAAmB,IAAI;AAC1C,QAAM,CAAC,SAAS,UAAU,IAAI,SAAyC,IAAI;AAC3E,QAAM,YAAY,UAAU,SAAS;AACrC,QAAM,cAAc,eAAe;AAEnC,QAAM,UAAU;AAAA,IACd,OAAO,mCAAS,UAAS,gBAAgB,WAAW;AAAA,IACpD,CAAC,OAAO;AAAA,EACV;AACA,QAAM,SAAS,MAAM;AAErB,QAAM,eAAe,YAAY,CAAC,MAAqC;AArFzE;AAsFI,UAAM,SAAS,EAAE;AACjB,QAAI,OAAO,UAAU,QAAQ;AAC3B,uBAAW,YAAX,oCAAqB;AAAA,IACvB;AACA,qBAAW,YAAX,oCAAqB;AACrB,iDAAW,YAAX,mBAAoB;AAAA,EACtB,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa,YAAY,CAAC,YAAqC;AACnE,WAAO,IAAI,QAAiB,CAAC,YAAY;AA/F7C;AAgGM,iBAAW,EAAE,GAAG,SAAS,MAAM,QAAQ,QAAQ,kBAAkB,CAAC;AAClE,mDAAW,YAAX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ACT,OAAM;AAAA,gBACN,OAAM;AAAA,gBAEL,6CAAS;AAAA;AAAA,YACZ;AAAA;AAAA;AAAA,MACF;AAAA,OACF,GACF;AAAA,KACF;AAEJ;AAEO,SAAS,kBAAqC;AACnD,QAAM,UAAU,WAAW,mBAAmB;AAC9C,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Portal
|
|
3
|
+
} from "./chunk-4CAT3FHV.js";
|
|
4
|
+
import {
|
|
5
|
+
Button
|
|
6
|
+
} from "./chunk-2ATICEW3.js";
|
|
7
|
+
import {
|
|
8
|
+
Input
|
|
9
|
+
} from "./chunk-5GEC53G7.js";
|
|
10
|
+
import {
|
|
11
|
+
Label
|
|
12
|
+
} from "./chunk-CU7HXAKM.js";
|
|
13
|
+
import {
|
|
14
|
+
Show
|
|
15
|
+
} from "./chunk-4O4QFF4S.js";
|
|
16
|
+
import {
|
|
17
|
+
Field
|
|
18
|
+
} from "./chunk-ZAU4JVLL.js";
|
|
19
|
+
import {
|
|
20
|
+
ModalIcon
|
|
21
|
+
} from "./chunk-G3JEWPLM.js";
|
|
22
|
+
import {
|
|
23
|
+
trapFocus
|
|
24
|
+
} from "./chunk-KESKDLX6.js";
|
|
25
|
+
import {
|
|
26
|
+
$cerberusIcons
|
|
27
|
+
} from "./chunk-6TXQZ3PB.js";
|
|
28
|
+
|
|
29
|
+
// src/context/prompt-modal.tsx
|
|
30
|
+
import {
|
|
31
|
+
createContext,
|
|
32
|
+
useCallback,
|
|
33
|
+
useContext,
|
|
34
|
+
useMemo,
|
|
35
|
+
useRef,
|
|
36
|
+
useState
|
|
37
|
+
} from "react";
|
|
38
|
+
import { css } from "@cerberus-design/styled-system/css";
|
|
39
|
+
import { hstack, vstack } from "@cerberus-design/styled-system/patterns";
|
|
40
|
+
import { modal } from "@cerberus-design/styled-system/recipes";
|
|
41
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
42
|
+
var PromptModalContext = createContext(null);
|
|
43
|
+
function PromptModal(props) {
|
|
44
|
+
const dialogRef = useRef(null);
|
|
45
|
+
const resolveRef = useRef(null);
|
|
46
|
+
const [content, setContent] = useState(null);
|
|
47
|
+
const [inputValue, setInputValue] = useState("");
|
|
48
|
+
const focusTrap = trapFocus(dialogRef);
|
|
49
|
+
const PromptIcon = $cerberusIcons.promptModal;
|
|
50
|
+
const isValid = useMemo(
|
|
51
|
+
() => inputValue === (content == null ? void 0 : content.key),
|
|
52
|
+
[inputValue, content]
|
|
53
|
+
);
|
|
54
|
+
const palette = useMemo(
|
|
55
|
+
() => (content == null ? void 0 : content.kind) === "destructive" ? "danger" : "action",
|
|
56
|
+
[content]
|
|
57
|
+
);
|
|
58
|
+
const styles = modal();
|
|
59
|
+
const handleChange = useCallback(
|
|
60
|
+
(e) => {
|
|
61
|
+
setInputValue(e.currentTarget.value);
|
|
62
|
+
},
|
|
63
|
+
[content]
|
|
64
|
+
);
|
|
65
|
+
const handleChoice = useCallback(
|
|
66
|
+
(e) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const target = e.currentTarget;
|
|
69
|
+
if (target.value === "true") {
|
|
70
|
+
(_a = resolveRef.current) == null ? void 0 : _a.call(resolveRef, inputValue);
|
|
71
|
+
}
|
|
72
|
+
(_b = dialogRef == null ? void 0 : dialogRef.current) == null ? void 0 : _b.close();
|
|
73
|
+
},
|
|
74
|
+
[inputValue]
|
|
75
|
+
);
|
|
76
|
+
const handleShow = useCallback((options) => {
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
var _a;
|
|
79
|
+
setContent({ ...options, kind: options.kind || "non-destructive" });
|
|
80
|
+
(_a = dialogRef == null ? void 0 : dialogRef.current) == null ? void 0 : _a.showModal();
|
|
81
|
+
resolveRef.current = resolve;
|
|
82
|
+
});
|
|
83
|
+
}, []);
|
|
84
|
+
const value = useMemo(
|
|
85
|
+
() => ({
|
|
86
|
+
show: handleShow
|
|
87
|
+
}),
|
|
88
|
+
[handleShow]
|
|
89
|
+
);
|
|
90
|
+
return /* @__PURE__ */ jsxs(PromptModalContext.Provider, { value, children: [
|
|
91
|
+
props.children,
|
|
92
|
+
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs("dialog", { className: styles.dialog, onKeyDown: focusTrap, ref: dialogRef, children: [
|
|
93
|
+
/* @__PURE__ */ jsxs(
|
|
94
|
+
"div",
|
|
95
|
+
{
|
|
96
|
+
className: vstack({
|
|
97
|
+
alignItems: "flex-start",
|
|
98
|
+
gap: "4"
|
|
99
|
+
}),
|
|
100
|
+
children: [
|
|
101
|
+
/* @__PURE__ */ jsx(
|
|
102
|
+
Show,
|
|
103
|
+
{
|
|
104
|
+
when: palette === "danger",
|
|
105
|
+
fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) }),
|
|
106
|
+
children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) })
|
|
107
|
+
}
|
|
108
|
+
),
|
|
109
|
+
/* @__PURE__ */ jsx("h2", { className: styles.heading, children: content == null ? void 0 : content.heading }),
|
|
110
|
+
/* @__PURE__ */ jsx("p", { className: styles.description, children: content == null ? void 0 : content.description })
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
),
|
|
114
|
+
/* @__PURE__ */ jsx(
|
|
115
|
+
"div",
|
|
116
|
+
{
|
|
117
|
+
className: vstack({
|
|
118
|
+
alignItems: "flex-start",
|
|
119
|
+
mt: "4",
|
|
120
|
+
mb: "8"
|
|
121
|
+
}),
|
|
122
|
+
children: /* @__PURE__ */ jsxs(Field, { invalid: !isValid, children: [
|
|
123
|
+
/* @__PURE__ */ jsxs(Label, { htmlFor: "confirm", size: "md", children: [
|
|
124
|
+
"Type",
|
|
125
|
+
/* @__PURE__ */ jsx(
|
|
126
|
+
"strong",
|
|
127
|
+
{
|
|
128
|
+
className: css({
|
|
129
|
+
textTransform: "uppercase"
|
|
130
|
+
}),
|
|
131
|
+
children: content == null ? void 0 : content.key
|
|
132
|
+
}
|
|
133
|
+
),
|
|
134
|
+
"to confirm"
|
|
135
|
+
] }),
|
|
136
|
+
/* @__PURE__ */ jsx(
|
|
137
|
+
Input,
|
|
138
|
+
{
|
|
139
|
+
id: "confirm",
|
|
140
|
+
name: "confirm",
|
|
141
|
+
onChange: handleChange,
|
|
142
|
+
type: "text"
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
] })
|
|
146
|
+
}
|
|
147
|
+
),
|
|
148
|
+
/* @__PURE__ */ jsxs(
|
|
149
|
+
"div",
|
|
150
|
+
{
|
|
151
|
+
className: hstack({
|
|
152
|
+
justifyContent: "stretch",
|
|
153
|
+
gap: "4"
|
|
154
|
+
}),
|
|
155
|
+
children: [
|
|
156
|
+
/* @__PURE__ */ jsx(
|
|
157
|
+
Button,
|
|
158
|
+
{
|
|
159
|
+
autoFocus: true,
|
|
160
|
+
className: css({
|
|
161
|
+
w: "1/2"
|
|
162
|
+
}),
|
|
163
|
+
disabled: !isValid,
|
|
164
|
+
name: "confirm",
|
|
165
|
+
onClick: handleChoice,
|
|
166
|
+
palette,
|
|
167
|
+
value: "true",
|
|
168
|
+
children: content == null ? void 0 : content.actionText
|
|
169
|
+
}
|
|
170
|
+
),
|
|
171
|
+
/* @__PURE__ */ jsx(
|
|
172
|
+
Button,
|
|
173
|
+
{
|
|
174
|
+
className: css({
|
|
175
|
+
w: "1/2"
|
|
176
|
+
}),
|
|
177
|
+
name: "cancel",
|
|
178
|
+
onClick: handleChoice,
|
|
179
|
+
usage: "outlined",
|
|
180
|
+
value: "false",
|
|
181
|
+
children: content == null ? void 0 : content.cancelText
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
] }) })
|
|
188
|
+
] });
|
|
189
|
+
}
|
|
190
|
+
function usePromptModal() {
|
|
191
|
+
const context = useContext(PromptModalContext);
|
|
192
|
+
if (context === null) {
|
|
193
|
+
throw new Error("usePromptModal must be used within a PromptModal Provider");
|
|
194
|
+
}
|
|
195
|
+
return context;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export {
|
|
199
|
+
PromptModal,
|
|
200
|
+
usePromptModal
|
|
201
|
+
};
|
|
202
|
+
//# sourceMappingURL=chunk-WKSC2WCV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/prompt-modal.tsx"],"sourcesContent":["'use client'\n\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n type ChangeEvent,\n type MouseEvent,\n type PropsWithChildren,\n} from 'react'\nimport { Portal } from '../components/Portal'\nimport { Button } from '../components/Button'\nimport { css } from '@cerberus-design/styled-system/css'\nimport { hstack, vstack } from '@cerberus-design/styled-system/patterns'\nimport { modal } from '@cerberus-design/styled-system/recipes'\nimport { trapFocus } from '../aria-helpers/trap-focus.aria'\nimport { Input } from '../components/Input'\nimport { Field } from './field'\nimport { Label } from '../components/Label'\nimport { $cerberusIcons } from '../config/defineIcons'\nimport { ModalIcon } from '../components/ModalIcon'\nimport { Show } from '../components/Show'\n\n/**\n * This module provides a context and hook for the prompt modal.\n * @module\n */\n\nexport interface ShowPromptModalOptions {\n kind?: 'destructive' | 'non-destructive'\n heading: string\n description?: string\n key: string\n actionText: string\n cancelText: string\n}\nexport type PromptShowResult =\n | ((value: string | PromiseLike<string>) => void)\n | null\n\nexport interface PromptModalValue {\n show: (options: ShowPromptModalOptions) => Promise<string>\n}\n\nconst PromptModalContext = createContext<PromptModalValue | null>(null)\n\nexport interface PromptModalProviderProps {}\n\n/**\n * Provides a prompt modal to the app.\n * @example\n * ```tsx\n * // Wrap the Provider around the root of the feature.\n * <PromptModal>\n * <SomeFeatureSection />\n * </PromptModal>\n *\n * // Use the hook to show the prompt modal.\n * const prompt = usePromptModal()\n *\n * const handleClick = useCallback(async () => {\n * const accepted = await prompt.show({\n * kind: 'destructive',\n * heading: 'Delete channel?',\n * description:\n * 'This will permanently delete a channel on your account. There is no going back.',\n * key: CHANNEL_NAME,\n * actionText: 'Yes, delete channel',\n * cancelText: 'No, cancel',\n * })\n * // do something with accepted\n * }, [prompt])\n * ```\n */\nexport function PromptModal(\n props: PropsWithChildren<PromptModalProviderProps>,\n) {\n const dialogRef = useRef<HTMLDialogElement>(null)\n const resolveRef = useRef<PromptShowResult>(null)\n const [content, setContent] = useState<ShowPromptModalOptions | null>(null)\n const [inputValue, setInputValue] = useState<string>('')\n const focusTrap = trapFocus(dialogRef)\n const PromptIcon = $cerberusIcons.promptModal\n\n const isValid = useMemo(\n () => inputValue === content?.key,\n [inputValue, content],\n )\n\n const palette = useMemo(\n () => (content?.kind === 'destructive' ? 'danger' : 'action'),\n [content],\n )\n const styles = modal()\n\n const handleChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n setInputValue(e.currentTarget.value)\n },\n [content],\n )\n\n const handleChoice = useCallback(\n (e: MouseEvent<HTMLButtonElement>) => {\n const target = e.currentTarget as HTMLButtonElement\n if (target.value === 'true') {\n resolveRef.current?.(inputValue)\n }\n dialogRef?.current?.close()\n },\n [inputValue],\n )\n\n const handleShow = useCallback((options: ShowPromptModalOptions) => {\n return new Promise<string>((resolve) => {\n setContent({ ...options, kind: options.kind || 'non-destructive' })\n dialogRef?.current?.showModal()\n resolveRef.current = resolve\n })\n }, [])\n\n const value = useMemo(\n () => ({\n show: handleShow,\n }),\n [handleShow],\n )\n\n return (\n <PromptModalContext.Provider value={value}>\n {props.children}\n\n <Portal>\n <dialog className={styles.dialog} onKeyDown={focusTrap} ref={dialogRef}>\n <div\n className={vstack({\n alignItems: 'flex-start',\n gap: '4',\n })}\n >\n <Show\n when={palette === 'danger'}\n fallback={\n <ModalIcon palette=\"action\">\n <PromptIcon size={24} />\n </ModalIcon>\n }\n >\n <ModalIcon palette=\"danger\">\n <PromptIcon size={24} />\n </ModalIcon>\n </Show>\n <h2 className={styles.heading}>{content?.heading}</h2>\n <p className={styles.description}>{content?.description}</p>\n </div>\n\n <div\n className={vstack({\n alignItems: 'flex-start',\n mt: '4',\n mb: '8',\n })}\n >\n <Field invalid={!isValid}>\n <Label htmlFor=\"confirm\" size=\"md\">\n Type\n <strong\n className={css({\n textTransform: 'uppercase',\n })}\n >\n {content?.key}\n </strong>\n to confirm\n </Label>\n <Input\n id=\"confirm\"\n name=\"confirm\"\n onChange={handleChange}\n type=\"text\"\n />\n </Field>\n </div>\n\n <div\n className={hstack({\n justifyContent: 'stretch',\n gap: '4',\n })}\n >\n <Button\n autoFocus\n className={css({\n w: '1/2',\n })}\n disabled={!isValid}\n name=\"confirm\"\n onClick={handleChoice}\n palette={palette}\n value=\"true\"\n >\n {content?.actionText}\n </Button>\n <Button\n className={css({\n w: '1/2',\n })}\n name=\"cancel\"\n onClick={handleChoice}\n usage=\"outlined\"\n value=\"false\"\n >\n {content?.cancelText}\n </Button>\n </div>\n </dialog>\n </Portal>\n </PromptModalContext.Provider>\n )\n}\n\nexport function usePromptModal(): PromptModalValue {\n const context = useContext(PromptModalContext)\n if (context === null) {\n throw new Error('usePromptModal must be used within a PromptModal Provider')\n }\n return context\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP,SAAS,WAAW;AACpB,SAAS,QAAQ,cAAc;AAC/B,SAAS,aAAa;AAwHZ,SAUQ,KAVR;AA1FV,IAAM,qBAAqB,cAAuC,IAAI;AA8B/D,SAAS,YACd,OACA;AACA,QAAM,YAAY,OAA0B,IAAI;AAChD,QAAM,aAAa,OAAyB,IAAI;AAChD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAwC,IAAI;AAC1E,QAAM,CAAC,YAAY,aAAa,IAAI,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AAA,gBACC,WAAW,IAAI;AAAA,kBACb,GAAG;AAAA,gBACL,CAAC;AAAA,gBACD,MAAK;AAAA,gBACL,SAAS;AAAA,gBACT,OAAM;AAAA,gBACN,OAAM;AAAA,gBAEL,6CAAS;AAAA;AAAA,YACZ;AAAA;AAAA;AAAA,MACF;AAAA,OACF,GACF;AAAA,KACF;AAEJ;AAEO,SAAS,iBAAmC;AACjD,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
Input
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-ZAU4JVLL.js";
|
|
4
|
+
} from "../chunk-5GEC53G7.js";
|
|
6
5
|
import "../chunk-4O4QFF4S.js";
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-ZAU4JVLL.js";
|
|
7
|
+
import "../chunk-6TXQZ3PB.js";
|
|
8
|
+
import "../chunk-C45DY4VE.js";
|
|
9
9
|
export {
|
|
10
10
|
Input
|
|
11
11
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
Toggle
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-TAZI77TP.js";
|
|
5
5
|
import "../chunk-ZAU4JVLL.js";
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-6TXQZ3PB.js";
|
|
7
|
+
import "../chunk-C45DY4VE.js";
|
|
8
8
|
export {
|
|
9
9
|
Toggle
|
|
10
10
|
};
|