@cerberus-design/react 0.10.4-next-4e536c0 → 0.10.4-next-10ee67c

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.
@@ -2485,9 +2485,16 @@ export { useFieldContext }
2485
2485
  export { useFieldContext as useFieldContext_alias_1 }
2486
2486
 
2487
2487
  /**
2488
- * Provides a hook for using a custom modal.
2488
+ * Provides a hook for using a custom modal via the native dialog element
2489
+ * methods.
2490
+ *
2491
+ * Cerberus modals use the native dialog element. This hook
2492
+ * does not control the modal via React state but rather by calling the
2493
+ * native dialog element's `showModal` and `close` methods.
2494
+ *
2489
2495
  * @memberof module:Modal
2490
- * @returns The modal hook.
2496
+ * @see https://cerberus.digitalu.design/react/modal
2497
+ * @description [Moz Dev Dialog Docs](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/showModal)
2491
2498
  */
2492
2499
  declare function useModal(): UseModalReturnValue;
2493
2500
  export { useModal }
@@ -2510,6 +2517,10 @@ declare interface UseModalReturnValue {
2510
2517
  * Closes the modal.
2511
2518
  */
2512
2519
  close: () => void;
2520
+ /**
2521
+ * Whether the modal is open based on the show and close methods.
2522
+ */
2523
+ isOpen: boolean;
2513
2524
  }
2514
2525
 
2515
2526
  /**
@@ -1,23 +1,27 @@
1
1
  // src/hooks/useModal.ts
2
- import { useCallback, useMemo, useRef } from "react";
2
+ import { useCallback, useMemo, useRef, useState } from "react";
3
3
  function useModal() {
4
4
  const modalRef = useRef(null);
5
+ const [isOpen, setIsOpen] = useState(false);
5
6
  const show = useCallback(() => {
6
7
  modalRef.current?.showModal();
8
+ setIsOpen(true);
7
9
  }, []);
8
10
  const close = useCallback(() => {
9
11
  modalRef.current?.close();
12
+ setIsOpen(false);
10
13
  }, []);
11
14
  return useMemo(() => {
12
15
  return {
13
16
  modalRef,
14
17
  show,
15
- close
18
+ close,
19
+ isOpen
16
20
  };
17
- }, [modalRef, show, close]);
21
+ }, [modalRef, show, close, isOpen]);
18
22
  }
19
23
 
20
24
  export {
21
25
  useModal
22
26
  };
23
- //# sourceMappingURL=chunk-OW62FLJ6.js.map
27
+ //# sourceMappingURL=chunk-7T3JIGM7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useModal.ts"],"sourcesContent":["'use client'\n\nimport { useCallback, useMemo, useRef, useState, type RefObject } from 'react'\n\n/**\n * This module provides a hook for using a custom modal.\n * @module\n */\n\ninterface UseModalReturnValue {\n /**\n * The ref for the modal.\n */\n modalRef: RefObject<HTMLDialogElement>\n /**\n * Shows the modal.\n */\n show: () => void\n /**\n * Closes the modal.\n */\n close: () => void\n /**\n * Whether the modal is open based on the show and close methods.\n */\n isOpen: boolean\n}\n\n/**\n * Provides a hook for using a custom modal via the native dialog element\n * methods.\n *\n * Cerberus modals use the native dialog element. This hook\n * does not control the modal via React state but rather by calling the\n * native dialog element's `showModal` and `close` methods.\n *\n * @memberof module:Modal\n * @see https://cerberus.digitalu.design/react/modal\n * @description [Moz Dev Dialog Docs](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/showModal)\n */\nexport function useModal(): UseModalReturnValue {\n const modalRef = useRef<HTMLDialogElement | null>(null)\n const [isOpen, setIsOpen] = useState<boolean>(false)\n\n const show = useCallback(() => {\n modalRef.current?.showModal()\n setIsOpen(true)\n }, [])\n\n const close = useCallback(() => {\n modalRef.current?.close()\n setIsOpen(false)\n }, [])\n\n return useMemo(() => {\n return {\n modalRef,\n show,\n close,\n isOpen,\n }\n }, [modalRef, show, close, isOpen])\n}\n"],"mappings":";AAEA,SAAS,aAAa,SAAS,QAAQ,gBAAgC;AAsChE,SAAS,WAAgC;AAC9C,QAAM,WAAW,OAAiC,IAAI;AACtD,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAkB,KAAK;AAEnD,QAAM,OAAO,YAAY,MAAM;AAC7B,aAAS,SAAS,UAAU;AAC5B,cAAU,IAAI;AAAA,EAChB,GAAG,CAAC,CAAC;AAEL,QAAM,QAAQ,YAAY,MAAM;AAC9B,aAAS,SAAS,MAAM;AACxB,cAAU,KAAK;AAAA,EACjB,GAAG,CAAC,CAAC;AAEL,SAAO,QAAQ,MAAM;AACnB,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,UAAU,MAAM,OAAO,MAAM,CAAC;AACpC;","names":[]}
@@ -30,7 +30,7 @@ import {
30
30
  } from "./chunk-NBG2OSYI.js";
31
31
  import {
32
32
  useModal
33
- } from "./chunk-OW62FLJ6.js";
33
+ } from "./chunk-7T3JIGM7.js";
34
34
 
35
35
  // src/context/confirm-modal.tsx
36
36
  import {
@@ -176,4 +176,4 @@ export {
176
176
  ConfirmModal,
177
177
  useConfirmModal
178
178
  };
179
- //# sourceMappingURL=chunk-BGBCJ2W2.js.map
179
+ //# sourceMappingURL=chunk-BDNY6R3H.js.map
@@ -39,7 +39,7 @@ import {
39
39
  } from "./chunk-NBG2OSYI.js";
40
40
  import {
41
41
  useModal
42
- } from "./chunk-OW62FLJ6.js";
42
+ } from "./chunk-7T3JIGM7.js";
43
43
 
44
44
  // src/context/prompt-modal.tsx
45
45
  import {
@@ -229,4 +229,4 @@ export {
229
229
  PromptModal,
230
230
  usePromptModal
231
231
  };
232
- //# sourceMappingURL=chunk-77LI5SP3.js.map
232
+ //# sourceMappingURL=chunk-ZBRG3FQV.js.map
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  ConfirmModal,
4
4
  useConfirmModal
5
- } from "../chunk-BGBCJ2W2.js";
5
+ } from "../chunk-BDNY6R3H.js";
6
6
  import "../chunk-GLY7GU5S.js";
7
7
  import "../chunk-BE4EOU2P.js";
8
8
  import "../chunk-Q7BRMIBR.js";
@@ -15,7 +15,7 @@ import "../chunk-JIZQFTW6.js";
15
15
  import "../chunk-NBG2OSYI.js";
16
16
  import "../chunk-BDCFYW34.js";
17
17
  import "../chunk-CP7OUC2Q.js";
18
- import "../chunk-OW62FLJ6.js";
18
+ import "../chunk-7T3JIGM7.js";
19
19
  export {
20
20
  ConfirmModal,
21
21
  useConfirmModal
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  PromptModal,
4
4
  usePromptModal
5
- } from "../chunk-77LI5SP3.js";
5
+ } from "../chunk-ZBRG3FQV.js";
6
6
  import "../chunk-GLY7GU5S.js";
7
7
  import "../chunk-BE4EOU2P.js";
8
8
  import "../chunk-Q7BRMIBR.js";
@@ -18,7 +18,7 @@ import "../chunk-JIZQFTW6.js";
18
18
  import "../chunk-NBG2OSYI.js";
19
19
  import "../chunk-BDCFYW34.js";
20
20
  import "../chunk-CP7OUC2Q.js";
21
- import "../chunk-OW62FLJ6.js";
21
+ import "../chunk-7T3JIGM7.js";
22
22
  export {
23
23
  PromptModal,
24
24
  usePromptModal
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  useModal
4
- } from "../chunk-OW62FLJ6.js";
4
+ } from "../chunk-7T3JIGM7.js";
5
5
  export {
6
6
  useModal
7
7
  };
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  PromptModal,
7
7
  usePromptModal
8
- } from "./chunk-77LI5SP3.js";
8
+ } from "./chunk-ZBRG3FQV.js";
9
9
  import {
10
10
  ThemeProvider,
11
11
  useThemeContext
@@ -25,7 +25,7 @@ import {
25
25
  import {
26
26
  ConfirmModal,
27
27
  useConfirmModal
28
- } from "./chunk-BGBCJ2W2.js";
28
+ } from "./chunk-BDNY6R3H.js";
29
29
  import {
30
30
  Spinner
31
31
  } from "./chunk-7SYJFI5E.js";
@@ -187,7 +187,7 @@ import "./chunk-BDCFYW34.js";
187
187
  import "./chunk-CP7OUC2Q.js";
188
188
  import {
189
189
  useModal
190
- } from "./chunk-OW62FLJ6.js";
190
+ } from "./chunk-7T3JIGM7.js";
191
191
 
192
192
  // src/index.ts
193
193
  export * from "@dnd-kit/core";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cerberus-design/react",
3
- "version": "0.10.4-next-4e536c0",
3
+ "version": "0.10.4-next-10ee67c",
4
4
  "description": "The Cerberus Design React component library.",
5
5
  "browserslist": "> 0.25%, not dead",
6
6
  "sideEffects": false,
@@ -26,7 +26,7 @@
26
26
  "react-dom": "^18",
27
27
  "tsup": "^8.1.0",
28
28
  "@cerberus-design/configs": "0.0.0",
29
- "@cerberus-design/styled-system": "0.10.4-next-4e536c0"
29
+ "@cerberus-design/styled-system": "0.10.4-next-10ee67c"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
@@ -1,6 +1,6 @@
1
1
  'use client'
2
2
 
3
- import { useCallback, useMemo, useRef, type RefObject } from 'react'
3
+ import { useCallback, useMemo, useRef, useState, type RefObject } from 'react'
4
4
 
5
5
  /**
6
6
  * This module provides a hook for using a custom modal.
@@ -20,22 +20,36 @@ interface UseModalReturnValue {
20
20
  * Closes the modal.
21
21
  */
22
22
  close: () => void
23
+ /**
24
+ * Whether the modal is open based on the show and close methods.
25
+ */
26
+ isOpen: boolean
23
27
  }
24
28
 
25
29
  /**
26
- * Provides a hook for using a custom modal.
30
+ * Provides a hook for using a custom modal via the native dialog element
31
+ * methods.
32
+ *
33
+ * Cerberus modals use the native dialog element. This hook
34
+ * does not control the modal via React state but rather by calling the
35
+ * native dialog element's `showModal` and `close` methods.
36
+ *
27
37
  * @memberof module:Modal
28
- * @returns The modal hook.
38
+ * @see https://cerberus.digitalu.design/react/modal
39
+ * @description [Moz Dev Dialog Docs](https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/showModal)
29
40
  */
30
41
  export function useModal(): UseModalReturnValue {
31
42
  const modalRef = useRef<HTMLDialogElement | null>(null)
43
+ const [isOpen, setIsOpen] = useState<boolean>(false)
32
44
 
33
45
  const show = useCallback(() => {
34
46
  modalRef.current?.showModal()
47
+ setIsOpen(true)
35
48
  }, [])
36
49
 
37
50
  const close = useCallback(() => {
38
51
  modalRef.current?.close()
52
+ setIsOpen(false)
39
53
  }, [])
40
54
 
41
55
  return useMemo(() => {
@@ -43,6 +57,7 @@ export function useModal(): UseModalReturnValue {
43
57
  modalRef,
44
58
  show,
45
59
  close,
60
+ isOpen,
46
61
  }
47
- }, [modalRef, show, close])
62
+ }, [modalRef, show, close, isOpen])
48
63
  }
@@ -1 +0,0 @@
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 /**\n * The ref for the modal.\n */\n modalRef: RefObject<HTMLDialogElement>\n /**\n * Shows the modal.\n */\n show: () => void\n /**\n * Closes the modal.\n */\n close: () => void\n}\n\n/**\n * Provides a hook for using a custom modal.\n * @memberof module:Modal\n * @returns The modal hook.\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;AA2BtD,SAAS,WAAgC;AAC9C,QAAM,WAAW,OAAiC,IAAI;AAEtD,QAAM,OAAO,YAAY,MAAM;AAC7B,aAAS,SAAS,UAAU;AAAA,EAC9B,GAAG,CAAC,CAAC;AAEL,QAAM,QAAQ,YAAY,MAAM;AAC9B,aAAS,SAAS,MAAM;AAAA,EAC1B,GAAG,CAAC,CAAC;AAEL,SAAO,QAAQ,MAAM;AACnB,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,GAAG,CAAC,UAAU,MAAM,KAAK,CAAC;AAC5B;","names":[]}