@cerberus-design/react 0.6.1-next-f9a7124 → 0.6.1-next-1315bf2

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 (71) hide show
  1. package/build/legacy/_tsup-dts-rollup.d.ts +72 -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/legacy/{chunk-3CBN7U25.js → chunk-3TYUA4C7.js} +6 -3
  5. package/build/legacy/chunk-3TYUA4C7.js.map +1 -0
  6. package/build/{modern/chunk-JDRWQFCE.js → legacy/chunk-4M3EUP57.js} +1 -1
  7. package/build/legacy/chunk-4M3EUP57.js.map +1 -0
  8. package/build/legacy/{chunk-X4YQ27D5.js → chunk-5RA3ZIXA.js} +2 -2
  9. package/build/legacy/chunk-KESKDLX6.js +30 -0
  10. package/build/legacy/chunk-KESKDLX6.js.map +1 -0
  11. package/build/legacy/chunk-SCAVVE6E.js +16 -0
  12. package/build/legacy/chunk-SCAVVE6E.js.map +1 -0
  13. package/build/legacy/{chunk-734PGVLT.js → chunk-VLVKNEA5.js} +2 -2
  14. package/build/{modern/chunk-ZVNBWU4J.js → legacy/chunk-VULPMZUW.js} +2 -2
  15. package/build/legacy/chunk-YRUUO4AP.js +166 -0
  16. package/build/legacy/chunk-YRUUO4AP.js.map +1 -0
  17. package/build/legacy/components/FeatureFlag.js +2 -2
  18. package/build/legacy/components/Input.js +3 -3
  19. package/build/legacy/components/Toggle.js +3 -3
  20. package/build/legacy/config/cerbIcons.js +1 -1
  21. package/build/legacy/config/defineIcons.js +2 -2
  22. package/build/legacy/context/confirm-modal.js +16 -0
  23. package/build/legacy/context/confirm-modal.js.map +1 -0
  24. package/build/legacy/context/feature-flags.js +1 -1
  25. package/build/legacy/index.js +29 -19
  26. package/build/modern/_tsup-dts-rollup.d.ts +72 -5
  27. package/build/modern/aria-helpers/trap-focus.aria.js +7 -0
  28. package/build/modern/aria-helpers/trap-focus.aria.js.map +1 -0
  29. package/build/modern/{chunk-3CBN7U25.js → chunk-3TYUA4C7.js} +6 -3
  30. package/build/modern/chunk-3TYUA4C7.js.map +1 -0
  31. package/build/{legacy/chunk-JDRWQFCE.js → modern/chunk-4M3EUP57.js} +1 -1
  32. package/build/modern/chunk-4M3EUP57.js.map +1 -0
  33. package/build/modern/{chunk-X4YQ27D5.js → chunk-5RA3ZIXA.js} +2 -2
  34. package/build/modern/chunk-BVK6GEDZ.js +164 -0
  35. package/build/modern/chunk-BVK6GEDZ.js.map +1 -0
  36. package/build/modern/chunk-JIZQFTW6.js +29 -0
  37. package/build/modern/chunk-JIZQFTW6.js.map +1 -0
  38. package/build/modern/chunk-SCAVVE6E.js +16 -0
  39. package/build/modern/chunk-SCAVVE6E.js.map +1 -0
  40. package/build/modern/{chunk-734PGVLT.js → chunk-VLVKNEA5.js} +2 -2
  41. package/build/{legacy/chunk-ZVNBWU4J.js → modern/chunk-VULPMZUW.js} +2 -2
  42. package/build/modern/components/FeatureFlag.js +2 -2
  43. package/build/modern/components/Input.js +3 -3
  44. package/build/modern/components/Toggle.js +3 -3
  45. package/build/modern/config/cerbIcons.js +1 -1
  46. package/build/modern/config/defineIcons.js +2 -2
  47. package/build/modern/context/confirm-modal.js +16 -0
  48. package/build/modern/context/confirm-modal.js.map +1 -0
  49. package/build/modern/context/feature-flags.js +1 -1
  50. package/build/modern/index.js +29 -19
  51. package/package.json +2 -2
  52. package/src/aria-helpers/trap-focus.aria.ts +29 -0
  53. package/src/config/cerbIcons.ts +9 -2
  54. package/src/config/defineIcons.ts +6 -3
  55. package/src/context/confirm-modal.tsx +205 -0
  56. package/src/context/feature-flags.tsx +2 -2
  57. package/src/index.ts +2 -0
  58. package/build/legacy/chunk-3CBN7U25.js.map +0 -1
  59. package/build/legacy/chunk-5MNCW677.js +0 -11
  60. package/build/legacy/chunk-5MNCW677.js.map +0 -1
  61. package/build/legacy/chunk-JDRWQFCE.js.map +0 -1
  62. package/build/modern/chunk-3CBN7U25.js.map +0 -1
  63. package/build/modern/chunk-5MNCW677.js +0 -11
  64. package/build/modern/chunk-5MNCW677.js.map +0 -1
  65. package/build/modern/chunk-JDRWQFCE.js.map +0 -1
  66. /package/build/legacy/{chunk-X4YQ27D5.js.map → chunk-5RA3ZIXA.js.map} +0 -0
  67. /package/build/legacy/{chunk-734PGVLT.js.map → chunk-VLVKNEA5.js.map} +0 -0
  68. /package/build/legacy/{chunk-ZVNBWU4J.js.map → chunk-VULPMZUW.js.map} +0 -0
  69. /package/build/modern/{chunk-X4YQ27D5.js.map → chunk-5RA3ZIXA.js.map} +0 -0
  70. /package/build/modern/{chunk-734PGVLT.js.map → chunk-VLVKNEA5.js.map} +0 -0
  71. /package/build/modern/{chunk-ZVNBWU4J.js.map → chunk-VULPMZUW.js.map} +0 -0
@@ -11,6 +11,7 @@ import { iconButton } from '@cerberus/styled-system/recipes';
11
11
  import { input } from '@cerberus/styled-system/recipes';
12
12
  import type { InputHTMLAttributes } from 'react';
13
13
  import { JSX as JSX_2 } from 'react/jsx-runtime';
14
+ import type { KeyboardEventHandler } from 'react';
14
15
  import { label } from '@cerberus/styled-system/recipes';
15
16
  import { MutableRefObject } from 'react';
16
17
  import type { Pretty } from '@cerberus-design/styled-system/types';
@@ -27,7 +28,7 @@ import { tag } from '@cerberus/styled-system/recipes';
27
28
  import type { TextareaHTMLAttributes } from 'react';
28
29
  import { ToggleVariantProps } from '@cerberus-design/styled-system/recipes';
29
30
 
30
- declare let $cerberusIcons: DefinedIcons;
31
+ declare let $cerberusIcons: Required<DefinedIcons>;
31
32
  export { $cerberusIcons }
32
33
  export { $cerberusIcons as $cerberusIcons_alias_1 }
33
34
 
@@ -61,6 +62,45 @@ declare type ColorModes = 'light' | 'dark';
61
62
  export { ColorModes }
62
63
  export { ColorModes as ColorModes_alias_1 }
63
64
 
65
+ /**
66
+ * Provides a confirm modal to the app.
67
+ * @example
68
+ * ```tsx
69
+ * // Wrap the Provider around the root of the feature.
70
+ * <ConfirmModal>
71
+ * <SomeFeatureSection />
72
+ * </ConfirmModal>
73
+ *
74
+ * // Use the hook to show the confirm modal.
75
+ * const confirm = useConfirmModal()
76
+ *
77
+ * const handleClick = useCallback(async () => {
78
+ * const userConsent = await confirm.show({
79
+ * heading: 'Add new payment method?',
80
+ * description:
81
+ * 'This will add a new payment method to your account to be billed for future purchases.',
82
+ * actionText: 'Yes, add payment method',
83
+ * cancelText: 'No, cancel',
84
+ * })
85
+ * setConsent(userConsent)
86
+ * }, [confirm])
87
+ * ```
88
+ */
89
+ declare function ConfirmModal(props: PropsWithChildren<ConfirmModalProviderProps>): JSX_2.Element;
90
+ export { ConfirmModal }
91
+ export { ConfirmModal as ConfirmModal_alias_1 }
92
+
93
+ declare interface ConfirmModalProviderProps {
94
+ }
95
+ export { ConfirmModalProviderProps }
96
+ export { ConfirmModalProviderProps as ConfirmModalProviderProps_alias_1 }
97
+
98
+ declare interface ConfirmModalValue {
99
+ show: (options: ShowConfirmModalOptions) => Promise<boolean>;
100
+ }
101
+ export { ConfirmModalValue }
102
+ export { ConfirmModalValue as ConfirmModalValue_alias_1 }
103
+
64
104
  declare function createNavTriggerProps(values: NavTriggerAriaValues): NavTriggerAriaReturn;
65
105
  export { createNavTriggerProps }
66
106
  export { createNavTriggerProps as createNavTriggerProps_alias_1 }
@@ -76,11 +116,12 @@ export { DefaultThemes }
76
116
  export { DefaultThemes as DefaultThemes_alias_1 }
77
117
 
78
118
  export declare interface DefinedIcons {
119
+ confirmModal?: CarbonIconType | ElementType;
79
120
  invalid: CarbonIconType | ElementType;
80
- toggleChecked: CarbonIconType | ElementType;
121
+ toggleChecked?: CarbonIconType | ElementType;
81
122
  }
82
123
 
83
- declare function defineIcons(icons: DefinedIcons): DefinedIcons;
124
+ declare function defineIcons(icons: DefinedIcons): Required<DefinedIcons>;
84
125
  export { defineIcons }
85
126
  export { defineIcons as defineIcons_alias_1 }
86
127
 
@@ -112,14 +153,14 @@ export { FeatureFlagProviderProps as FeatureFlagProviderProps_alias_1 }
112
153
  * }
113
154
  *
114
155
  * // Wrap the Provider around the root of your application.
115
- * <FeatureFlagProvider flags={flags}>
156
+ * <FeatureFlags flags={flags}>
116
157
  * <FeatureFlag flag="featureOne">
117
158
  * This is visible.
118
159
  * </FeatureFlag>
119
160
  * <FeatureFlag flag="featureTwo">
120
161
  * This is hidden.
121
162
  * </FeatureFlag>
122
- * </FeatureFlagProvider>
163
+ * </FeatureFlags>
123
164
  * ```
124
165
  */
125
166
  declare function FeatureFlags(props: PropsWithChildren<FeatureFlagProviderProps>): JSX_2.Element;
@@ -427,6 +468,20 @@ declare function Show(props: PropsWithChildren<ShowProps>): ReactNode;
427
468
  export { Show }
428
469
  export { Show as Show_alias_1 }
429
470
 
471
+ /**
472
+ * This module provides a context and hook for the confirm modal.
473
+ * @module
474
+ */
475
+ declare interface ShowConfirmModalOptions {
476
+ kind?: 'destructive' | 'non-destructive';
477
+ heading: string;
478
+ description?: string;
479
+ actionText: string;
480
+ cancelText: string;
481
+ }
482
+ export { ShowConfirmModalOptions }
483
+ export { ShowConfirmModalOptions as ShowConfirmModalOptions_alias_1 }
484
+
430
485
  declare interface ShowProps {
431
486
  when: boolean | null | undefined;
432
487
  fallback?: ReactNode;
@@ -434,6 +489,10 @@ declare interface ShowProps {
434
489
  export { ShowProps }
435
490
  export { ShowProps as ShowProps_alias_1 }
436
491
 
492
+ declare type ShowResult = ((value: boolean | PromiseLike<boolean>) => void) | null;
493
+ export { ShowResult }
494
+ export { ShowResult as ShowResult_alias_1 }
495
+
437
496
  declare type StaticTagProps = HTMLAttributes<HTMLSpanElement> & TagRecipeProps & {
438
497
  onClick?: never;
439
498
  };
@@ -660,6 +719,14 @@ declare type ToggleProps = ToggleBase & ToggleVariantProps;
660
719
  export { ToggleProps }
661
720
  export { ToggleProps as ToggleProps_alias_1 }
662
721
 
722
+ declare function trapFocus(modalRef: RefObject<HTMLDialogElement>): KeyboardEventHandler<HTMLDialogElement>;
723
+ export { trapFocus }
724
+ export { trapFocus as trapFocus_alias_1 }
725
+
726
+ declare function useConfirmModal(): ConfirmModalValue;
727
+ export { useConfirmModal }
728
+ export { useConfirmModal as useConfirmModal_alias_1 }
729
+
663
730
  declare function useFeatureFlags(key: string): boolean;
664
731
  export { useFeatureFlags }
665
732
  export { useFeatureFlags as useFeatureFlags_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":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultIcons
3
- } from "./chunk-5MNCW677.js";
3
+ } from "./chunk-SCAVVE6E.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-3TYUA4C7.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":[]}
@@ -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":[]}
@@ -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-3TYUA4C7.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-5RA3ZIXA.js.map
@@ -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":[]}
@@ -0,0 +1,16 @@
1
+ // src/config/cerbIcons.ts
2
+ import {
3
+ Checkmark,
4
+ Information,
5
+ WarningFilled
6
+ } from "@cerberus/icons";
7
+ var defaultIcons = {
8
+ confirmModal: Information,
9
+ invalid: WarningFilled,
10
+ toggleChecked: Checkmark
11
+ };
12
+
13
+ export {
14
+ defaultIcons
15
+ };
16
+ //# sourceMappingURL=chunk-SCAVVE6E.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 invalid: CarbonIconType | ElementType\n toggleChecked?: CarbonIconType | ElementType\n}\n\nexport const defaultIcons: DefinedIcons = {\n confirmModal: Information,\n invalid: WarningFilled,\n toggleChecked: Checkmark,\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AASA,IAAM,eAA6B;AAAA,EACxC,cAAc;AAAA,EACd,SAAS;AAAA,EACT,eAAe;AACjB;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-ZAU4JVLL.js";
4
4
  import {
5
5
  $cerberusIcons
6
- } from "./chunk-3CBN7U25.js";
6
+ } from "./chunk-3TYUA4C7.js";
7
7
 
8
8
  // src/components/Toggle.tsx
9
9
  import { cx } from "@cerberus-design/styled-system/css";
@@ -55,4 +55,4 @@ function Toggle(props) {
55
55
  export {
56
56
  Toggle
57
57
  };
58
- //# sourceMappingURL=chunk-734PGVLT.js.map
58
+ //# sourceMappingURL=chunk-VLVKNEA5.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useFeatureFlags
3
- } from "./chunk-JDRWQFCE.js";
3
+ } from "./chunk-4M3EUP57.js";
4
4
  import {
5
5
  Show
6
6
  } from "./chunk-4O4QFF4S.js";
@@ -15,4 +15,4 @@ function FeatureFlag(props) {
15
15
  export {
16
16
  FeatureFlag
17
17
  };
18
- //# sourceMappingURL=chunk-ZVNBWU4J.js.map
18
+ //# sourceMappingURL=chunk-VULPMZUW.js.map
@@ -0,0 +1,166 @@
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-3TYUA4C7.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, {}) }),
132
+ children: /* @__PURE__ */ jsx(
133
+ "div",
134
+ {
135
+ className: cx(
136
+ confirmModal({
137
+ palette: "danger"
138
+ }).icon,
139
+ circle({
140
+ bgColor: "danger.surface.initial"
141
+ })
142
+ ),
143
+ style: {
144
+ color: "var(--cerberus-colors-danger-text-100)"
145
+ },
146
+ children: /* @__PURE__ */ jsx(InfoIcon, {})
147
+ }
148
+ )
149
+ }
150
+ );
151
+ }
152
+ 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
+ useConfirmModal
165
+ };
166
+ //# sourceMappingURL=chunk-YRUUO4AP.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.\nfunction 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 />\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 />\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":";;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP,SAAS,KAAK,UAAU;AACxB,SAAS,QAAQ,QAAQ,cAAc;AAEvC;AAAA,EACE;AAAA,OAEK;AAgGG,SAOE,KAPF;AAxEV,IAAM,sBAAsB,cAAwC,IAAI;AA4BjE,SAAS,aACd,OACA;AACA,QAAM,YAAY,OAA0B,IAAI;AAChD,QAAM,aAAa,OAAmB,IAAI;AAC1C,QAA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"use client";
2
2
  import {
3
3
  FeatureFlag
4
- } from "../chunk-ZVNBWU4J.js";
5
- import "../chunk-JDRWQFCE.js";
4
+ } from "../chunk-VULPMZUW.js";
5
+ import "../chunk-4M3EUP57.js";
6
6
  import "../chunk-4O4QFF4S.js";
7
7
  export {
8
8
  FeatureFlag
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import {
3
3
  Input
4
- } from "../chunk-X4YQ27D5.js";
4
+ } from "../chunk-5RA3ZIXA.js";
5
5
  import "../chunk-ZAU4JVLL.js";
6
6
  import "../chunk-4O4QFF4S.js";
7
- import "../chunk-3CBN7U25.js";
8
- import "../chunk-5MNCW677.js";
7
+ import "../chunk-3TYUA4C7.js";
8
+ import "../chunk-SCAVVE6E.js";
9
9
  export {
10
10
  Input
11
11
  };
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import {
3
3
  Toggle
4
- } from "../chunk-734PGVLT.js";
4
+ } from "../chunk-VLVKNEA5.js";
5
5
  import "../chunk-ZAU4JVLL.js";
6
- import "../chunk-3CBN7U25.js";
7
- import "../chunk-5MNCW677.js";
6
+ import "../chunk-3TYUA4C7.js";
7
+ import "../chunk-SCAVVE6E.js";
8
8
  export {
9
9
  Toggle
10
10
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultIcons
3
- } from "../chunk-5MNCW677.js";
3
+ } from "../chunk-SCAVVE6E.js";
4
4
  export {
5
5
  defaultIcons
6
6
  };
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  $cerberusIcons,
3
3
  defineIcons
4
- } from "../chunk-3CBN7U25.js";
5
- import "../chunk-5MNCW677.js";
4
+ } from "../chunk-3TYUA4C7.js";
5
+ import "../chunk-SCAVVE6E.js";
6
6
  export {
7
7
  $cerberusIcons,
8
8
  defineIcons
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ import {
3
+ ConfirmModal,
4
+ useConfirmModal
5
+ } from "../chunk-YRUUO4AP.js";
6
+ import "../chunk-4CAT3FHV.js";
7
+ import "../chunk-2ATICEW3.js";
8
+ import "../chunk-4O4QFF4S.js";
9
+ import "../chunk-KESKDLX6.js";
10
+ import "../chunk-3TYUA4C7.js";
11
+ import "../chunk-SCAVVE6E.js";
12
+ export {
13
+ ConfirmModal,
14
+ useConfirmModal
15
+ };
16
+ //# sourceMappingURL=confirm-modal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  FeatureFlags,
4
4
  useFeatureFlags
5
- } from "../chunk-JDRWQFCE.js";
5
+ } from "../chunk-4M3EUP57.js";
6
6
  export {
7
7
  FeatureFlags,
8
8
  useFeatureFlags