@cerberus-design/react 0.6.1-next-2d28489 → 0.6.1-next-fa4208e
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 +119 -9
- package/build/legacy/chunk-2F5TB2EV.js +25 -0
- package/build/legacy/chunk-2F5TB2EV.js.map +1 -0
- package/build/legacy/{chunk-7ISHDUYN.js → chunk-5GEC53G7.js} +4 -4
- package/build/legacy/{chunk-JJGZRBIR.js → chunk-CU7HXAKM.js} +4 -4
- package/build/legacy/chunk-D3ZXZA3U.js +155 -0
- package/build/legacy/chunk-D3ZXZA3U.js.map +1 -0
- package/build/legacy/{chunk-SNSBODYR.js → chunk-DGPLSWFJ.js} +55 -71
- package/build/legacy/chunk-DGPLSWFJ.js.map +1 -0
- package/build/legacy/chunk-G3JEWPLM.js +29 -0
- package/build/legacy/chunk-G3JEWPLM.js.map +1 -0
- package/build/legacy/chunk-OGSAAB6K.js +12 -0
- package/build/legacy/chunk-OGSAAB6K.js.map +1 -0
- package/build/legacy/chunk-TPFNVGYA.js +21 -0
- package/build/legacy/chunk-TPFNVGYA.js.map +1 -0
- package/build/legacy/chunk-TZNYJ3G7.js +25 -0
- package/build/legacy/chunk-TZNYJ3G7.js.map +1 -0
- package/build/legacy/chunk-UPODPCRD.js +12 -0
- package/build/legacy/chunk-UPODPCRD.js.map +1 -0
- package/build/legacy/components/Input.js +2 -2
- package/build/legacy/components/Label.js +2 -2
- package/build/legacy/components/Modal.js +7 -0
- package/build/legacy/components/Modal.js.map +1 -0
- package/build/legacy/components/ModalDescription.js +7 -0
- package/build/legacy/components/ModalDescription.js.map +1 -0
- package/build/legacy/components/ModalHeader.js +7 -0
- package/build/legacy/components/ModalHeader.js.map +1 -0
- package/build/legacy/components/ModalHeading.js +7 -0
- package/build/legacy/components/ModalHeading.js.map +1 -0
- package/build/legacy/components/ModalIcon.js +7 -0
- package/build/legacy/components/ModalIcon.js.map +1 -0
- package/build/legacy/context/confirm-modal.js +7 -3
- package/build/legacy/context/prompt-modal.js +10 -7
- package/build/legacy/hooks/useModal.js +8 -0
- package/build/legacy/hooks/useModal.js.map +1 -0
- package/build/legacy/index.js +59 -39
- package/build/modern/_tsup-dts-rollup.d.ts +119 -9
- package/build/modern/chunk-2F5TB2EV.js +25 -0
- package/build/modern/chunk-2F5TB2EV.js.map +1 -0
- package/build/modern/{chunk-7ISHDUYN.js → chunk-5GEC53G7.js} +4 -4
- package/build/modern/chunk-C5HLLGME.js +23 -0
- package/build/modern/chunk-C5HLLGME.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-OGSAAB6K.js +12 -0
- package/build/modern/chunk-OGSAAB6K.js.map +1 -0
- package/build/modern/chunk-TAVCJ54A.js +154 -0
- package/build/modern/chunk-TAVCJ54A.js.map +1 -0
- package/build/modern/chunk-TPFNVGYA.js +21 -0
- package/build/modern/chunk-TPFNVGYA.js.map +1 -0
- package/build/modern/chunk-UPODPCRD.js +12 -0
- package/build/modern/chunk-UPODPCRD.js.map +1 -0
- package/build/modern/{chunk-FZ75OJLJ.js → chunk-WWG5QWXY.js} +54 -69
- package/build/modern/chunk-WWG5QWXY.js.map +1 -0
- package/build/modern/components/Input.js +2 -2
- package/build/modern/components/Label.js +2 -2
- package/build/modern/components/Modal.js +7 -0
- package/build/modern/components/Modal.js.map +1 -0
- package/build/modern/components/ModalDescription.js +7 -0
- package/build/modern/components/ModalDescription.js.map +1 -0
- package/build/modern/components/ModalHeader.js +7 -0
- package/build/modern/components/ModalHeader.js.map +1 -0
- package/build/modern/components/ModalHeading.js +7 -0
- package/build/modern/components/ModalHeading.js.map +1 -0
- package/build/modern/components/ModalIcon.js +7 -0
- package/build/modern/components/ModalIcon.js.map +1 -0
- package/build/modern/context/confirm-modal.js +7 -3
- package/build/modern/context/prompt-modal.js +10 -7
- package/build/modern/hooks/useModal.js +8 -0
- package/build/modern/hooks/useModal.js.map +1 -0
- package/build/modern/index.js +59 -39
- package/package.json +2 -2
- package/src/components/Modal.tsx +37 -0
- package/src/components/ModalDescription.tsx +23 -0
- package/src/components/ModalHeader.tsx +37 -0
- package/src/components/ModalHeading.tsx +23 -0
- package/src/components/ModalIcon.tsx +28 -0
- package/src/context/confirm-modal.tsx +50 -70
- package/src/context/prompt-modal.tsx +41 -63
- package/src/hooks/useModal.ts +34 -0
- package/src/index.ts +6 -0
- package/build/legacy/chunk-BLJ4SRAF.js +0 -167
- package/build/legacy/chunk-BLJ4SRAF.js.map +0 -1
- package/build/legacy/chunk-SNSBODYR.js.map +0 -1
- package/build/modern/chunk-4GURONLE.js +0 -165
- package/build/modern/chunk-4GURONLE.js.map +0 -1
- package/build/modern/chunk-FZ75OJLJ.js.map +0 -1
- /package/build/legacy/{chunk-7ISHDUYN.js.map → chunk-5GEC53G7.js.map} +0 -0
- /package/build/legacy/{chunk-JJGZRBIR.js.map → chunk-CU7HXAKM.js.map} +0 -0
- /package/build/modern/{chunk-7ISHDUYN.js.map → chunk-5GEC53G7.js.map} +0 -0
- /package/build/modern/{chunk-JJGZRBIR.js.map → chunk-CU7HXAKM.js.map} +0 -0
|
@@ -3,10 +3,10 @@ import { button } from '@cerberus/styled-system/recipes';
|
|
|
3
3
|
import { ButtonHTMLAttributes } from 'react';
|
|
4
4
|
import { CarbonIconType } from '@cerberus/icons';
|
|
5
5
|
import { ChangeEvent } from 'react';
|
|
6
|
-
import { ConfirmModalVariantProps } from '@cerberus-design/styled-system/recipes';
|
|
7
6
|
import { Context } from 'react';
|
|
8
7
|
import { ElementType } from 'react';
|
|
9
8
|
import { fieldMessage } from '@cerberus/styled-system/recipes';
|
|
9
|
+
import { ForwardRefExoticComponent } from 'react';
|
|
10
10
|
import { HTMLAttributes } from 'react';
|
|
11
11
|
import { iconButton } from '@cerberus/styled-system/recipes';
|
|
12
12
|
import { input } from '@cerberus/styled-system/recipes';
|
|
@@ -14,6 +14,7 @@ import type { InputHTMLAttributes } from 'react';
|
|
|
14
14
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
15
15
|
import type { KeyboardEventHandler } from 'react';
|
|
16
16
|
import { label } from '@cerberus/styled-system/recipes';
|
|
17
|
+
import { ModalIconVariantProps } from '@cerberus-design/styled-system/recipes';
|
|
17
18
|
import { MutableRefObject } from 'react';
|
|
18
19
|
import type { Pretty } from '@cerberus-design/styled-system/types';
|
|
19
20
|
import { PropsWithChildren } from 'react';
|
|
@@ -23,6 +24,7 @@ import { ReactPortal } from 'react';
|
|
|
23
24
|
import { RecipeVariantProps } from '@cerberus/styled-system/css';
|
|
24
25
|
import type { RecipeVariantProps as RecipeVariantProps_2 } from '@cerberus-design/styled-system/types';
|
|
25
26
|
import type { RecipeVariantProps as RecipeVariantProps_3 } from '@cerberus/styled-system/types';
|
|
27
|
+
import { RefAttributes } from 'react';
|
|
26
28
|
import { RefObject } from 'react';
|
|
27
29
|
import { TabsVariantProps } from '@cerberus-design/styled-system/recipes';
|
|
28
30
|
import { tag } from '@cerberus/styled-system/recipes';
|
|
@@ -91,10 +93,6 @@ declare function ConfirmModal(props: PropsWithChildren<ConfirmModalProviderProps
|
|
|
91
93
|
export { ConfirmModal }
|
|
92
94
|
export { ConfirmModal as ConfirmModal_alias_1 }
|
|
93
95
|
|
|
94
|
-
declare function ConfirmModalIcon(props: ConfirmModalVariantProps): JSX_2.Element;
|
|
95
|
-
export { ConfirmModalIcon }
|
|
96
|
-
export { ConfirmModalIcon as ConfirmModalIcon_alias_1 }
|
|
97
|
-
|
|
98
96
|
declare interface ConfirmModalProviderProps {
|
|
99
97
|
}
|
|
100
98
|
export { ConfirmModalProviderProps }
|
|
@@ -325,6 +323,108 @@ declare type LabelRecipeProps = RecipeVariantProps<typeof label>;
|
|
|
325
323
|
export { LabelRecipeProps }
|
|
326
324
|
export { LabelRecipeProps as LabelRecipeProps_alias_1 }
|
|
327
325
|
|
|
326
|
+
/**
|
|
327
|
+
* The Modal component is the root element for a customizable modal.
|
|
328
|
+
* @example
|
|
329
|
+
* ```tsx
|
|
330
|
+
* const { modalRef } = useModal()
|
|
331
|
+
*
|
|
332
|
+
* <Modal ref={modalRef}>
|
|
333
|
+
* <ModalIcon icon={$cerberusIcons.alert} />
|
|
334
|
+
* <h2>Modal Heading</h2>
|
|
335
|
+
* <p>Modal description</p>
|
|
336
|
+
* </Modal>
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
declare const Modal: ForwardRefExoticComponent<ModalProps & RefAttributes<HTMLDialogElement>>;
|
|
340
|
+
export { Modal }
|
|
341
|
+
export { Modal as Modal_alias_1 }
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The ModalDescription component is a heading element for a customizable modal.
|
|
345
|
+
* @example
|
|
346
|
+
* ```tsx
|
|
347
|
+
* <Modal>
|
|
348
|
+
* <ModalDescription>Modal Heading</ModalDescription>
|
|
349
|
+
* </Modal>
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
declare function ModalDescription(props: ModalDescriptionProps): JSX_2.Element;
|
|
353
|
+
export { ModalDescription }
|
|
354
|
+
export { ModalDescription as ModalDescription_alias_1 }
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* This module contains the ModalDescription component for a customizable modal.
|
|
358
|
+
* @module
|
|
359
|
+
*/
|
|
360
|
+
declare type ModalDescriptionProps = HTMLAttributes<HTMLParagraphElement>;
|
|
361
|
+
export { ModalDescriptionProps }
|
|
362
|
+
export { ModalDescriptionProps as ModalDescriptionProps_alias_1 }
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* The ModalHeader component is a header element for a customizable modal.
|
|
366
|
+
* @example
|
|
367
|
+
* ```tsx
|
|
368
|
+
* <Modal>
|
|
369
|
+
* <ModalHeader>
|
|
370
|
+
* <h2>Modal Heading</h2>
|
|
371
|
+
* </ModalHeader>
|
|
372
|
+
* </Modal>
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
declare function ModalHeader(props: ModalHeaderProps): JSX_2.Element;
|
|
376
|
+
export { ModalHeader }
|
|
377
|
+
export { ModalHeader as ModalHeader_alias_1 }
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* This module contains the ModalHeader component for a customizable modal.
|
|
381
|
+
* @module
|
|
382
|
+
*/
|
|
383
|
+
declare type ModalHeaderProps = HTMLAttributes<HTMLDivElement>;
|
|
384
|
+
export { ModalHeaderProps }
|
|
385
|
+
export { ModalHeaderProps as ModalHeaderProps_alias_1 }
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* The ModalHeading component is a heading element for a customizable modal.
|
|
389
|
+
* @example
|
|
390
|
+
* ```tsx
|
|
391
|
+
* <Modal>
|
|
392
|
+
* <ModalHeading>Modal Heading</ModalHeading>
|
|
393
|
+
* </Modal>
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
declare function ModalHeading(props: ModalHeadingProps): JSX_2.Element;
|
|
397
|
+
export { ModalHeading }
|
|
398
|
+
export { ModalHeading as ModalHeading_alias_1 }
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* This module contains the ModalHeading component for a customizable modal.
|
|
402
|
+
* @module
|
|
403
|
+
*/
|
|
404
|
+
declare type ModalHeadingProps = HTMLAttributes<HTMLParagraphElement>;
|
|
405
|
+
export { ModalHeadingProps }
|
|
406
|
+
export { ModalHeadingProps as ModalHeadingProps_alias_1 }
|
|
407
|
+
|
|
408
|
+
declare function ModalIcon(props: PropsWithChildren<ModalIconProps>): JSX_2.Element;
|
|
409
|
+
export { ModalIcon }
|
|
410
|
+
export { ModalIcon as ModalIcon_alias_1 }
|
|
411
|
+
|
|
412
|
+
declare type ModalIconBaseProps = HTMLAttributes<HTMLDivElement>;
|
|
413
|
+
export { ModalIconBaseProps }
|
|
414
|
+
export { ModalIconBaseProps as ModalIconBaseProps_alias_1 }
|
|
415
|
+
|
|
416
|
+
declare type ModalIconProps = ModalIconBaseProps & ModalIconVariantProps;
|
|
417
|
+
export { ModalIconProps }
|
|
418
|
+
export { ModalIconProps as ModalIconProps_alias_1 }
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* This module contains the Modal root component for a customizable modal.
|
|
422
|
+
* @module
|
|
423
|
+
*/
|
|
424
|
+
declare type ModalProps = HTMLAttributes<HTMLDialogElement>;
|
|
425
|
+
export { ModalProps }
|
|
426
|
+
export { ModalProps as ModalProps_alias_1 }
|
|
427
|
+
|
|
328
428
|
declare const MODE_KEY = "cerberus-mode";
|
|
329
429
|
export { MODE_KEY }
|
|
330
430
|
export { MODE_KEY as MODE_KEY_alias_1 }
|
|
@@ -472,10 +572,6 @@ declare function PromptModal(props: PropsWithChildren<PromptModalProviderProps>)
|
|
|
472
572
|
export { PromptModal }
|
|
473
573
|
export { PromptModal as PromptModal_alias_1 }
|
|
474
574
|
|
|
475
|
-
declare function PromptModalIcon(props: ConfirmModalVariantProps): JSX_2.Element;
|
|
476
|
-
export { PromptModalIcon }
|
|
477
|
-
export { PromptModalIcon as PromptModalIcon_alias_1 }
|
|
478
|
-
|
|
479
575
|
declare interface PromptModalProviderProps {
|
|
480
576
|
}
|
|
481
577
|
export { PromptModalProviderProps }
|
|
@@ -805,6 +901,20 @@ declare function useFieldContext(): FieldContextValue;
|
|
|
805
901
|
export { useFieldContext }
|
|
806
902
|
export { useFieldContext as useFieldContext_alias_1 }
|
|
807
903
|
|
|
904
|
+
declare function useModal(): UseModalReturnValue;
|
|
905
|
+
export { useModal }
|
|
906
|
+
export { useModal as useModal_alias_1 }
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* This module provides a hook for using a custom modal.
|
|
910
|
+
* @module
|
|
911
|
+
*/
|
|
912
|
+
declare interface UseModalReturnValue {
|
|
913
|
+
modalRef: RefObject<HTMLDialogElement>;
|
|
914
|
+
show: () => void;
|
|
915
|
+
close: () => void;
|
|
916
|
+
}
|
|
917
|
+
|
|
808
918
|
declare function useNavMenuContext(): NavMenuContextValue;
|
|
809
919
|
export { useNavMenuContext }
|
|
810
920
|
export { useNavMenuContext as useNavMenuContext_alias_1 }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/components/ModalHeader.tsx
|
|
2
|
+
import { cx } from "@cerberus-design/styled-system/css";
|
|
3
|
+
import { vstack } from "@cerberus-design/styled-system/patterns";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
function ModalHeader(props) {
|
|
6
|
+
return /* @__PURE__ */ jsx(
|
|
7
|
+
"div",
|
|
8
|
+
{
|
|
9
|
+
...props,
|
|
10
|
+
className: cx(
|
|
11
|
+
props.className,
|
|
12
|
+
vstack({
|
|
13
|
+
alignItems: "flex-start",
|
|
14
|
+
gap: "4",
|
|
15
|
+
mb: "8"
|
|
16
|
+
})
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
ModalHeader
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-2F5TB2EV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/ModalHeader.tsx"],"sourcesContent":["import { cx } from '@cerberus-design/styled-system/css'\nimport { vstack } from '@cerberus-design/styled-system/patterns'\nimport type { HTMLAttributes } from 'react'\n\n/**\n * This module contains the ModalHeader component for a customizable modal.\n * @module\n */\n\nexport type ModalHeaderProps = HTMLAttributes<HTMLDivElement>\n\n/**\n * The ModalHeader component is a header element for a customizable modal.\n * @example\n * ```tsx\n * <Modal>\n * <ModalHeader>\n * <h2>Modal Heading</h2>\n * </ModalHeader>\n * </Modal>\n * ```\n */\nexport function ModalHeader(props: ModalHeaderProps) {\n return (\n <div\n {...props}\n className={cx(\n props.className,\n vstack({\n alignItems: 'flex-start',\n gap: '4',\n mb: '8',\n }),\n )}\n />\n )\n}\n"],"mappings":";AAAA,SAAS,UAAU;AACnB,SAAS,cAAc;AAuBnB;AAFG,SAAS,YAAY,OAAyB;AACnD,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,WAAW;AAAA,QACT,MAAM;AAAA,QACN,OAAO;AAAA,UACL,YAAY;AAAA,UACZ,KAAK;AAAA,UACL,IAAI;AAAA,QACN,CAAC;AAAA,MACH;AAAA;AAAA,EACF;AAEJ;","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
|
import {
|
|
8
8
|
$cerberusIcons
|
|
9
9
|
} from "./chunk-6TXQZ3PB.js";
|
|
@@ -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,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,155 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Portal
|
|
3
|
+
} from "./chunk-4CAT3FHV.js";
|
|
4
|
+
import {
|
|
5
|
+
Modal
|
|
6
|
+
} from "./chunk-TPFNVGYA.js";
|
|
7
|
+
import {
|
|
8
|
+
ModalDescription
|
|
9
|
+
} from "./chunk-UPODPCRD.js";
|
|
10
|
+
import {
|
|
11
|
+
ModalHeader
|
|
12
|
+
} from "./chunk-2F5TB2EV.js";
|
|
13
|
+
import {
|
|
14
|
+
ModalHeading
|
|
15
|
+
} from "./chunk-OGSAAB6K.js";
|
|
16
|
+
import {
|
|
17
|
+
ModalIcon
|
|
18
|
+
} from "./chunk-G3JEWPLM.js";
|
|
19
|
+
import {
|
|
20
|
+
Button
|
|
21
|
+
} from "./chunk-2ATICEW3.js";
|
|
22
|
+
import {
|
|
23
|
+
Show
|
|
24
|
+
} from "./chunk-4O4QFF4S.js";
|
|
25
|
+
import {
|
|
26
|
+
trapFocus
|
|
27
|
+
} from "./chunk-KESKDLX6.js";
|
|
28
|
+
import {
|
|
29
|
+
$cerberusIcons
|
|
30
|
+
} from "./chunk-6TXQZ3PB.js";
|
|
31
|
+
import {
|
|
32
|
+
useModal
|
|
33
|
+
} from "./chunk-TZNYJ3G7.js";
|
|
34
|
+
|
|
35
|
+
// src/context/confirm-modal.tsx
|
|
36
|
+
import {
|
|
37
|
+
createContext,
|
|
38
|
+
useCallback,
|
|
39
|
+
useContext,
|
|
40
|
+
useMemo,
|
|
41
|
+
useRef,
|
|
42
|
+
useState
|
|
43
|
+
} from "react";
|
|
44
|
+
import { css } from "@cerberus-design/styled-system/css";
|
|
45
|
+
import { hstack } from "@cerberus-design/styled-system/patterns";
|
|
46
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
47
|
+
var ConfirmModalContext = createContext(null);
|
|
48
|
+
function ConfirmModal(props) {
|
|
49
|
+
const { modalRef, show, close } = useModal();
|
|
50
|
+
const resolveRef = useRef(null);
|
|
51
|
+
const [content, setContent] = useState(null);
|
|
52
|
+
const focusTrap = trapFocus(modalRef);
|
|
53
|
+
const ConfirmIcon = $cerberusIcons.confirmModal;
|
|
54
|
+
const palette = useMemo(
|
|
55
|
+
() => (content == null ? void 0 : content.kind) === "destructive" ? "danger" : "action",
|
|
56
|
+
[content]
|
|
57
|
+
);
|
|
58
|
+
const handleChoice = useCallback(
|
|
59
|
+
(e) => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
const target = e.currentTarget;
|
|
62
|
+
if (target.value === "true") {
|
|
63
|
+
(_a = resolveRef.current) == null ? void 0 : _a.call(resolveRef, true);
|
|
64
|
+
}
|
|
65
|
+
(_b = resolveRef.current) == null ? void 0 : _b.call(resolveRef, false);
|
|
66
|
+
close();
|
|
67
|
+
},
|
|
68
|
+
[close]
|
|
69
|
+
);
|
|
70
|
+
const handleShow = useCallback(
|
|
71
|
+
(options) => {
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
setContent({ ...options, kind: options.kind || "non-destructive" });
|
|
74
|
+
show();
|
|
75
|
+
resolveRef.current = resolve;
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
[show]
|
|
79
|
+
);
|
|
80
|
+
const value = useMemo(
|
|
81
|
+
() => ({
|
|
82
|
+
show: handleShow
|
|
83
|
+
}),
|
|
84
|
+
[handleShow]
|
|
85
|
+
);
|
|
86
|
+
return /* @__PURE__ */ jsxs(ConfirmModalContext.Provider, { value, children: [
|
|
87
|
+
props.children,
|
|
88
|
+
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs(Modal, { onKeyDown: focusTrap, ref: modalRef, children: [
|
|
89
|
+
/* @__PURE__ */ jsxs(ModalHeader, { children: [
|
|
90
|
+
/* @__PURE__ */ jsx(
|
|
91
|
+
Show,
|
|
92
|
+
{
|
|
93
|
+
when: palette === "danger",
|
|
94
|
+
fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) }),
|
|
95
|
+
children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) })
|
|
96
|
+
}
|
|
97
|
+
),
|
|
98
|
+
/* @__PURE__ */ jsx(ModalHeading, { children: content == null ? void 0 : content.heading }),
|
|
99
|
+
/* @__PURE__ */ jsx(ModalDescription, { children: content == null ? void 0 : content.description })
|
|
100
|
+
] }),
|
|
101
|
+
/* @__PURE__ */ jsxs(
|
|
102
|
+
"div",
|
|
103
|
+
{
|
|
104
|
+
className: hstack({
|
|
105
|
+
gap: "4"
|
|
106
|
+
}),
|
|
107
|
+
children: [
|
|
108
|
+
/* @__PURE__ */ jsx(
|
|
109
|
+
Button,
|
|
110
|
+
{
|
|
111
|
+
autoFocus: true,
|
|
112
|
+
className: css({
|
|
113
|
+
w: "1/2"
|
|
114
|
+
}),
|
|
115
|
+
name: "confirm",
|
|
116
|
+
onClick: handleChoice,
|
|
117
|
+
palette,
|
|
118
|
+
value: "true",
|
|
119
|
+
children: content == null ? void 0 : content.actionText
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
/* @__PURE__ */ jsx(
|
|
123
|
+
Button,
|
|
124
|
+
{
|
|
125
|
+
className: css({
|
|
126
|
+
w: "1/2"
|
|
127
|
+
}),
|
|
128
|
+
name: "cancel",
|
|
129
|
+
onClick: handleChoice,
|
|
130
|
+
usage: "outlined",
|
|
131
|
+
value: "false",
|
|
132
|
+
children: content == null ? void 0 : content.cancelText
|
|
133
|
+
}
|
|
134
|
+
)
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
] }) })
|
|
139
|
+
] });
|
|
140
|
+
}
|
|
141
|
+
function useConfirmModal() {
|
|
142
|
+
const context = useContext(ConfirmModalContext);
|
|
143
|
+
if (context === null) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
"useConfirmModal must be used within a ConfirmModal Provider"
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return context;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export {
|
|
152
|
+
ConfirmModal,
|
|
153
|
+
useConfirmModal
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=chunk-D3ZXZA3U.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 } from '@cerberus-design/styled-system/patterns'\nimport { $cerberusIcons } from '../config/defineIcons'\nimport { trapFocus } from '../aria-helpers/trap-focus.aria'\nimport { ModalIcon } from '../components/ModalIcon'\nimport { Show } from '../components/Show'\nimport { Modal } from '../components/Modal'\nimport { useModal } from '../hooks/useModal'\nimport { ModalHeader } from '../components/ModalHeader'\nimport { ModalHeading } from '../components/ModalHeading'\nimport { ModalDescription } from '../components/ModalDescription'\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 { modalRef, show, close } = useModal()\n const resolveRef = useRef<ShowResult>(null)\n const [content, setContent] = useState<ShowConfirmModalOptions | null>(null)\n const focusTrap = trapFocus(modalRef)\n const ConfirmIcon = $cerberusIcons.confirmModal\n\n const palette = useMemo(\n () => (content?.kind === 'destructive' ? 'danger' : 'action'),\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?.(true)\n }\n resolveRef.current?.(false)\n close()\n },\n [close],\n )\n\n const handleShow = useCallback(\n (options: ShowConfirmModalOptions) => {\n return new Promise<boolean>((resolve) => {\n setContent({ ...options, kind: options.kind || 'non-destructive' })\n show()\n resolveRef.current = resolve\n })\n },\n [show],\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 <Modal onKeyDown={focusTrap} ref={modalRef}>\n <ModalHeader>\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 <ModalHeading>{content?.heading}</ModalHeading>\n <ModalDescription>{content?.description}</ModalDescription>\n </ModalHeader>\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 </Modal>\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,cAAc;AA6Gb,SAKQ,KALR;AA9EV,IAAM,sBAAsB,cAAwC,IAAI;AA4BjE,SAAS,aACd,OACA;AACA,QAAM,EAAE,UAAU,MAAM,MAAM,IAAI,SAAS;AAC3C,QAAM,aAAa,OAAmB,IAAI;AAC1C,QAAM,CAAC,SAAS,UAAU,IAAI,SAAyC,IAAI;AAC3E,QAAM,YAAY,UAAU,QAAQ;AACpC,QAAM,cAAc,eAAe;AAEnC,QAAM,UAAU;AAAA,IACd,OAAO,mCAAS,UAAS,gBAAgB,WAAW;AAAA,IACpD,CAAC,OAAO;AAAA,EACV;AAEA,QAAM,eAAe;AAAA,IACnB,CAAC,MAAqC;AAzF1C;AA0FM,YAAM,SAAS,EAAE;AACjB,UAAI,OAAO,UAAU,QAAQ;AAC3B,yBAAW,YAAX,oCAAqB;AAAA,MACvB;AACA,uBAAW,YAAX,oCAAqB;AACrB,YAAM;AAAA,IACR;AAAA,IACA,CAAC,KAAK;AAAA,EACR;AAEA,QAAM,aAAa;AAAA,IACjB,CAAC,YAAqC;AACpC,aAAO,IAAI,QAAiB,CAAC,YAAY;AACvC,mBAAW,EAAE,GAAG,SAAS,MAAM,QAAQ,QAAQ,kBAAkB,CAAC;AAClE,aAAK;AACL,mBAAW,UAAU;AAAA,MACvB,CAAC;AAAA,IACH;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,QAAM,QAAQ;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}
|
|
@@ -1,30 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConfirmModalIcon
|
|
3
|
-
} from "./chunk-BLJ4SRAF.js";
|
|
4
1
|
import {
|
|
5
2
|
Portal
|
|
6
3
|
} from "./chunk-4CAT3FHV.js";
|
|
4
|
+
import {
|
|
5
|
+
Modal
|
|
6
|
+
} from "./chunk-TPFNVGYA.js";
|
|
7
|
+
import {
|
|
8
|
+
ModalDescription
|
|
9
|
+
} from "./chunk-UPODPCRD.js";
|
|
10
|
+
import {
|
|
11
|
+
ModalHeader
|
|
12
|
+
} from "./chunk-2F5TB2EV.js";
|
|
13
|
+
import {
|
|
14
|
+
ModalHeading
|
|
15
|
+
} from "./chunk-OGSAAB6K.js";
|
|
16
|
+
import {
|
|
17
|
+
ModalIcon
|
|
18
|
+
} from "./chunk-G3JEWPLM.js";
|
|
7
19
|
import {
|
|
8
20
|
Button
|
|
9
21
|
} from "./chunk-2ATICEW3.js";
|
|
10
22
|
import {
|
|
11
23
|
Input
|
|
12
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-5GEC53G7.js";
|
|
13
25
|
import {
|
|
14
26
|
Label
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import {
|
|
17
|
-
Field
|
|
18
|
-
} from "./chunk-ZAU4JVLL.js";
|
|
27
|
+
} from "./chunk-CU7HXAKM.js";
|
|
19
28
|
import {
|
|
20
29
|
Show
|
|
21
30
|
} from "./chunk-4O4QFF4S.js";
|
|
31
|
+
import {
|
|
32
|
+
Field
|
|
33
|
+
} from "./chunk-ZAU4JVLL.js";
|
|
22
34
|
import {
|
|
23
35
|
trapFocus
|
|
24
36
|
} from "./chunk-KESKDLX6.js";
|
|
25
37
|
import {
|
|
26
38
|
$cerberusIcons
|
|
27
39
|
} from "./chunk-6TXQZ3PB.js";
|
|
40
|
+
import {
|
|
41
|
+
useModal
|
|
42
|
+
} from "./chunk-TZNYJ3G7.js";
|
|
28
43
|
|
|
29
44
|
// src/context/prompt-modal.tsx
|
|
30
45
|
import {
|
|
@@ -35,19 +50,17 @@ import {
|
|
|
35
50
|
useRef,
|
|
36
51
|
useState
|
|
37
52
|
} from "react";
|
|
38
|
-
import { css
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
confirmModal
|
|
42
|
-
} from "@cerberus-design/styled-system/recipes";
|
|
53
|
+
import { css } from "@cerberus-design/styled-system/css";
|
|
54
|
+
import { hstack, vstack } from "@cerberus-design/styled-system/patterns";
|
|
43
55
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
44
56
|
var PromptModalContext = createContext(null);
|
|
45
57
|
function PromptModal(props) {
|
|
46
|
-
const
|
|
58
|
+
const { modalRef, show, close } = useModal();
|
|
47
59
|
const resolveRef = useRef(null);
|
|
48
60
|
const [content, setContent] = useState(null);
|
|
49
61
|
const [inputValue, setInputValue] = useState("");
|
|
50
|
-
const focusTrap = trapFocus(
|
|
62
|
+
const focusTrap = trapFocus(modalRef);
|
|
63
|
+
const PromptIcon = $cerberusIcons.promptModal;
|
|
51
64
|
const isValid = useMemo(
|
|
52
65
|
() => inputValue === (content == null ? void 0 : content.key),
|
|
53
66
|
[inputValue, content]
|
|
@@ -56,7 +69,6 @@ function PromptModal(props) {
|
|
|
56
69
|
() => (content == null ? void 0 : content.kind) === "destructive" ? "danger" : "action",
|
|
57
70
|
[content]
|
|
58
71
|
);
|
|
59
|
-
const styles = confirmModal({ palette });
|
|
60
72
|
const handleChange = useCallback(
|
|
61
73
|
(e) => {
|
|
62
74
|
setInputValue(e.currentTarget.value);
|
|
@@ -65,23 +77,25 @@ function PromptModal(props) {
|
|
|
65
77
|
);
|
|
66
78
|
const handleChoice = useCallback(
|
|
67
79
|
(e) => {
|
|
68
|
-
var _a
|
|
80
|
+
var _a;
|
|
69
81
|
const target = e.currentTarget;
|
|
70
82
|
if (target.value === "true") {
|
|
71
83
|
(_a = resolveRef.current) == null ? void 0 : _a.call(resolveRef, inputValue);
|
|
72
84
|
}
|
|
73
|
-
|
|
85
|
+
close();
|
|
74
86
|
},
|
|
75
|
-
[inputValue]
|
|
87
|
+
[inputValue, close]
|
|
88
|
+
);
|
|
89
|
+
const handleShow = useCallback(
|
|
90
|
+
(options) => {
|
|
91
|
+
return new Promise((resolve) => {
|
|
92
|
+
setContent({ ...options, kind: options.kind || "non-destructive" });
|
|
93
|
+
show();
|
|
94
|
+
resolveRef.current = resolve;
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
[show]
|
|
76
98
|
);
|
|
77
|
-
const handleShow = useCallback((options) => {
|
|
78
|
-
return new Promise((resolve) => {
|
|
79
|
-
var _a;
|
|
80
|
-
setContent({ ...options, kind: options.kind || "non-destructive" });
|
|
81
|
-
(_a = dialogRef == null ? void 0 : dialogRef.current) == null ? void 0 : _a.showModal();
|
|
82
|
-
resolveRef.current = resolve;
|
|
83
|
-
});
|
|
84
|
-
}, []);
|
|
85
99
|
const value = useMemo(
|
|
86
100
|
() => ({
|
|
87
101
|
show: handleShow
|
|
@@ -90,21 +104,19 @@ function PromptModal(props) {
|
|
|
90
104
|
);
|
|
91
105
|
return /* @__PURE__ */ jsxs(PromptModalContext.Provider, { value, children: [
|
|
92
106
|
props.children,
|
|
93
|
-
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs(
|
|
94
|
-
/* @__PURE__ */ jsxs(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
),
|
|
107
|
+
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs(Modal, { onKeyDown: focusTrap, ref: modalRef, children: [
|
|
108
|
+
/* @__PURE__ */ jsxs(ModalHeader, { children: [
|
|
109
|
+
/* @__PURE__ */ jsx(
|
|
110
|
+
Show,
|
|
111
|
+
{
|
|
112
|
+
when: palette === "danger",
|
|
113
|
+
fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) }),
|
|
114
|
+
children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) })
|
|
115
|
+
}
|
|
116
|
+
),
|
|
117
|
+
/* @__PURE__ */ jsx(ModalHeading, { children: content == null ? void 0 : content.heading }),
|
|
118
|
+
/* @__PURE__ */ jsx(ModalDescription, { children: content == null ? void 0 : content.description })
|
|
119
|
+
] }),
|
|
108
120
|
/* @__PURE__ */ jsx(
|
|
109
121
|
"div",
|
|
110
122
|
{
|
|
@@ -181,33 +193,6 @@ function PromptModal(props) {
|
|
|
181
193
|
] }) })
|
|
182
194
|
] });
|
|
183
195
|
}
|
|
184
|
-
function PromptModalIcon(props) {
|
|
185
|
-
const PromptIcon = $cerberusIcons.promptModal;
|
|
186
|
-
return /* @__PURE__ */ jsx(
|
|
187
|
-
Show,
|
|
188
|
-
{
|
|
189
|
-
when: props.palette === "danger",
|
|
190
|
-
fallback: /* @__PURE__ */ jsx("div", { className: cx(confirmModal().icon, circle()), children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) }),
|
|
191
|
-
children: /* @__PURE__ */ jsx(
|
|
192
|
-
"div",
|
|
193
|
-
{
|
|
194
|
-
className: cx(
|
|
195
|
-
confirmModal({
|
|
196
|
-
palette: "danger"
|
|
197
|
-
}).icon,
|
|
198
|
-
circle({
|
|
199
|
-
bgColor: "danger.surface.initial"
|
|
200
|
-
})
|
|
201
|
-
),
|
|
202
|
-
style: {
|
|
203
|
-
color: "var(--cerberus-colors-danger-text-100)"
|
|
204
|
-
},
|
|
205
|
-
children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 })
|
|
206
|
-
}
|
|
207
|
-
)
|
|
208
|
-
}
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
196
|
function usePromptModal() {
|
|
212
197
|
const context = useContext(PromptModalContext);
|
|
213
198
|
if (context === null) {
|
|
@@ -218,7 +203,6 @@ function usePromptModal() {
|
|
|
218
203
|
|
|
219
204
|
export {
|
|
220
205
|
PromptModal,
|
|
221
|
-
PromptModalIcon,
|
|
222
206
|
usePromptModal
|
|
223
207
|
};
|
|
224
|
-
//# sourceMappingURL=chunk-
|
|
208
|
+
//# sourceMappingURL=chunk-DGPLSWFJ.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 { 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'\nimport { useModal } from '../hooks/useModal'\nimport { Modal } from '../components/Modal'\nimport { ModalHeader } from '../components/ModalHeader'\nimport { ModalHeading } from '../components/ModalHeading'\nimport { ModalDescription } from '../components/ModalDescription'\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 { modalRef, show, close } = useModal()\n const resolveRef = useRef<PromptShowResult>(null)\n const [content, setContent] = useState<ShowPromptModalOptions | null>(null)\n const [inputValue, setInputValue] = useState<string>('')\n const focusTrap = trapFocus(modalRef)\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\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 close()\n },\n [inputValue, close],\n )\n\n const handleShow = useCallback(\n (options: ShowPromptModalOptions) => {\n return new Promise<string>((resolve) => {\n setContent({ ...options, kind: options.kind || 'non-destructive' })\n show()\n resolveRef.current = resolve\n })\n },\n [show],\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 <Modal onKeyDown={focusTrap} ref={modalRef}>\n <ModalHeader>\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 <ModalHeading>{content?.heading}</ModalHeading>\n <ModalDescription>{content?.description}</ModalDescription>\n </ModalHeader>\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 </Modal>\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;AA+HrB,SAKQ,KALR;AA5FV,IAAM,qBAAqB,cAAuC,IAAI;AA8B/D,SAAS,YACd,OACA;AACA,QAAM,EAAE,UAAU,MAAM,MAAM,IAAI,SAAS;AAC3C,QAAM,aAAa,OAAyB,IAAI;AAChD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAwC,IAAI;AAC1E,QAAM,CAAC,YAAY,aAAa,IAAI,SAAiB,EAAE;AACvD,QAAM,YAAY,UAAU,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AAS,iBAAmC;AACjD,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AACA,SAAO;AACT;","names":[]}
|
|
@@ -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":[]}
|