@gateweb/react-utils 1.15.0 → 1.17.0

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.
@@ -0,0 +1,24 @@
1
+ 'use client';
2
+ import { useState, useCallback } from 'react';
3
+
4
+ /**
5
+ * A small hook to control open/close state.
6
+ *
7
+ * Supports an optional controlled pattern by passing `isOpen` and `onChange`.
8
+ *
9
+ * @example
10
+ * const { isOpen, open, close, toggle } = useDisclosure();
11
+ */ function useDisclosure(initialState = false) {
12
+ const [isOpen, setIsOpen] = useState(initialState);
13
+ const open = useCallback(()=>setIsOpen(true), []);
14
+ const close = useCallback(()=>setIsOpen(false), []);
15
+ const toggle = useCallback(()=>setIsOpen((prev)=>!prev), []);
16
+ return {
17
+ isOpen,
18
+ open,
19
+ close,
20
+ toggle
21
+ };
22
+ }
23
+
24
+ export { useDisclosure as u };