@cerberus-design/react 0.6.1-next-8062b70 → 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.
Files changed (69) hide show
  1. package/build/legacy/_tsup-dts-rollup.d.ts +106 -0
  2. package/build/legacy/chunk-2F5TB2EV.js +25 -0
  3. package/build/legacy/chunk-2F5TB2EV.js.map +1 -0
  4. package/build/legacy/{chunk-UZIN7UOS.js → chunk-D3ZXZA3U.js} +57 -49
  5. package/build/legacy/chunk-D3ZXZA3U.js.map +1 -0
  6. package/build/legacy/{chunk-WKSC2WCV.js → chunk-DGPLSWFJ.js} +47 -41
  7. package/build/legacy/chunk-DGPLSWFJ.js.map +1 -0
  8. package/build/legacy/chunk-OGSAAB6K.js +12 -0
  9. package/build/legacy/chunk-OGSAAB6K.js.map +1 -0
  10. package/build/legacy/chunk-TPFNVGYA.js +21 -0
  11. package/build/legacy/chunk-TPFNVGYA.js.map +1 -0
  12. package/build/legacy/chunk-TZNYJ3G7.js +25 -0
  13. package/build/legacy/chunk-TZNYJ3G7.js.map +1 -0
  14. package/build/legacy/chunk-UPODPCRD.js +12 -0
  15. package/build/legacy/chunk-UPODPCRD.js.map +1 -0
  16. package/build/legacy/components/Modal.js +7 -0
  17. package/build/legacy/components/Modal.js.map +1 -0
  18. package/build/legacy/components/ModalDescription.js +7 -0
  19. package/build/legacy/components/ModalDescription.js.map +1 -0
  20. package/build/legacy/components/ModalHeader.js +7 -0
  21. package/build/legacy/components/ModalHeader.js.map +1 -0
  22. package/build/legacy/components/ModalHeading.js +7 -0
  23. package/build/legacy/components/ModalHeading.js.map +1 -0
  24. package/build/legacy/context/confirm-modal.js +7 -2
  25. package/build/legacy/context/prompt-modal.js +7 -2
  26. package/build/legacy/hooks/useModal.js +8 -0
  27. package/build/legacy/hooks/useModal.js.map +1 -0
  28. package/build/legacy/index.js +46 -26
  29. package/build/modern/_tsup-dts-rollup.d.ts +106 -0
  30. package/build/modern/chunk-2F5TB2EV.js +25 -0
  31. package/build/modern/chunk-2F5TB2EV.js.map +1 -0
  32. package/build/modern/chunk-C5HLLGME.js +23 -0
  33. package/build/modern/chunk-C5HLLGME.js.map +1 -0
  34. package/build/modern/chunk-OGSAAB6K.js +12 -0
  35. package/build/modern/chunk-OGSAAB6K.js.map +1 -0
  36. package/build/modern/{chunk-X2GKC3IU.js → chunk-TAVCJ54A.js} +56 -47
  37. package/build/modern/chunk-TAVCJ54A.js.map +1 -0
  38. package/build/modern/chunk-TPFNVGYA.js +21 -0
  39. package/build/modern/chunk-TPFNVGYA.js.map +1 -0
  40. package/build/modern/chunk-UPODPCRD.js +12 -0
  41. package/build/modern/chunk-UPODPCRD.js.map +1 -0
  42. package/build/modern/{chunk-YHJTKBVE.js → chunk-WWG5QWXY.js} +46 -39
  43. package/build/modern/chunk-WWG5QWXY.js.map +1 -0
  44. package/build/modern/components/Modal.js +7 -0
  45. package/build/modern/components/Modal.js.map +1 -0
  46. package/build/modern/components/ModalDescription.js +7 -0
  47. package/build/modern/components/ModalDescription.js.map +1 -0
  48. package/build/modern/components/ModalHeader.js +7 -0
  49. package/build/modern/components/ModalHeader.js.map +1 -0
  50. package/build/modern/components/ModalHeading.js +7 -0
  51. package/build/modern/components/ModalHeading.js.map +1 -0
  52. package/build/modern/context/confirm-modal.js +7 -2
  53. package/build/modern/context/prompt-modal.js +7 -2
  54. package/build/modern/hooks/useModal.js +8 -0
  55. package/build/modern/hooks/useModal.js.map +1 -0
  56. package/build/modern/index.js +46 -26
  57. package/package.json +2 -2
  58. package/src/components/Modal.tsx +37 -0
  59. package/src/components/ModalDescription.tsx +23 -0
  60. package/src/components/ModalHeader.tsx +37 -0
  61. package/src/components/ModalHeading.tsx +23 -0
  62. package/src/context/confirm-modal.tsx +35 -32
  63. package/src/context/prompt-modal.tsx +25 -24
  64. package/src/hooks/useModal.ts +34 -0
  65. package/src/index.ts +5 -0
  66. package/build/legacy/chunk-UZIN7UOS.js.map +0 -1
  67. package/build/legacy/chunk-WKSC2WCV.js.map +0 -1
  68. package/build/modern/chunk-X2GKC3IU.js.map +0 -1
  69. package/build/modern/chunk-YHJTKBVE.js.map +0 -1
@@ -0,0 +1,7 @@
1
+ import {
2
+ ModalHeading
3
+ } from "../chunk-OGSAAB6K.js";
4
+ export {
5
+ ModalHeading
6
+ };
7
+ //# sourceMappingURL=ModalHeading.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -2,14 +2,19 @@
2
2
  import {
3
3
  ConfirmModal,
4
4
  useConfirmModal
5
- } from "../chunk-UZIN7UOS.js";
5
+ } from "../chunk-D3ZXZA3U.js";
6
6
  import "../chunk-4CAT3FHV.js";
7
+ import "../chunk-TPFNVGYA.js";
8
+ import "../chunk-UPODPCRD.js";
9
+ import "../chunk-2F5TB2EV.js";
10
+ import "../chunk-OGSAAB6K.js";
11
+ import "../chunk-G3JEWPLM.js";
7
12
  import "../chunk-2ATICEW3.js";
8
13
  import "../chunk-4O4QFF4S.js";
9
- import "../chunk-G3JEWPLM.js";
10
14
  import "../chunk-KESKDLX6.js";
11
15
  import "../chunk-6TXQZ3PB.js";
12
16
  import "../chunk-C45DY4VE.js";
17
+ import "../chunk-TZNYJ3G7.js";
13
18
  export {
14
19
  ConfirmModal,
15
20
  useConfirmModal
@@ -2,17 +2,22 @@
2
2
  import {
3
3
  PromptModal,
4
4
  usePromptModal
5
- } from "../chunk-WKSC2WCV.js";
5
+ } from "../chunk-DGPLSWFJ.js";
6
6
  import "../chunk-4CAT3FHV.js";
7
+ import "../chunk-TPFNVGYA.js";
8
+ import "../chunk-UPODPCRD.js";
9
+ import "../chunk-2F5TB2EV.js";
10
+ import "../chunk-OGSAAB6K.js";
11
+ import "../chunk-G3JEWPLM.js";
7
12
  import "../chunk-2ATICEW3.js";
8
13
  import "../chunk-5GEC53G7.js";
9
14
  import "../chunk-CU7HXAKM.js";
10
15
  import "../chunk-4O4QFF4S.js";
11
16
  import "../chunk-ZAU4JVLL.js";
12
- import "../chunk-G3JEWPLM.js";
13
17
  import "../chunk-KESKDLX6.js";
14
18
  import "../chunk-6TXQZ3PB.js";
15
19
  import "../chunk-C45DY4VE.js";
20
+ import "../chunk-TZNYJ3G7.js";
16
21
  export {
17
22
  PromptModal,
18
23
  usePromptModal
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import {
3
+ useModal
4
+ } from "../chunk-TZNYJ3G7.js";
5
+ export {
6
+ useModal
7
+ };
8
+ //# sourceMappingURL=useModal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,7 +1,26 @@
1
+ import {
2
+ Toggle
3
+ } from "./chunk-TAZI77TP.js";
4
+ import {
5
+ ConfirmModal,
6
+ useConfirmModal
7
+ } from "./chunk-D3ZXZA3U.js";
1
8
  import {
2
9
  PromptModal,
3
10
  usePromptModal
4
- } from "./chunk-WKSC2WCV.js";
11
+ } from "./chunk-DGPLSWFJ.js";
12
+ import {
13
+ Portal
14
+ } from "./chunk-4CAT3FHV.js";
15
+ import {
16
+ Radio
17
+ } from "./chunk-WE3JNSNO.js";
18
+ import {
19
+ Tab
20
+ } from "./chunk-JI4YTPEJ.js";
21
+ import {
22
+ TabList
23
+ } from "./chunk-X2JMXTBH.js";
5
24
  import {
6
25
  TabPanel
7
26
  } from "./chunk-67S42J4B.js";
@@ -12,12 +31,20 @@ import {
12
31
  Textarea
13
32
  } from "./chunk-TCO46FK7.js";
14
33
  import {
15
- Toggle
16
- } from "./chunk-TAZI77TP.js";
34
+ Modal
35
+ } from "./chunk-TPFNVGYA.js";
17
36
  import {
18
- ConfirmModal,
19
- useConfirmModal
20
- } from "./chunk-UZIN7UOS.js";
37
+ ModalDescription
38
+ } from "./chunk-UPODPCRD.js";
39
+ import {
40
+ ModalHeader
41
+ } from "./chunk-2F5TB2EV.js";
42
+ import {
43
+ ModalHeading
44
+ } from "./chunk-OGSAAB6K.js";
45
+ import {
46
+ ModalIcon
47
+ } from "./chunk-G3JEWPLM.js";
21
48
  import {
22
49
  NavMenuLink
23
50
  } from "./chunk-6DIGPXAD.js";
@@ -33,17 +60,12 @@ import {
33
60
  useNavMenuContext
34
61
  } from "./chunk-KJUCHZHV.js";
35
62
  import {
36
- Portal
37
- } from "./chunk-4CAT3FHV.js";
38
- import {
39
- Radio
40
- } from "./chunk-WE3JNSNO.js";
41
- import {
42
- Tab
43
- } from "./chunk-JI4YTPEJ.js";
44
- import {
45
- TabList
46
- } from "./chunk-X2JMXTBH.js";
63
+ MODE_KEY,
64
+ THEME_KEY,
65
+ ThemeProvider,
66
+ useTheme,
67
+ useThemeContext
68
+ } from "./chunk-SXXWC6UD.js";
47
69
  import {
48
70
  useToggle
49
71
  } from "./chunk-SCQVXJBT.js";
@@ -76,9 +98,6 @@ import {
76
98
  Field,
77
99
  useFieldContext
78
100
  } from "./chunk-ZAU4JVLL.js";
79
- import {
80
- ModalIcon
81
- } from "./chunk-G3JEWPLM.js";
82
101
  import "./chunk-55J6XMHW.js";
83
102
  import {
84
103
  createNavTriggerProps
@@ -100,12 +119,8 @@ import {
100
119
  } from "./chunk-6TXQZ3PB.js";
101
120
  import "./chunk-C45DY4VE.js";
102
121
  import {
103
- MODE_KEY,
104
- THEME_KEY,
105
- ThemeProvider,
106
- useTheme,
107
- useThemeContext
108
- } from "./chunk-SXXWC6UD.js";
122
+ useModal
123
+ } from "./chunk-TZNYJ3G7.js";
109
124
  export {
110
125
  $cerberusIcons,
111
126
  Button,
@@ -118,6 +133,10 @@ export {
118
133
  Input,
119
134
  Label,
120
135
  MODE_KEY,
136
+ Modal,
137
+ ModalDescription,
138
+ ModalHeader,
139
+ ModalHeading,
121
140
  ModalIcon,
122
141
  NavMenu,
123
142
  NavMenuLink,
@@ -144,6 +163,7 @@ export {
144
163
  useConfirmModal,
145
164
  useFeatureFlags,
146
165
  useFieldContext,
166
+ useModal,
147
167
  useNavMenuContext,
148
168
  usePromptModal,
149
169
  useTabsContext,
@@ -6,6 +6,7 @@ import { ChangeEvent } from 'react';
6
6
  import { Context } from 'react';
7
7
  import { ElementType } from 'react';
8
8
  import { fieldMessage } from '@cerberus/styled-system/recipes';
9
+ import { ForwardRefExoticComponent } from 'react';
9
10
  import { HTMLAttributes } from 'react';
10
11
  import { iconButton } from '@cerberus/styled-system/recipes';
11
12
  import { input } from '@cerberus/styled-system/recipes';
@@ -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';
@@ -321,6 +323,88 @@ declare type LabelRecipeProps = RecipeVariantProps<typeof label>;
321
323
  export { LabelRecipeProps }
322
324
  export { LabelRecipeProps as LabelRecipeProps_alias_1 }
323
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
+
324
408
  declare function ModalIcon(props: PropsWithChildren<ModalIconProps>): JSX_2.Element;
325
409
  export { ModalIcon }
326
410
  export { ModalIcon as ModalIcon_alias_1 }
@@ -333,6 +417,14 @@ declare type ModalIconProps = ModalIconBaseProps & ModalIconVariantProps;
333
417
  export { ModalIconProps }
334
418
  export { ModalIconProps as ModalIconProps_alias_1 }
335
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
+
336
428
  declare const MODE_KEY = "cerberus-mode";
337
429
  export { MODE_KEY }
338
430
  export { MODE_KEY as MODE_KEY_alias_1 }
@@ -809,6 +901,20 @@ declare function useFieldContext(): FieldContextValue;
809
901
  export { useFieldContext }
810
902
  export { useFieldContext as useFieldContext_alias_1 }
811
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
+
812
918
  declare function useNavMenuContext(): NavMenuContextValue;
813
919
  export { useNavMenuContext }
814
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":[]}
@@ -0,0 +1,23 @@
1
+ // src/hooks/useModal.ts
2
+ import { useCallback, useMemo, useRef } from "react";
3
+ function useModal() {
4
+ const modalRef = useRef(null);
5
+ const show = useCallback(() => {
6
+ modalRef.current?.showModal();
7
+ }, []);
8
+ const close = useCallback(() => {
9
+ modalRef.current?.close();
10
+ }, []);
11
+ return useMemo(() => {
12
+ return {
13
+ modalRef,
14
+ show,
15
+ close
16
+ };
17
+ }, [modalRef, show, close]);
18
+ }
19
+
20
+ export {
21
+ useModal
22
+ };
23
+ //# sourceMappingURL=chunk-C5HLLGME.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useModal.ts"],"sourcesContent":["'use client'\n\nimport { useCallback, useMemo, useRef, type RefObject } from 'react'\n\n/**\n * This module provides a hook for using a custom modal.\n * @module\n */\n\ninterface UseModalReturnValue {\n modalRef: RefObject<HTMLDialogElement>\n show: () => void\n close: () => void\n}\n\nexport function useModal(): UseModalReturnValue {\n const modalRef = useRef<HTMLDialogElement | null>(null)\n\n const show = useCallback(() => {\n modalRef.current?.showModal()\n }, [])\n\n const close = useCallback(() => {\n modalRef.current?.close()\n }, [])\n\n return useMemo(() => {\n return {\n modalRef,\n show,\n close,\n }\n }, [modalRef, show, close])\n}\n"],"mappings":";AAEA,SAAS,aAAa,SAAS,cAA8B;AAatD,SAAS,WAAgC;AAC9C,QAAM,WAAW,OAAiC,IAAI;AAEtD,QAAM,OAAO,YAAY,MAAM;AAC7B,aAAS,SAAS,UAAU;AAAA,EAC9B,GAAG,CAAC,CAAC;AAEL,QAAM,QAAQ,YAAY,MAAM;AAC9B,aAAS,SAAS,MAAM;AAAA,EAC1B,GAAG,CAAC,CAAC;AAEL,SAAO,QAAQ,MAAM;AACnB,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,UAAU,MAAM,KAAK,CAAC;AAC5B;","names":[]}
@@ -0,0 +1,12 @@
1
+ // src/components/ModalHeading.tsx
2
+ import { cx } from "@cerberus-design/styled-system/css";
3
+ import { modal } from "@cerberus-design/styled-system/recipes";
4
+ import { jsx } from "react/jsx-runtime";
5
+ function ModalHeading(props) {
6
+ return /* @__PURE__ */ jsx("p", { ...props, className: cx(props.className, modal().heading) });
7
+ }
8
+
9
+ export {
10
+ ModalHeading
11
+ };
12
+ //# sourceMappingURL=chunk-OGSAAB6K.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/ModalHeading.tsx"],"sourcesContent":["import { cx } from '@cerberus-design/styled-system/css'\nimport { modal } from '@cerberus-design/styled-system/recipes'\nimport type { HTMLAttributes } from 'react'\n\n/**\n * This module contains the ModalHeading component for a customizable modal.\n * @module\n */\n\nexport type ModalHeadingProps = HTMLAttributes<HTMLParagraphElement>\n\n/**\n * The ModalHeading component is a heading element for a customizable modal.\n * @example\n * ```tsx\n * <Modal>\n * <ModalHeading>Modal Heading</ModalHeading>\n * </Modal>\n * ```\n */\nexport function ModalHeading(props: ModalHeadingProps) {\n return <p {...props} className={cx(props.className, modal().heading)} />\n}\n"],"mappings":";AAAA,SAAS,UAAU;AACnB,SAAS,aAAa;AAoBb;AADF,SAAS,aAAa,OAA0B;AACrD,SAAO,oBAAC,OAAG,GAAG,OAAO,WAAW,GAAG,MAAM,WAAW,MAAM,EAAE,OAAO,GAAG;AACxE;","names":[]}
@@ -1,21 +1,36 @@
1
1
  import {
2
2
  Portal
3
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";
4
19
  import {
5
20
  Button
6
21
  } from "./chunk-2ATICEW3.js";
7
22
  import {
8
23
  Show
9
24
  } from "./chunk-4O4QFF4S.js";
10
- import {
11
- ModalIcon
12
- } from "./chunk-G3JEWPLM.js";
13
25
  import {
14
26
  trapFocus
15
27
  } from "./chunk-JIZQFTW6.js";
16
28
  import {
17
29
  $cerberusIcons
18
30
  } from "./chunk-6TXQZ3PB.js";
31
+ import {
32
+ useModal
33
+ } from "./chunk-C5HLLGME.js";
19
34
 
20
35
  // src/context/confirm-modal.tsx
21
36
  import {
@@ -27,36 +42,40 @@ import {
27
42
  useState
28
43
  } from "react";
29
44
  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";
45
+ import { hstack } from "@cerberus-design/styled-system/patterns";
32
46
  import { jsx, jsxs } from "react/jsx-runtime";
33
47
  var ConfirmModalContext = createContext(null);
34
48
  function ConfirmModal(props) {
35
- const dialogRef = useRef(null);
49
+ const { modalRef, show, close } = useModal();
36
50
  const resolveRef = useRef(null);
37
51
  const [content, setContent] = useState(null);
38
- const focusTrap = trapFocus(dialogRef);
52
+ const focusTrap = trapFocus(modalRef);
39
53
  const ConfirmIcon = $cerberusIcons.confirmModal;
40
54
  const palette = useMemo(
41
55
  () => content?.kind === "destructive" ? "danger" : "action",
42
56
  [content]
43
57
  );
44
- const styles = modal();
45
- const handleChoice = useCallback((e) => {
46
- const target = e.currentTarget;
47
- if (target.value === "true") {
48
- resolveRef.current?.(true);
49
- }
50
- resolveRef.current?.(false);
51
- dialogRef?.current?.close();
52
- }, []);
53
- const handleShow = useCallback((options) => {
54
- return new Promise((resolve) => {
55
- setContent({ ...options, kind: options.kind || "non-destructive" });
56
- dialogRef?.current?.showModal();
57
- resolveRef.current = resolve;
58
- });
59
- }, []);
58
+ const handleChoice = useCallback(
59
+ (e) => {
60
+ const target = e.currentTarget;
61
+ if (target.value === "true") {
62
+ resolveRef.current?.(true);
63
+ }
64
+ resolveRef.current?.(false);
65
+ close();
66
+ },
67
+ [close]
68
+ );
69
+ const handleShow = useCallback(
70
+ (options) => {
71
+ return new Promise((resolve) => {
72
+ setContent({ ...options, kind: options.kind || "non-destructive" });
73
+ show();
74
+ resolveRef.current = resolve;
75
+ });
76
+ },
77
+ [show]
78
+ );
60
79
  const value = useMemo(
61
80
  () => ({
62
81
  show: handleShow
@@ -65,29 +84,19 @@ function ConfirmModal(props) {
65
84
  );
66
85
  return /* @__PURE__ */ jsxs(ConfirmModalContext.Provider, { value, children: [
67
86
  props.children,
68
- /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs("dialog", { className: styles.dialog, onKeyDown: focusTrap, ref: dialogRef, children: [
69
- /* @__PURE__ */ jsxs(
70
- "section",
71
- {
72
- className: vstack({
73
- alignItems: "flex-start",
74
- gap: "4",
75
- mb: "8"
76
- }),
77
- children: [
78
- /* @__PURE__ */ jsx(
79
- Show,
80
- {
81
- when: palette === "danger",
82
- fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) }),
83
- children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) })
84
- }
85
- ),
86
- /* @__PURE__ */ jsx("h2", { className: styles.heading, children: content?.heading }),
87
- /* @__PURE__ */ jsx("p", { className: styles.description, children: content?.description })
88
- ]
89
- }
90
- ),
87
+ /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs(Modal, { onKeyDown: focusTrap, ref: modalRef, children: [
88
+ /* @__PURE__ */ jsxs(ModalHeader, { children: [
89
+ /* @__PURE__ */ jsx(
90
+ Show,
91
+ {
92
+ when: palette === "danger",
93
+ fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) }),
94
+ children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) })
95
+ }
96
+ ),
97
+ /* @__PURE__ */ jsx(ModalHeading, { children: content?.heading }),
98
+ /* @__PURE__ */ jsx(ModalDescription, { children: content?.description })
99
+ ] }),
91
100
  /* @__PURE__ */ jsxs(
92
101
  "div",
93
102
  {
@@ -142,4 +151,4 @@ export {
142
151
  ConfirmModal,
143
152
  useConfirmModal
144
153
  };
145
- //# sourceMappingURL=chunk-X2GKC3IU.js.map
154
+ //# sourceMappingURL=chunk-TAVCJ54A.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,MAAO,SAAS,SAAS,gBAAgB,WAAW;AAAA,IACpD,CAAC,OAAO;AAAA,EACV;AAEA,QAAM,eAAe;AAAA,IACnB,CAAC,MAAqC;AACpC,YAAM,SAAS,EAAE;AACjB,UAAI,OAAO,UAAU,QAAQ;AAC3B,mBAAW,UAAU,IAAI;AAAA,MAC3B;AACA,iBAAW,UAAU,KAAK;AAC1B,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;AAAA,IACZ,OAAO;AAAA,MACL,MAAM;AAAA,IACR;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AAEA,SACE,qBAAC,oBAAoB,UAApB,EAA6B,OAC3B;AAAA,UAAM;AAAA,IAEP,oBAAC,UACC,+BAAC,SAAM,WAAW,WAAW,KAAK,UAChC;AAAA,2BAAC,eACC;AAAA;AAAA,UAAC;AAAA;AAAA,YACC,MAAM,YAAY;AAAA,YAClB,UACE,oBAAC,aAAU,SAAQ,UACjB,8BAAC,eAAY,MAAM,IAAI,GACzB;AAAA,YAGF,8BAAC,aAAU,SAAQ,UACjB,8BAAC,eAAY,MAAM,IAAI,GACzB;AAAA;AAAA,QACF;AAAA,QACA,oBAAC,gBAAc,mBAAS,SAAQ;AAAA,QAChC,oBAAC,oBAAkB,mBAAS,aAAY;AAAA,SAC1C;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC,WAAW,OAAO;AAAA,YAChB,KAAK;AAAA,UACP,CAAC;AAAA,UAED;AAAA;AAAA,cAAC;AAAA;AAAA,gBACC,WAAS;AAAA,gBACT,WAAW,IAAI;AAAA,kBACb,GAAG;AAAA,gBACL,CAAC;AAAA,gBACD,MAAK;AAAA,gBACL,SAAS;AAAA,gBACT;AAAA,gBACA,OAAM;AAAA,gBAEL,mBAAS;AAAA;AAAA,YACZ;AAAA,YACA;AAAA,cAAC;AAAA;AAAA,gBACC,WAAW,IAAI;AAAA,kBACb,GAAG;AAAA,gBACL,CAAC;AAAA,gBACD,MAAK;AAAA,gBACL,SAAS;AAAA,gBACT,OAAM;AAAA,gBACN,OAAM;AAAA,gBAEL,mBAAS;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,21 @@
1
+ // src/components/Modal.tsx
2
+ import { cx } from "@cerberus-design/styled-system/css";
3
+ import { modal } from "@cerberus-design/styled-system/recipes";
4
+ import { forwardRef } from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+ function ModalEl(props, ref) {
7
+ return /* @__PURE__ */ jsx(
8
+ "dialog",
9
+ {
10
+ ...props,
11
+ className: cx(props.className, modal().dialog),
12
+ ref
13
+ }
14
+ );
15
+ }
16
+ var Modal = forwardRef(ModalEl);
17
+
18
+ export {
19
+ Modal
20
+ };
21
+ //# sourceMappingURL=chunk-TPFNVGYA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/Modal.tsx"],"sourcesContent":["import { cx } from '@cerberus-design/styled-system/css'\nimport { modal } from '@cerberus-design/styled-system/recipes'\nimport { forwardRef, type ForwardedRef, type HTMLAttributes } from 'react'\n\n/**\n * This module contains the Modal root component for a customizable modal.\n * @module\n */\n\n// Modal\n\nexport type ModalProps = HTMLAttributes<HTMLDialogElement>\n\nfunction ModalEl(props: ModalProps, ref: ForwardedRef<HTMLDialogElement>) {\n return (\n <dialog\n {...props}\n className={cx(props.className, modal().dialog)}\n ref={ref}\n />\n )\n}\n\n/**\n * The Modal component is the root element for a customizable modal.\n * @example\n * ```tsx\n * const { modalRef } = useModal()\n *\n * <Modal ref={modalRef}>\n * <ModalIcon icon={$cerberusIcons.alert} />\n * <h2>Modal Heading</h2>\n * <p>Modal description</p>\n * </Modal>\n * ```\n */\nexport const Modal = forwardRef(ModalEl)\n"],"mappings":";AAAA,SAAS,UAAU;AACnB,SAAS,aAAa;AACtB,SAAS,kBAA0D;AAa/D;AAFJ,SAAS,QAAQ,OAAmB,KAAsC;AACxE,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,WAAW,GAAG,MAAM,WAAW,MAAM,EAAE,MAAM;AAAA,MAC7C;AAAA;AAAA,EACF;AAEJ;AAeO,IAAM,QAAQ,WAAW,OAAO;","names":[]}
@@ -0,0 +1,12 @@
1
+ // src/components/ModalDescription.tsx
2
+ import { cx } from "@cerberus-design/styled-system/css";
3
+ import { modal } from "@cerberus-design/styled-system/recipes";
4
+ import { jsx } from "react/jsx-runtime";
5
+ function ModalDescription(props) {
6
+ return /* @__PURE__ */ jsx("p", { ...props, className: cx(props.className, modal().description) });
7
+ }
8
+
9
+ export {
10
+ ModalDescription
11
+ };
12
+ //# sourceMappingURL=chunk-UPODPCRD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/ModalDescription.tsx"],"sourcesContent":["import { cx } from '@cerberus-design/styled-system/css'\nimport { modal } from '@cerberus-design/styled-system/recipes'\nimport type { HTMLAttributes } from 'react'\n\n/**\n * This module contains the ModalDescription component for a customizable modal.\n * @module\n */\n\nexport type ModalDescriptionProps = HTMLAttributes<HTMLParagraphElement>\n\n/**\n * The ModalDescription component is a heading element for a customizable modal.\n * @example\n * ```tsx\n * <Modal>\n * <ModalDescription>Modal Heading</ModalDescription>\n * </Modal>\n * ```\n */\nexport function ModalDescription(props: ModalDescriptionProps) {\n return <p {...props} className={cx(props.className, modal().description)} />\n}\n"],"mappings":";AAAA,SAAS,UAAU;AACnB,SAAS,aAAa;AAoBb;AADF,SAAS,iBAAiB,OAA8B;AAC7D,SAAO,oBAAC,OAAG,GAAG,OAAO,WAAW,GAAG,MAAM,WAAW,MAAM,EAAE,WAAW,GAAG;AAC5E;","names":[]}