@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
@@ -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":[]}
@@ -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-KESKDLX6.js";
16
28
  import {
17
29
  $cerberusIcons
18
30
  } from "./chunk-6TXQZ3PB.js";
31
+ import {
32
+ useModal
33
+ } from "./chunk-TZNYJ3G7.js";
19
34
 
20
35
  // src/context/confirm-modal.tsx
21
36
  import {
@@ -27,38 +42,41 @@ 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 == null ? void 0 : content.kind) === "destructive" ? "danger" : "action",
42
56
  [content]
43
57
  );
44
- const styles = modal();
45
- const handleChoice = useCallback((e) => {
46
- var _a, _b, _c;
47
- const target = e.currentTarget;
48
- if (target.value === "true") {
49
- (_a = resolveRef.current) == null ? void 0 : _a.call(resolveRef, true);
50
- }
51
- (_b = resolveRef.current) == null ? void 0 : _b.call(resolveRef, false);
52
- (_c = dialogRef == null ? void 0 : dialogRef.current) == null ? void 0 : _c.close();
53
- }, []);
54
- const handleShow = useCallback((options) => {
55
- return new Promise((resolve) => {
56
- var _a;
57
- setContent({ ...options, kind: options.kind || "non-destructive" });
58
- (_a = dialogRef == null ? void 0 : dialogRef.current) == null ? void 0 : _a.showModal();
59
- resolveRef.current = resolve;
60
- });
61
- }, []);
58
+ const handleChoice = useCallback(
59
+ (e) => {
60
+ var _a, _b;
61
+ const target = e.currentTarget;
62
+ if (target.value === "true") {
63
+ (_a = resolveRef.current) == null ? void 0 : _a.call(resolveRef, true);
64
+ }
65
+ (_b = resolveRef.current) == null ? void 0 : _b.call(resolveRef, false);
66
+ close();
67
+ },
68
+ [close]
69
+ );
70
+ const handleShow = useCallback(
71
+ (options) => {
72
+ return new Promise((resolve) => {
73
+ setContent({ ...options, kind: options.kind || "non-destructive" });
74
+ show();
75
+ resolveRef.current = resolve;
76
+ });
77
+ },
78
+ [show]
79
+ );
62
80
  const value = useMemo(
63
81
  () => ({
64
82
  show: handleShow
@@ -67,29 +85,19 @@ function ConfirmModal(props) {
67
85
  );
68
86
  return /* @__PURE__ */ jsxs(ConfirmModalContext.Provider, { value, children: [
69
87
  props.children,
70
- /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs("dialog", { className: styles.dialog, onKeyDown: focusTrap, ref: dialogRef, children: [
71
- /* @__PURE__ */ jsxs(
72
- "section",
73
- {
74
- className: vstack({
75
- alignItems: "flex-start",
76
- gap: "4",
77
- mb: "8"
78
- }),
79
- children: [
80
- /* @__PURE__ */ jsx(
81
- Show,
82
- {
83
- when: palette === "danger",
84
- fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) }),
85
- children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) })
86
- }
87
- ),
88
- /* @__PURE__ */ jsx("h2", { className: styles.heading, children: content == null ? void 0 : content.heading }),
89
- /* @__PURE__ */ jsx("p", { className: styles.description, children: content == null ? void 0 : content.description })
90
- ]
91
- }
92
- ),
88
+ /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs(Modal, { onKeyDown: focusTrap, ref: modalRef, children: [
89
+ /* @__PURE__ */ jsxs(ModalHeader, { children: [
90
+ /* @__PURE__ */ jsx(
91
+ Show,
92
+ {
93
+ when: palette === "danger",
94
+ fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) }),
95
+ children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(ConfirmIcon, { size: 24 }) })
96
+ }
97
+ ),
98
+ /* @__PURE__ */ jsx(ModalHeading, { children: content == null ? void 0 : content.heading }),
99
+ /* @__PURE__ */ jsx(ModalDescription, { children: content == null ? void 0 : content.description })
100
+ ] }),
93
101
  /* @__PURE__ */ jsxs(
94
102
  "div",
95
103
  {
@@ -144,4 +152,4 @@ export {
144
152
  ConfirmModal,
145
153
  useConfirmModal
146
154
  };
147
- //# sourceMappingURL=chunk-UZIN7UOS.js.map
155
+ //# sourceMappingURL=chunk-D3ZXZA3U.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/confirm-modal.tsx"],"sourcesContent":["'use client'\n\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n type MouseEvent,\n type PropsWithChildren,\n} from 'react'\nimport { Portal } from '../components/Portal'\nimport { Button } from '../components/Button'\nimport { css } from '@cerberus-design/styled-system/css'\nimport { hstack } from '@cerberus-design/styled-system/patterns'\nimport { $cerberusIcons } from '../config/defineIcons'\nimport { trapFocus } from '../aria-helpers/trap-focus.aria'\nimport { ModalIcon } from '../components/ModalIcon'\nimport { Show } from '../components/Show'\nimport { Modal } from '../components/Modal'\nimport { useModal } from '../hooks/useModal'\nimport { ModalHeader } from '../components/ModalHeader'\nimport { ModalHeading } from '../components/ModalHeading'\nimport { ModalDescription } from '../components/ModalDescription'\n\n/**\n * This module provides a context and hook for the confirm modal.\n * @module\n */\n\nexport interface ShowConfirmModalOptions {\n kind?: 'destructive' | 'non-destructive'\n heading: string\n description?: string\n actionText: string\n cancelText: string\n}\nexport type ShowResult =\n | ((value: boolean | PromiseLike<boolean>) => void)\n | null\n\nexport interface ConfirmModalValue {\n show: (options: ShowConfirmModalOptions) => Promise<boolean>\n}\n\nconst ConfirmModalContext = createContext<ConfirmModalValue | null>(null)\n\nexport interface ConfirmModalProviderProps {}\n\n/**\n * Provides a confirm modal to the app.\n * @example\n * ```tsx\n * // Wrap the Provider around the root of the feature.\n * <ConfirmModal>\n * <SomeFeatureSection />\n * </ConfirmModal>\n *\n * // Use the hook to show the confirm modal.\n * const confirm = useConfirmModal()\n *\n * const handleClick = useCallback(async () => {\n * const userConsent = await confirm.show({\n * heading: 'Add new payment method?',\n * description:\n * 'This will add a new payment method to your account to be billed for future purchases.',\n * actionText: 'Yes, add payment method',\n * cancelText: 'No, cancel',\n * })\n * setConsent(userConsent)\n * }, [confirm])\n * ```\n */\nexport function ConfirmModal(\n props: PropsWithChildren<ConfirmModalProviderProps>,\n) {\n const { modalRef, show, close } = useModal()\n const resolveRef = useRef<ShowResult>(null)\n const [content, setContent] = useState<ShowConfirmModalOptions | null>(null)\n const focusTrap = trapFocus(modalRef)\n const ConfirmIcon = $cerberusIcons.confirmModal\n\n const palette = useMemo(\n () => (content?.kind === 'destructive' ? 'danger' : 'action'),\n [content],\n )\n\n const handleChoice = useCallback(\n (e: MouseEvent<HTMLButtonElement>) => {\n const target = e.currentTarget as HTMLButtonElement\n if (target.value === 'true') {\n resolveRef.current?.(true)\n }\n resolveRef.current?.(false)\n close()\n },\n [close],\n )\n\n const handleShow = useCallback(\n (options: ShowConfirmModalOptions) => {\n return new Promise<boolean>((resolve) => {\n setContent({ ...options, kind: options.kind || 'non-destructive' })\n show()\n resolveRef.current = resolve\n })\n },\n [show],\n )\n\n const value = useMemo(\n () => ({\n show: handleShow,\n }),\n [handleShow],\n )\n\n return (\n <ConfirmModalContext.Provider value={value}>\n {props.children}\n\n <Portal>\n <Modal onKeyDown={focusTrap} ref={modalRef}>\n <ModalHeader>\n <Show\n when={palette === 'danger'}\n fallback={\n <ModalIcon palette=\"action\">\n <ConfirmIcon size={24} />\n </ModalIcon>\n }\n >\n <ModalIcon palette=\"danger\">\n <ConfirmIcon size={24} />\n </ModalIcon>\n </Show>\n <ModalHeading>{content?.heading}</ModalHeading>\n <ModalDescription>{content?.description}</ModalDescription>\n </ModalHeader>\n\n <div\n className={hstack({\n gap: '4',\n })}\n >\n <Button\n autoFocus\n className={css({\n w: '1/2',\n })}\n name=\"confirm\"\n onClick={handleChoice}\n palette={palette}\n value=\"true\"\n >\n {content?.actionText}\n </Button>\n <Button\n className={css({\n w: '1/2',\n })}\n name=\"cancel\"\n onClick={handleChoice}\n usage=\"outlined\"\n value=\"false\"\n >\n {content?.cancelText}\n </Button>\n </div>\n </Modal>\n </Portal>\n </ConfirmModalContext.Provider>\n )\n}\n\nexport function useConfirmModal(): ConfirmModalValue {\n const context = useContext(ConfirmModalContext)\n if (context === null) {\n throw new Error(\n 'useConfirmModal must be used within a ConfirmModal Provider',\n )\n }\n return context\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP,SAAS,WAAW;AACpB,SAAS,cAAc;AA6Gb,SAKQ,KALR;AA9EV,IAAM,sBAAsB,cAAwC,IAAI;AA4BjE,SAAS,aACd,OACA;AACA,QAAM,EAAE,UAAU,MAAM,MAAM,IAAI,SAAS;AAC3C,QAAM,aAAa,OAAmB,IAAI;AAC1C,QAAM,CAAC,SAAS,UAAU,IAAI,SAAyC,IAAI;AAC3E,QAAM,YAAY,UAAU,QAAQ;AACpC,QAAM,cAAc,eAAe;AAEnC,QAAM,UAAU;AAAA,IACd,OAAO,mCAAS,UAAS,gBAAgB,WAAW;AAAA,IACpD,CAAC,OAAO;AAAA,EACV;AAEA,QAAM,eAAe;AAAA,IACnB,CAAC,MAAqC;AAzF1C;AA0FM,YAAM,SAAS,EAAE;AACjB,UAAI,OAAO,UAAU,QAAQ;AAC3B,yBAAW,YAAX,oCAAqB;AAAA,MACvB;AACA,uBAAW,YAAX,oCAAqB;AACrB,YAAM;AAAA,IACR;AAAA,IACA,CAAC,KAAK;AAAA,EACR;AAEA,QAAM,aAAa;AAAA,IACjB,CAAC,YAAqC;AACpC,aAAO,IAAI,QAAiB,CAAC,YAAY;AACvC,mBAAW,EAAE,GAAG,SAAS,MAAM,QAAQ,QAAQ,kBAAkB,CAAC;AAClE,aAAK;AACL,mBAAW,UAAU;AAAA,MACvB,CAAC;AAAA,IACH;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,QAAM,QAAQ;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,6CAAS,SAAQ;AAAA,QAChC,oBAAC,oBAAkB,6CAAS,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,6CAAS;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,6CAAS;AAAA;AAAA,YACZ;AAAA;AAAA;AAAA,MACF;AAAA,OACF,GACF;AAAA,KACF;AAEJ;AAEO,SAAS,kBAAqC;AACnD,QAAM,UAAU,WAAW,mBAAmB;AAC9C,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
@@ -1,6 +1,21 @@
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";
@@ -16,15 +31,15 @@ import {
16
31
  import {
17
32
  Field
18
33
  } from "./chunk-ZAU4JVLL.js";
19
- import {
20
- ModalIcon
21
- } from "./chunk-G3JEWPLM.js";
22
34
  import {
23
35
  trapFocus
24
36
  } from "./chunk-KESKDLX6.js";
25
37
  import {
26
38
  $cerberusIcons
27
39
  } from "./chunk-6TXQZ3PB.js";
40
+ import {
41
+ useModal
42
+ } from "./chunk-TZNYJ3G7.js";
28
43
 
29
44
  // src/context/prompt-modal.tsx
30
45
  import {
@@ -37,15 +52,14 @@ import {
37
52
  } from "react";
38
53
  import { css } from "@cerberus-design/styled-system/css";
39
54
  import { hstack, vstack } from "@cerberus-design/styled-system/patterns";
40
- import { modal } from "@cerberus-design/styled-system/recipes";
41
55
  import { jsx, jsxs } from "react/jsx-runtime";
42
56
  var PromptModalContext = createContext(null);
43
57
  function PromptModal(props) {
44
- const dialogRef = useRef(null);
58
+ const { modalRef, show, close } = useModal();
45
59
  const resolveRef = useRef(null);
46
60
  const [content, setContent] = useState(null);
47
61
  const [inputValue, setInputValue] = useState("");
48
- const focusTrap = trapFocus(dialogRef);
62
+ const focusTrap = trapFocus(modalRef);
49
63
  const PromptIcon = $cerberusIcons.promptModal;
50
64
  const isValid = useMemo(
51
65
  () => inputValue === (content == null ? void 0 : content.key),
@@ -55,7 +69,6 @@ function PromptModal(props) {
55
69
  () => (content == null ? void 0 : content.kind) === "destructive" ? "danger" : "action",
56
70
  [content]
57
71
  );
58
- const styles = modal();
59
72
  const handleChange = useCallback(
60
73
  (e) => {
61
74
  setInputValue(e.currentTarget.value);
@@ -64,23 +77,25 @@ function PromptModal(props) {
64
77
  );
65
78
  const handleChoice = useCallback(
66
79
  (e) => {
67
- var _a, _b;
80
+ var _a;
68
81
  const target = e.currentTarget;
69
82
  if (target.value === "true") {
70
83
  (_a = resolveRef.current) == null ? void 0 : _a.call(resolveRef, inputValue);
71
84
  }
72
- (_b = dialogRef == null ? void 0 : dialogRef.current) == null ? void 0 : _b.close();
85
+ close();
73
86
  },
74
- [inputValue]
87
+ [inputValue, close]
88
+ );
89
+ const handleShow = useCallback(
90
+ (options) => {
91
+ return new Promise((resolve) => {
92
+ setContent({ ...options, kind: options.kind || "non-destructive" });
93
+ show();
94
+ resolveRef.current = resolve;
95
+ });
96
+ },
97
+ [show]
75
98
  );
76
- const handleShow = useCallback((options) => {
77
- return new Promise((resolve) => {
78
- var _a;
79
- setContent({ ...options, kind: options.kind || "non-destructive" });
80
- (_a = dialogRef == null ? void 0 : dialogRef.current) == null ? void 0 : _a.showModal();
81
- resolveRef.current = resolve;
82
- });
83
- }, []);
84
99
  const value = useMemo(
85
100
  () => ({
86
101
  show: handleShow
@@ -89,28 +104,19 @@ function PromptModal(props) {
89
104
  );
90
105
  return /* @__PURE__ */ jsxs(PromptModalContext.Provider, { value, children: [
91
106
  props.children,
92
- /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs("dialog", { className: styles.dialog, onKeyDown: focusTrap, ref: dialogRef, children: [
93
- /* @__PURE__ */ jsxs(
94
- "div",
95
- {
96
- className: vstack({
97
- alignItems: "flex-start",
98
- gap: "4"
99
- }),
100
- children: [
101
- /* @__PURE__ */ jsx(
102
- Show,
103
- {
104
- when: palette === "danger",
105
- fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) }),
106
- children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) })
107
- }
108
- ),
109
- /* @__PURE__ */ jsx("h2", { className: styles.heading, children: content == null ? void 0 : content.heading }),
110
- /* @__PURE__ */ jsx("p", { className: styles.description, children: content == null ? void 0 : content.description })
111
- ]
112
- }
113
- ),
107
+ /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsxs(Modal, { onKeyDown: focusTrap, ref: modalRef, children: [
108
+ /* @__PURE__ */ jsxs(ModalHeader, { children: [
109
+ /* @__PURE__ */ jsx(
110
+ Show,
111
+ {
112
+ when: palette === "danger",
113
+ fallback: /* @__PURE__ */ jsx(ModalIcon, { palette: "action", children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) }),
114
+ children: /* @__PURE__ */ jsx(ModalIcon, { palette: "danger", children: /* @__PURE__ */ jsx(PromptIcon, { size: 24 }) })
115
+ }
116
+ ),
117
+ /* @__PURE__ */ jsx(ModalHeading, { children: content == null ? void 0 : content.heading }),
118
+ /* @__PURE__ */ jsx(ModalDescription, { children: content == null ? void 0 : content.description })
119
+ ] }),
114
120
  /* @__PURE__ */ jsx(
115
121
  "div",
116
122
  {
@@ -199,4 +205,4 @@ export {
199
205
  PromptModal,
200
206
  usePromptModal
201
207
  };
202
- //# sourceMappingURL=chunk-WKSC2WCV.js.map
208
+ //# sourceMappingURL=chunk-DGPLSWFJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/prompt-modal.tsx"],"sourcesContent":["'use client'\n\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n type ChangeEvent,\n type MouseEvent,\n type PropsWithChildren,\n} from 'react'\nimport { Portal } from '../components/Portal'\nimport { Button } from '../components/Button'\nimport { css } from '@cerberus-design/styled-system/css'\nimport { hstack, vstack } from '@cerberus-design/styled-system/patterns'\nimport { trapFocus } from '../aria-helpers/trap-focus.aria'\nimport { Input } from '../components/Input'\nimport { Field } from './field'\nimport { Label } from '../components/Label'\nimport { $cerberusIcons } from '../config/defineIcons'\nimport { ModalIcon } from '../components/ModalIcon'\nimport { Show } from '../components/Show'\nimport { useModal } from '../hooks/useModal'\nimport { Modal } from '../components/Modal'\nimport { ModalHeader } from '../components/ModalHeader'\nimport { ModalHeading } from '../components/ModalHeading'\nimport { ModalDescription } from '../components/ModalDescription'\n\n/**\n * This module provides a context and hook for the prompt modal.\n * @module\n */\n\nexport interface ShowPromptModalOptions {\n kind?: 'destructive' | 'non-destructive'\n heading: string\n description?: string\n key: string\n actionText: string\n cancelText: string\n}\nexport type PromptShowResult =\n | ((value: string | PromiseLike<string>) => void)\n | null\n\nexport interface PromptModalValue {\n show: (options: ShowPromptModalOptions) => Promise<string>\n}\n\nconst PromptModalContext = createContext<PromptModalValue | null>(null)\n\nexport interface PromptModalProviderProps {}\n\n/**\n * Provides a prompt modal to the app.\n * @example\n * ```tsx\n * // Wrap the Provider around the root of the feature.\n * <PromptModal>\n * <SomeFeatureSection />\n * </PromptModal>\n *\n * // Use the hook to show the prompt modal.\n * const prompt = usePromptModal()\n *\n * const handleClick = useCallback(async () => {\n * const accepted = await prompt.show({\n * kind: 'destructive',\n * heading: 'Delete channel?',\n * description:\n * 'This will permanently delete a channel on your account. There is no going back.',\n * key: CHANNEL_NAME,\n * actionText: 'Yes, delete channel',\n * cancelText: 'No, cancel',\n * })\n * // do something with accepted\n * }, [prompt])\n * ```\n */\nexport function PromptModal(\n props: PropsWithChildren<PromptModalProviderProps>,\n) {\n const { modalRef, show, close } = useModal()\n const resolveRef = useRef<PromptShowResult>(null)\n const [content, setContent] = useState<ShowPromptModalOptions | null>(null)\n const [inputValue, setInputValue] = useState<string>('')\n const focusTrap = trapFocus(modalRef)\n const PromptIcon = $cerberusIcons.promptModal\n\n const isValid = useMemo(\n () => inputValue === content?.key,\n [inputValue, content],\n )\n\n const palette = useMemo(\n () => (content?.kind === 'destructive' ? 'danger' : 'action'),\n [content],\n )\n\n const handleChange = useCallback(\n (e: ChangeEvent<HTMLInputElement>) => {\n setInputValue(e.currentTarget.value)\n },\n [content],\n )\n\n const handleChoice = useCallback(\n (e: MouseEvent<HTMLButtonElement>) => {\n const target = e.currentTarget as HTMLButtonElement\n if (target.value === 'true') {\n resolveRef.current?.(inputValue)\n }\n close()\n },\n [inputValue, close],\n )\n\n const handleShow = useCallback(\n (options: ShowPromptModalOptions) => {\n return new Promise<string>((resolve) => {\n setContent({ ...options, kind: options.kind || 'non-destructive' })\n show()\n resolveRef.current = resolve\n })\n },\n [show],\n )\n\n const value = useMemo(\n () => ({\n show: handleShow,\n }),\n [handleShow],\n )\n\n return (\n <PromptModalContext.Provider value={value}>\n {props.children}\n\n <Portal>\n <Modal onKeyDown={focusTrap} ref={modalRef}>\n <ModalHeader>\n <Show\n when={palette === 'danger'}\n fallback={\n <ModalIcon palette=\"action\">\n <PromptIcon size={24} />\n </ModalIcon>\n }\n >\n <ModalIcon palette=\"danger\">\n <PromptIcon size={24} />\n </ModalIcon>\n </Show>\n <ModalHeading>{content?.heading}</ModalHeading>\n <ModalDescription>{content?.description}</ModalDescription>\n </ModalHeader>\n\n <div\n className={vstack({\n alignItems: 'flex-start',\n mt: '4',\n mb: '8',\n })}\n >\n <Field invalid={!isValid}>\n <Label htmlFor=\"confirm\" size=\"md\">\n Type\n <strong\n className={css({\n textTransform: 'uppercase',\n })}\n >\n {content?.key}\n </strong>\n to confirm\n </Label>\n <Input\n id=\"confirm\"\n name=\"confirm\"\n onChange={handleChange}\n type=\"text\"\n />\n </Field>\n </div>\n\n <div\n className={hstack({\n justifyContent: 'stretch',\n gap: '4',\n })}\n >\n <Button\n autoFocus\n className={css({\n w: '1/2',\n })}\n disabled={!isValid}\n name=\"confirm\"\n onClick={handleChoice}\n palette={palette}\n value=\"true\"\n >\n {content?.actionText}\n </Button>\n <Button\n className={css({\n w: '1/2',\n })}\n name=\"cancel\"\n onClick={handleChoice}\n usage=\"outlined\"\n value=\"false\"\n >\n {content?.cancelText}\n </Button>\n </div>\n </Modal>\n </Portal>\n </PromptModalContext.Provider>\n )\n}\n\nexport function usePromptModal(): PromptModalValue {\n const context = useContext(PromptModalContext)\n if (context === null) {\n throw new Error('usePromptModal must be used within a PromptModal Provider')\n }\n return context\n}\n"],"mappings":"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","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":[]}
@@ -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,25 @@
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
+ var _a;
7
+ (_a = modalRef.current) == null ? void 0 : _a.showModal();
8
+ }, []);
9
+ const close = useCallback(() => {
10
+ var _a;
11
+ (_a = modalRef.current) == null ? void 0 : _a.close();
12
+ }, []);
13
+ return useMemo(() => {
14
+ return {
15
+ modalRef,
16
+ show,
17
+ close
18
+ };
19
+ }, [modalRef, show, close]);
20
+ }
21
+
22
+ export {
23
+ useModal
24
+ };
25
+ //# sourceMappingURL=chunk-TZNYJ3G7.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;AAlBjC;AAmBI,mBAAS,YAAT,mBAAkB;AAAA,EACpB,GAAG,CAAC,CAAC;AAEL,QAAM,QAAQ,YAAY,MAAM;AAtBlC;AAuBI,mBAAS,YAAT,mBAAkB;AAAA,EACpB,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/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":[]}
@@ -0,0 +1,7 @@
1
+ import {
2
+ Modal
3
+ } from "../chunk-TPFNVGYA.js";
4
+ export {
5
+ Modal
6
+ };
7
+ //# sourceMappingURL=Modal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,7 @@
1
+ import {
2
+ ModalDescription
3
+ } from "../chunk-UPODPCRD.js";
4
+ export {
5
+ ModalDescription
6
+ };
7
+ //# sourceMappingURL=ModalDescription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,7 @@
1
+ import {
2
+ ModalHeader
3
+ } from "../chunk-2F5TB2EV.js";
4
+ export {
5
+ ModalHeader
6
+ };
7
+ //# sourceMappingURL=ModalHeader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}