@cerberus-design/react 0.6.1-next-f9a7124 → 0.6.1-next-2d28489

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 (80) hide show
  1. package/build/legacy/_tsup-dts-rollup.d.ts +146 -5
  2. package/build/legacy/aria-helpers/trap-focus.aria.js +7 -0
  3. package/build/legacy/aria-helpers/trap-focus.aria.js.map +1 -0
  4. package/build/{modern/chunk-JDRWQFCE.js → legacy/chunk-4M3EUP57.js} +1 -1
  5. package/build/legacy/chunk-4M3EUP57.js.map +1 -0
  6. package/build/legacy/{chunk-3CBN7U25.js → chunk-6TXQZ3PB.js} +6 -3
  7. package/build/legacy/chunk-6TXQZ3PB.js.map +1 -0
  8. package/build/legacy/{chunk-X4YQ27D5.js → chunk-7ISHDUYN.js} +2 -2
  9. package/build/legacy/chunk-BLJ4SRAF.js +167 -0
  10. package/build/legacy/chunk-BLJ4SRAF.js.map +1 -0
  11. package/build/legacy/chunk-C45DY4VE.js +17 -0
  12. package/build/legacy/chunk-C45DY4VE.js.map +1 -0
  13. package/build/legacy/chunk-KESKDLX6.js +30 -0
  14. package/build/legacy/chunk-KESKDLX6.js.map +1 -0
  15. package/build/legacy/chunk-SNSBODYR.js +224 -0
  16. package/build/legacy/chunk-SNSBODYR.js.map +1 -0
  17. package/build/legacy/{chunk-734PGVLT.js → chunk-TAZI77TP.js} +2 -2
  18. package/build/{modern/chunk-ZVNBWU4J.js → legacy/chunk-VULPMZUW.js} +2 -2
  19. package/build/legacy/components/FeatureFlag.js +2 -2
  20. package/build/legacy/components/Input.js +3 -3
  21. package/build/legacy/components/Toggle.js +3 -3
  22. package/build/legacy/config/cerbIcons.js +1 -1
  23. package/build/legacy/config/defineIcons.js +2 -2
  24. package/build/legacy/context/confirm-modal.js +18 -0
  25. package/build/legacy/context/confirm-modal.js.map +1 -0
  26. package/build/legacy/context/feature-flags.js +1 -1
  27. package/build/legacy/context/prompt-modal.js +22 -0
  28. package/build/legacy/context/prompt-modal.js.map +1 -0
  29. package/build/legacy/index.js +39 -19
  30. package/build/modern/_tsup-dts-rollup.d.ts +146 -5
  31. package/build/modern/aria-helpers/trap-focus.aria.js +7 -0
  32. package/build/modern/aria-helpers/trap-focus.aria.js.map +1 -0
  33. package/build/modern/chunk-4GURONLE.js +165 -0
  34. package/build/modern/chunk-4GURONLE.js.map +1 -0
  35. package/build/{legacy/chunk-JDRWQFCE.js → modern/chunk-4M3EUP57.js} +1 -1
  36. package/build/modern/chunk-4M3EUP57.js.map +1 -0
  37. package/build/modern/{chunk-3CBN7U25.js → chunk-6TXQZ3PB.js} +6 -3
  38. package/build/modern/chunk-6TXQZ3PB.js.map +1 -0
  39. package/build/modern/{chunk-X4YQ27D5.js → chunk-7ISHDUYN.js} +2 -2
  40. package/build/modern/chunk-C45DY4VE.js +17 -0
  41. package/build/modern/chunk-C45DY4VE.js.map +1 -0
  42. package/build/modern/chunk-FZ75OJLJ.js +222 -0
  43. package/build/modern/chunk-FZ75OJLJ.js.map +1 -0
  44. package/build/modern/chunk-JIZQFTW6.js +29 -0
  45. package/build/modern/chunk-JIZQFTW6.js.map +1 -0
  46. package/build/modern/{chunk-734PGVLT.js → chunk-TAZI77TP.js} +2 -2
  47. package/build/{legacy/chunk-ZVNBWU4J.js → modern/chunk-VULPMZUW.js} +2 -2
  48. package/build/modern/components/FeatureFlag.js +2 -2
  49. package/build/modern/components/Input.js +3 -3
  50. package/build/modern/components/Toggle.js +3 -3
  51. package/build/modern/config/cerbIcons.js +1 -1
  52. package/build/modern/config/defineIcons.js +2 -2
  53. package/build/modern/context/confirm-modal.js +18 -0
  54. package/build/modern/context/confirm-modal.js.map +1 -0
  55. package/build/modern/context/feature-flags.js +1 -1
  56. package/build/modern/context/prompt-modal.js +22 -0
  57. package/build/modern/context/prompt-modal.js.map +1 -0
  58. package/build/modern/index.js +39 -19
  59. package/package.json +2 -2
  60. package/src/aria-helpers/trap-focus.aria.ts +29 -0
  61. package/src/config/cerbIcons.ts +11 -2
  62. package/src/config/defineIcons.ts +6 -3
  63. package/src/context/confirm-modal.tsx +205 -0
  64. package/src/context/feature-flags.tsx +2 -2
  65. package/src/context/prompt-modal.tsx +254 -0
  66. package/src/index.ts +3 -0
  67. package/build/legacy/chunk-3CBN7U25.js.map +0 -1
  68. package/build/legacy/chunk-5MNCW677.js +0 -11
  69. package/build/legacy/chunk-5MNCW677.js.map +0 -1
  70. package/build/legacy/chunk-JDRWQFCE.js.map +0 -1
  71. package/build/modern/chunk-3CBN7U25.js.map +0 -1
  72. package/build/modern/chunk-5MNCW677.js +0 -11
  73. package/build/modern/chunk-5MNCW677.js.map +0 -1
  74. package/build/modern/chunk-JDRWQFCE.js.map +0 -1
  75. /package/build/legacy/{chunk-X4YQ27D5.js.map → chunk-7ISHDUYN.js.map} +0 -0
  76. /package/build/legacy/{chunk-734PGVLT.js.map → chunk-TAZI77TP.js.map} +0 -0
  77. /package/build/legacy/{chunk-ZVNBWU4J.js.map → chunk-VULPMZUW.js.map} +0 -0
  78. /package/build/modern/{chunk-X4YQ27D5.js.map → chunk-7ISHDUYN.js.map} +0 -0
  79. /package/build/modern/{chunk-734PGVLT.js.map → chunk-TAZI77TP.js.map} +0 -0
  80. /package/build/modern/{chunk-ZVNBWU4J.js.map → chunk-VULPMZUW.js.map} +0 -0
@@ -3,6 +3,7 @@ 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';
6
7
  import { Context } from 'react';
7
8
  import { ElementType } from 'react';
8
9
  import { fieldMessage } from '@cerberus/styled-system/recipes';
@@ -11,6 +12,7 @@ import { iconButton } from '@cerberus/styled-system/recipes';
11
12
  import { input } from '@cerberus/styled-system/recipes';
12
13
  import type { InputHTMLAttributes } from 'react';
13
14
  import { JSX as JSX_2 } from 'react/jsx-runtime';
15
+ import type { KeyboardEventHandler } from 'react';
14
16
  import { label } from '@cerberus/styled-system/recipes';
15
17
  import { MutableRefObject } from 'react';
16
18
  import type { Pretty } from '@cerberus-design/styled-system/types';
@@ -27,7 +29,7 @@ import { tag } from '@cerberus/styled-system/recipes';
27
29
  import type { TextareaHTMLAttributes } from 'react';
28
30
  import { ToggleVariantProps } from '@cerberus-design/styled-system/recipes';
29
31
 
30
- declare let $cerberusIcons: DefinedIcons;
32
+ declare let $cerberusIcons: Required<DefinedIcons>;
31
33
  export { $cerberusIcons }
32
34
  export { $cerberusIcons as $cerberusIcons_alias_1 }
33
35
 
@@ -61,6 +63,49 @@ declare type ColorModes = 'light' | 'dark';
61
63
  export { ColorModes }
62
64
  export { ColorModes as ColorModes_alias_1 }
63
65
 
66
+ /**
67
+ * Provides a confirm modal to the app.
68
+ * @example
69
+ * ```tsx
70
+ * // Wrap the Provider around the root of the feature.
71
+ * <ConfirmModal>
72
+ * <SomeFeatureSection />
73
+ * </ConfirmModal>
74
+ *
75
+ * // Use the hook to show the confirm modal.
76
+ * const confirm = useConfirmModal()
77
+ *
78
+ * const handleClick = useCallback(async () => {
79
+ * const userConsent = await confirm.show({
80
+ * heading: 'Add new payment method?',
81
+ * description:
82
+ * 'This will add a new payment method to your account to be billed for future purchases.',
83
+ * actionText: 'Yes, add payment method',
84
+ * cancelText: 'No, cancel',
85
+ * })
86
+ * setConsent(userConsent)
87
+ * }, [confirm])
88
+ * ```
89
+ */
90
+ declare function ConfirmModal(props: PropsWithChildren<ConfirmModalProviderProps>): JSX_2.Element;
91
+ export { ConfirmModal }
92
+ export { ConfirmModal as ConfirmModal_alias_1 }
93
+
94
+ declare function ConfirmModalIcon(props: ConfirmModalVariantProps): JSX_2.Element;
95
+ export { ConfirmModalIcon }
96
+ export { ConfirmModalIcon as ConfirmModalIcon_alias_1 }
97
+
98
+ declare interface ConfirmModalProviderProps {
99
+ }
100
+ export { ConfirmModalProviderProps }
101
+ export { ConfirmModalProviderProps as ConfirmModalProviderProps_alias_1 }
102
+
103
+ declare interface ConfirmModalValue {
104
+ show: (options: ShowConfirmModalOptions) => Promise<boolean>;
105
+ }
106
+ export { ConfirmModalValue }
107
+ export { ConfirmModalValue as ConfirmModalValue_alias_1 }
108
+
64
109
  declare function createNavTriggerProps(values: NavTriggerAriaValues): NavTriggerAriaReturn;
65
110
  export { createNavTriggerProps }
66
111
  export { createNavTriggerProps as createNavTriggerProps_alias_1 }
@@ -76,11 +121,13 @@ export { DefaultThemes }
76
121
  export { DefaultThemes as DefaultThemes_alias_1 }
77
122
 
78
123
  export declare interface DefinedIcons {
124
+ confirmModal?: CarbonIconType | ElementType;
125
+ promptModal?: CarbonIconType | ElementType;
79
126
  invalid: CarbonIconType | ElementType;
80
- toggleChecked: CarbonIconType | ElementType;
127
+ toggleChecked?: CarbonIconType | ElementType;
81
128
  }
82
129
 
83
- declare function defineIcons(icons: DefinedIcons): DefinedIcons;
130
+ declare function defineIcons(icons: DefinedIcons): Required<DefinedIcons>;
84
131
  export { defineIcons }
85
132
  export { defineIcons as defineIcons_alias_1 }
86
133
 
@@ -112,14 +159,14 @@ export { FeatureFlagProviderProps as FeatureFlagProviderProps_alias_1 }
112
159
  * }
113
160
  *
114
161
  * // Wrap the Provider around the root of your application.
115
- * <FeatureFlagProvider flags={flags}>
162
+ * <FeatureFlags flags={flags}>
116
163
  * <FeatureFlag flag="featureOne">
117
164
  * This is visible.
118
165
  * </FeatureFlag>
119
166
  * <FeatureFlag flag="featureTwo">
120
167
  * This is hidden.
121
168
  * </FeatureFlag>
122
- * </FeatureFlagProvider>
169
+ * </FeatureFlags>
123
170
  * ```
124
171
  */
125
172
  declare function FeatureFlags(props: PropsWithChildren<FeatureFlagProviderProps>): JSX_2.Element;
@@ -395,6 +442,55 @@ declare type Positions = 'top' | 'right' | 'bottom' | 'left';
395
442
  export { Positions }
396
443
  export { Positions as Positions_alias_1 }
397
444
 
445
+ /**
446
+ * Provides a prompt modal to the app.
447
+ * @example
448
+ * ```tsx
449
+ * // Wrap the Provider around the root of the feature.
450
+ * <PromptModal>
451
+ * <SomeFeatureSection />
452
+ * </PromptModal>
453
+ *
454
+ * // Use the hook to show the prompt modal.
455
+ * const prompt = usePromptModal()
456
+ *
457
+ * const handleClick = useCallback(async () => {
458
+ * const accepted = await prompt.show({
459
+ * kind: 'destructive',
460
+ * heading: 'Delete channel?',
461
+ * description:
462
+ * 'This will permanently delete a channel on your account. There is no going back.',
463
+ * key: CHANNEL_NAME,
464
+ * actionText: 'Yes, delete channel',
465
+ * cancelText: 'No, cancel',
466
+ * })
467
+ * // do something with accepted
468
+ * }, [prompt])
469
+ * ```
470
+ */
471
+ declare function PromptModal(props: PropsWithChildren<PromptModalProviderProps>): JSX_2.Element;
472
+ export { PromptModal }
473
+ export { PromptModal as PromptModal_alias_1 }
474
+
475
+ declare function PromptModalIcon(props: ConfirmModalVariantProps): JSX_2.Element;
476
+ export { PromptModalIcon }
477
+ export { PromptModalIcon as PromptModalIcon_alias_1 }
478
+
479
+ declare interface PromptModalProviderProps {
480
+ }
481
+ export { PromptModalProviderProps }
482
+ export { PromptModalProviderProps as PromptModalProviderProps_alias_1 }
483
+
484
+ declare interface PromptModalValue {
485
+ show: (options: ShowPromptModalOptions) => Promise<string>;
486
+ }
487
+ export { PromptModalValue }
488
+ export { PromptModalValue as PromptModalValue_alias_1 }
489
+
490
+ declare type PromptShowResult = ((value: string | PromiseLike<string>) => void) | null;
491
+ export { PromptShowResult }
492
+ export { PromptShowResult as PromptShowResult_alias_1 }
493
+
398
494
  declare function Radio(props: PropsWithChildren<RadioProps>): JSX_2.Element;
399
495
  export { Radio }
400
496
  export { Radio as Radio_alias_1 }
@@ -427,6 +523,35 @@ declare function Show(props: PropsWithChildren<ShowProps>): ReactNode;
427
523
  export { Show }
428
524
  export { Show as Show_alias_1 }
429
525
 
526
+ /**
527
+ * This module provides a context and hook for the confirm modal.
528
+ * @module
529
+ */
530
+ declare interface ShowConfirmModalOptions {
531
+ kind?: 'destructive' | 'non-destructive';
532
+ heading: string;
533
+ description?: string;
534
+ actionText: string;
535
+ cancelText: string;
536
+ }
537
+ export { ShowConfirmModalOptions }
538
+ export { ShowConfirmModalOptions as ShowConfirmModalOptions_alias_1 }
539
+
540
+ /**
541
+ * This module provides a context and hook for the prompt modal.
542
+ * @module
543
+ */
544
+ declare interface ShowPromptModalOptions {
545
+ kind?: 'destructive' | 'non-destructive';
546
+ heading: string;
547
+ description?: string;
548
+ key: string;
549
+ actionText: string;
550
+ cancelText: string;
551
+ }
552
+ export { ShowPromptModalOptions }
553
+ export { ShowPromptModalOptions as ShowPromptModalOptions_alias_1 }
554
+
430
555
  declare interface ShowProps {
431
556
  when: boolean | null | undefined;
432
557
  fallback?: ReactNode;
@@ -434,6 +559,10 @@ declare interface ShowProps {
434
559
  export { ShowProps }
435
560
  export { ShowProps as ShowProps_alias_1 }
436
561
 
562
+ declare type ShowResult = ((value: boolean | PromiseLike<boolean>) => void) | null;
563
+ export { ShowResult }
564
+ export { ShowResult as ShowResult_alias_1 }
565
+
437
566
  declare type StaticTagProps = HTMLAttributes<HTMLSpanElement> & TagRecipeProps & {
438
567
  onClick?: never;
439
568
  };
@@ -660,6 +789,14 @@ declare type ToggleProps = ToggleBase & ToggleVariantProps;
660
789
  export { ToggleProps }
661
790
  export { ToggleProps as ToggleProps_alias_1 }
662
791
 
792
+ declare function trapFocus(modalRef: RefObject<HTMLDialogElement>): KeyboardEventHandler<HTMLDialogElement>;
793
+ export { trapFocus }
794
+ export { trapFocus as trapFocus_alias_1 }
795
+
796
+ declare function useConfirmModal(): ConfirmModalValue;
797
+ export { useConfirmModal }
798
+ export { useConfirmModal as useConfirmModal_alias_1 }
799
+
663
800
  declare function useFeatureFlags(key: string): boolean;
664
801
  export { useFeatureFlags }
665
802
  export { useFeatureFlags as useFeatureFlags_alias_1 }
@@ -672,6 +809,10 @@ declare function useNavMenuContext(): NavMenuContextValue;
672
809
  export { useNavMenuContext }
673
810
  export { useNavMenuContext as useNavMenuContext_alias_1 }
674
811
 
812
+ declare function usePromptModal(): PromptModalValue;
813
+ export { usePromptModal }
814
+ export { usePromptModal as usePromptModal_alias_1 }
815
+
675
816
  declare function useTabsContext(): TabsContextValue;
676
817
  export { useTabsContext }
677
818
  export { useTabsContext as useTabsContext_alias_1 }
@@ -0,0 +1,7 @@
1
+ import {
2
+ trapFocus
3
+ } from "../chunk-KESKDLX6.js";
4
+ export {
5
+ trapFocus
6
+ };
7
+ //# sourceMappingURL=trap-focus.aria.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -19,4 +19,4 @@ export {
19
19
  FeatureFlags,
20
20
  useFeatureFlags
21
21
  };
22
- //# sourceMappingURL=chunk-JDRWQFCE.js.map
22
+ //# sourceMappingURL=chunk-4M3EUP57.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/feature-flags.tsx"],"sourcesContent":["'use client'\n\nimport { createContext, useContext, type PropsWithChildren } from 'react'\n\n/**\n * This module provides a context and hook for feature flags.\n * @module\n */\n\nexport interface FeatureFlagValue {\n [key: string]: boolean\n}\n\nconst FeatureFlagContext = createContext<FeatureFlagValue | null>(null)\n\nexport interface FeatureFlagProviderProps {\n flags: FeatureFlagValue\n}\n\n/**\n * Provides feature flags to the application.\n * @param flags - The flags data for the provider.\n * @example\n * ```tsx\n * // This should be a JSON file or a server response.\n * const flags = {\n * featureOne: true,\n * featureTwo: false\n * }\n *\n * // Wrap the Provider around the root of your application.\n * <FeatureFlags flags={flags}>\n * <FeatureFlag flag=\"featureOne\">\n * This is visible.\n * </FeatureFlag>\n * <FeatureFlag flag=\"featureTwo\">\n * This is hidden.\n * </FeatureFlag>\n * </FeatureFlags>\n * ```\n */\nexport function FeatureFlags(\n props: PropsWithChildren<FeatureFlagProviderProps>,\n) {\n return (\n <FeatureFlagContext.Provider value={props.flags}>\n {props.children}\n </FeatureFlagContext.Provider>\n )\n}\n\nexport function useFeatureFlags(key: string): boolean {\n const context = useContext(FeatureFlagContext)\n if (context === null) {\n throw new Error(\n 'useFeatureFlag must be used within a FeatureFlags Provider',\n )\n }\n return context[key] ?? false\n}\n"],"mappings":";AAEA,SAAS,eAAe,kBAA0C;AA2C9D;AAhCJ,IAAM,qBAAqB,cAAuC,IAAI;AA4B/D,SAAS,aACd,OACA;AACA,SACE,oBAAC,mBAAmB,UAAnB,EAA4B,OAAO,MAAM,OACvC,gBAAM,UACT;AAEJ;AAEO,SAAS,gBAAgB,KAAsB;AACpD,QAAM,UAAU,WAAW,kBAAkB;AAC7C,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,QAAQ,GAAG,KAAK;AACzB;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultIcons
3
- } from "./chunk-5MNCW677.js";
3
+ } from "./chunk-C45DY4VE.js";
4
4
 
5
5
  // src/config/defineIcons.ts
6
6
  function _validateIconsProperties(icons) {
@@ -12,7 +12,10 @@ function _validateIconsProperties(icons) {
12
12
  }
13
13
  function defineIcons(icons) {
14
14
  _validateIconsProperties(icons);
15
- $cerberusIcons = icons;
15
+ $cerberusIcons = {
16
+ ...defaultIcons,
17
+ ...icons
18
+ };
16
19
  return $cerberusIcons;
17
20
  }
18
21
  var $cerberusIcons = defaultIcons;
@@ -21,4 +24,4 @@ export {
21
24
  defineIcons,
22
25
  $cerberusIcons
23
26
  };
24
- //# sourceMappingURL=chunk-3CBN7U25.js.map
27
+ //# sourceMappingURL=chunk-6TXQZ3PB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config/defineIcons.ts"],"sourcesContent":["import { defaultIcons, type DefinedIcons } from './cerbIcons'\n\nfunction _validateIconsProperties(icons: DefinedIcons) {\n if (!icons.invalid) {\n throw new Error(\n 'The an invalid property must be defined in your custom icons library.',\n )\n }\n}\n\nexport function defineIcons(icons: DefinedIcons): Required<DefinedIcons> {\n _validateIconsProperties(icons)\n $cerberusIcons = {\n ...defaultIcons,\n ...icons,\n } as Required<DefinedIcons>\n return $cerberusIcons\n}\n\n// Default icons\n\nexport let $cerberusIcons = defaultIcons as Required<DefinedIcons>\n"],"mappings":";;;;;AAEA,SAAS,yBAAyB,OAAqB;AACrD,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,YAAY,OAA6C;AACvE,2BAAyB,KAAK;AAC9B,mBAAiB;AAAA,IACf,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AACA,SAAO;AACT;AAIO,IAAI,iBAAiB;","names":[]}
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-4O4QFF4S.js";
7
7
  import {
8
8
  $cerberusIcons
9
- } from "./chunk-3CBN7U25.js";
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-X4YQ27D5.js.map
42
+ //# sourceMappingURL=chunk-7ISHDUYN.js.map
@@ -0,0 +1,167 @@
1
+ import {
2
+ Portal
3
+ } from "./chunk-4CAT3FHV.js";
4
+ import {
5
+ Button
6
+ } from "./chunk-2ATICEW3.js";
7
+ import {
8
+ Show
9
+ } from "./chunk-4O4QFF4S.js";
10
+ import {
11
+ trapFocus
12
+ } from "./chunk-KESKDLX6.js";
13
+ import {
14
+ $cerberusIcons
15
+ } from "./chunk-6TXQZ3PB.js";
16
+
17
+ // src/context/confirm-modal.tsx
18
+ import {
19
+ createContext,
20
+ useCallback,
21
+ useContext,
22
+ useMemo,
23
+ useRef,
24
+ useState
25
+ } from "react";
26
+ import { css, cx } from "@cerberus-design/styled-system/css";
27
+ import { circle, hstack, vstack } from "@cerberus-design/styled-system/patterns";
28
+ import {
29
+ confirmModal
30
+ } from "@cerberus-design/styled-system/recipes";
31
+ import { jsx, jsxs } from "react/jsx-runtime";
32
+ var ConfirmModalContext = createContext(null);
33
+ function ConfirmModal(props) {
34
+ const dialogRef = useRef(null);
35
+ const resolveRef = useRef(null);
36
+ const [content, setContent] = useState(null);
37
+ const focusTrap = trapFocus(dialogRef);
38
+ const palette = useMemo(
39
+ () => (content == null ? void 0 : content.kind) === "destructive" ? "danger" : "action",
40
+ [content]
41
+ );
42
+ const styles = confirmModal({ palette });
43
+ const handleChoice = useCallback((e) => {
44
+ var _a, _b, _c;
45
+ const target = e.currentTarget;
46
+ if (target.value === "true") {
47
+ (_a = resolveRef.current) == null ? void 0 : _a.call(resolveRef, true);
48
+ }
49
+ (_b = resolveRef.current) == null ? void 0 : _b.call(resolveRef, false);
50
+ (_c = dialogRef == null ? void 0 : dialogRef.current) == null ? void 0 : _c.close();
51
+ }, []);
52
+ const handleShow = useCallback((options) => {
53
+ return new Promise((resolve) => {
54
+ var _a;
55
+ setContent({ ...options, kind: options.kind || "non-destructive" });
56
+ (_a = dialogRef == null ? void 0 : dialogRef.current) == null ? void 0 : _a.showModal();
57
+ resolveRef.current = resolve;
58
+ });
59
+ }, []);
60
+ const value = useMemo(
61
+ () => ({
62
+ show: handleShow
63
+ }),
64
+ [handleShow]
65
+ );
66
+ return /* @__PURE__ */ jsxs(ConfirmModalContext.Provider, { value, children: [
67
+ props.children,
68
+ /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs("dialog", { className: styles.dialog, onKeyDown: focusTrap, ref: dialogRef, children: [
69
+ /* @__PURE__ */ jsxs(
70
+ "div",
71
+ {
72
+ className: vstack({
73
+ alignItems: "flex-start",
74
+ gap: "4",
75
+ mb: "8"
76
+ }),
77
+ children: [
78
+ /* @__PURE__ */ jsx(ConfirmModalIcon, { palette }),
79
+ /* @__PURE__ */ jsx("h2", { className: styles.heading, children: content == null ? void 0 : content.heading }),
80
+ /* @__PURE__ */ jsx("p", { className: styles.description, children: content == null ? void 0 : content.description })
81
+ ]
82
+ }
83
+ ),
84
+ /* @__PURE__ */ jsxs(
85
+ "div",
86
+ {
87
+ className: hstack({
88
+ justifyContent: "stretch",
89
+ gap: "4"
90
+ }),
91
+ children: [
92
+ /* @__PURE__ */ jsx(
93
+ Button,
94
+ {
95
+ autoFocus: true,
96
+ className: css({
97
+ w: "1/2"
98
+ }),
99
+ name: "confirm",
100
+ onClick: handleChoice,
101
+ palette,
102
+ value: "true",
103
+ children: content == null ? void 0 : content.actionText
104
+ }
105
+ ),
106
+ /* @__PURE__ */ jsx(
107
+ Button,
108
+ {
109
+ className: css({
110
+ w: "1/2"
111
+ }),
112
+ name: "cancel",
113
+ onClick: handleChoice,
114
+ usage: "outlined",
115
+ value: "false",
116
+ children: content == null ? void 0 : content.cancelText
117
+ }
118
+ )
119
+ ]
120
+ }
121
+ )
122
+ ] }) })
123
+ ] });
124
+ }
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, { size: 24 }) }),
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, { size: 24 })
147
+ }
148
+ )
149
+ }
150
+ );
151
+ }
152
+ function useConfirmModal() {
153
+ const context = useContext(ConfirmModalContext);
154
+ if (context === null) {
155
+ throw new Error(
156
+ "useConfirmModal must be used within a ConfirmModal Provider"
157
+ );
158
+ }
159
+ return context;
160
+ }
161
+
162
+ export {
163
+ ConfirmModal,
164
+ ConfirmModalIcon,
165
+ useConfirmModal
166
+ };
167
+ //# sourceMappingURL=chunk-BLJ4SRAF.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, cx } from '@cerberus-design/styled-system/css'\nimport { circle, hstack, vstack } from '@cerberus-design/styled-system/patterns'\nimport { $cerberusIcons } from '../config/defineIcons'\nimport {\n confirmModal,\n type ConfirmModalVariantProps,\n} from '@cerberus-design/styled-system/recipes'\nimport { trapFocus } from '../aria-helpers/trap-focus.aria'\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\n const palette = useMemo(\n () => (content?.kind === 'destructive' ? 'danger' : 'action'),\n [content],\n )\n const styles = confirmModal({ palette })\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 <div\n className={vstack({\n alignItems: 'flex-start',\n gap: '4',\n mb: '8',\n })}\n >\n <ConfirmModalIcon palette={palette} />\n <h2 className={styles.heading}>{content?.heading}</h2>\n <p className={styles.description}>{content?.description}</p>\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 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\n// This is to help show the variant styles for the icon since Panda is\n// not syncing correctly for the danger variant.\nexport function ConfirmModalIcon(props: ConfirmModalVariantProps) {\n const InfoIcon = $cerberusIcons.confirmModal\n return (\n <Show\n when={props.palette === 'danger'}\n fallback={\n <div className={cx(confirmModal().icon, circle())}>\n <InfoIcon size={24} />\n </div>\n }\n >\n <div\n className={cx(\n confirmModal({\n palette: 'danger',\n }).icon,\n circle({\n bgColor: 'danger.surface.initial',\n }),\n )}\n style={{\n color: 'var(--cerberus-colors-danger-text-100)',\n }}\n >\n <InfoIcon size={24} />\n </div>\n </Show>\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":"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","names":[]}
@@ -0,0 +1,17 @@
1
+ // src/config/cerbIcons.ts
2
+ import {
3
+ Checkmark,
4
+ Information,
5
+ WarningFilled
6
+ } from "@cerberus/icons";
7
+ var defaultIcons = {
8
+ confirmModal: Information,
9
+ promptModal: Information,
10
+ invalid: WarningFilled,
11
+ toggleChecked: Checkmark
12
+ };
13
+
14
+ export {
15
+ defaultIcons
16
+ };
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":[]}
@@ -0,0 +1,30 @@
1
+ // src/aria-helpers/trap-focus.aria.ts
2
+ function trapFocus(modalRef) {
3
+ var _a;
4
+ const focusableElements = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
5
+ const focusable = Array.from(
6
+ ((_a = modalRef.current) == null ? void 0 : _a.querySelectorAll(focusableElements)) ?? []
7
+ );
8
+ const firstFocusable = focusable[0];
9
+ const lastFocusable = focusable[focusable.length - 1];
10
+ return function handleKeyDown(event) {
11
+ if (event.key === "Tab") {
12
+ if (event.shiftKey) {
13
+ if (document.activeElement === firstFocusable) {
14
+ lastFocusable.focus();
15
+ event.preventDefault();
16
+ }
17
+ } else {
18
+ if (document.activeElement === lastFocusable) {
19
+ firstFocusable.focus();
20
+ event.preventDefault();
21
+ }
22
+ }
23
+ }
24
+ };
25
+ }
26
+
27
+ export {
28
+ trapFocus
29
+ };
30
+ //# sourceMappingURL=chunk-KESKDLX6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/aria-helpers/trap-focus.aria.ts"],"sourcesContent":["import type { KeyboardEvent, KeyboardEventHandler, RefObject } from 'react'\n\nexport function trapFocus(\n modalRef: RefObject<HTMLDialogElement>,\n): KeyboardEventHandler<HTMLDialogElement> {\n const focusableElements =\n 'button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])'\n const focusable = Array.from(\n modalRef.current?.querySelectorAll(focusableElements) ?? [],\n )\n const firstFocusable = focusable[0] as HTMLElement\n const lastFocusable = focusable[focusable.length - 1] as HTMLElement\n\n return function handleKeyDown(event: KeyboardEvent<HTMLDialogElement>) {\n if (event.key === 'Tab') {\n if (event.shiftKey) {\n if (document.activeElement === firstFocusable) {\n lastFocusable.focus()\n event.preventDefault()\n }\n } else {\n if (document.activeElement === lastFocusable) {\n firstFocusable.focus()\n event.preventDefault()\n }\n }\n }\n }\n}\n"],"mappings":";AAEO,SAAS,UACd,UACyC;AAJ3C;AAKE,QAAM,oBACJ;AACF,QAAM,YAAY,MAAM;AAAA,MACtB,cAAS,YAAT,mBAAkB,iBAAiB,uBAAsB,CAAC;AAAA,EAC5D;AACA,QAAM,iBAAiB,UAAU,CAAC;AAClC,QAAM,gBAAgB,UAAU,UAAU,SAAS,CAAC;AAEpD,SAAO,SAAS,cAAc,OAAyC;AACrE,QAAI,MAAM,QAAQ,OAAO;AACvB,UAAI,MAAM,UAAU;AAClB,YAAI,SAAS,kBAAkB,gBAAgB;AAC7C,wBAAc,MAAM;AACpB,gBAAM,eAAe;AAAA,QACvB;AAAA,MACF,OAAO;AACL,YAAI,SAAS,kBAAkB,eAAe;AAC5C,yBAAe,MAAM;AACrB,gBAAM,eAAe;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}