@yamada-ui/use-disclosure
Advanced tools
Comparing version 1.1.1 to 1.1.2-dev-20241203094339
interface UseDisclosureProps<Y extends (...args: any[]) => Promise<void> | void = () => void, M extends (...args: any[]) => Promise<void> | void = () => void> { | ||
defaultIsOpen?: boolean; | ||
/** | ||
* @deprecated Use `open` instead. | ||
*/ | ||
isOpen?: boolean; | ||
open?: boolean; | ||
timing?: "after" | "before"; | ||
@@ -15,3 +19,7 @@ onClose?: M; | ||
declare const useDisclosure: <Y extends (...args: any[]) => Promise<void> | void = () => void, M extends (...args: any[]) => Promise<void> | void = () => void>(props?: UseDisclosureProps<Y, M>) => { | ||
/** | ||
* @deprecated Use `open` instead. | ||
*/ | ||
isOpen: boolean; | ||
open: boolean; | ||
onClose: M; | ||
@@ -33,3 +41,7 @@ onOpen: Y; | ||
declare const usePromiseDisclosure: <Y extends (...args: any[]) => Promise<void> | void = () => void, M extends (...args: any[]) => Promise<void> | void = () => void>({ disableCloseOnSuccess, error, ...rest }?: UsePromiseDisclosureProps<Y, M>) => { | ||
/** | ||
* @deprecated Use `open` instead. | ||
*/ | ||
isOpen: boolean; | ||
open: boolean; | ||
onClose: M; | ||
@@ -44,8 +56,12 @@ onOpen: (...args: Parameters<Y>) => Promise<void>; | ||
enabled?: boolean; | ||
/** | ||
* @deprecated Use `selected` instead. | ||
*/ | ||
isSelected?: boolean; | ||
mode?: LazyMode; | ||
selected?: boolean; | ||
wasSelected?: boolean; | ||
} | ||
declare const useLazyDisclosure: ({ enabled, isSelected, mode, wasSelected, }: UseLazyDisclosureProps) => boolean; | ||
declare const useLazyDisclosure: ({ enabled, isSelected, mode, selected, wasSelected, }: UseLazyDisclosureProps) => boolean; | ||
export { type LazyMode, type UseDisclosureProps, type UseDisclosureReturn, type UseLazyDisclosureProps, type UsePromiseDisclosureProps, type UsePromiseDisclosureReturn, useDisclosure, useLazyDisclosure, usePromiseDisclosure }; |
@@ -32,18 +32,19 @@ "use client" | ||
var useDisclosure = (props = {}) => { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
const [defaultIsOpen, setIsOpen] = (0, import_react.useState)( | ||
(_a = props.defaultIsOpen) != null ? _a : false | ||
); | ||
const timingRef = (0, import_react.useRef)((_b = props.timing) != null ? _b : "after"); | ||
const openProps = (_b = props.open) != null ? _b : props.isOpen; | ||
const timingRef = (0, import_react.useRef)((_c = props.timing) != null ? _c : "after"); | ||
const handleOpen = (0, import_utils.useCallbackRef)(props.onOpen); | ||
const handleClose = (0, import_utils.useCallbackRef)(props.onClose); | ||
const isControlled = props.isOpen !== void 0; | ||
const isOpen = props.isOpen !== void 0 ? props.isOpen : defaultIsOpen; | ||
const controlled = openProps !== void 0; | ||
const open = openProps !== void 0 ? openProps : defaultIsOpen; | ||
const onOpen = (0, import_react.useCallback)( | ||
async (...args) => { | ||
if (timingRef.current === "before") await handleOpen(...args); | ||
if (!isControlled) setIsOpen(true); | ||
if (!controlled) setIsOpen(true); | ||
if (timingRef.current === "after") await handleOpen(...args); | ||
}, | ||
[isControlled, handleOpen, timingRef] | ||
[controlled, handleOpen, timingRef] | ||
); | ||
@@ -53,12 +54,21 @@ const onClose = (0, import_react.useCallback)( | ||
if (timingRef.current === "before") await handleClose(...args); | ||
if (!isControlled) setIsOpen(false); | ||
if (!controlled) setIsOpen(false); | ||
if (timingRef.current === "after") await handleClose(...args); | ||
}, | ||
[isControlled, handleClose, timingRef] | ||
[controlled, handleClose, timingRef] | ||
); | ||
const onToggle = (0, import_react.useCallback)( | ||
async (...args) => !isOpen ? onOpen(...args) : onClose(...args), | ||
[isOpen, onOpen, onClose] | ||
async (...args) => !open ? onOpen(...args) : onClose(...args), | ||
[open, onOpen, onClose] | ||
); | ||
return { isOpen, onClose, onOpen, onToggle }; | ||
return { | ||
/** | ||
* @deprecated Use `open` instead. | ||
*/ | ||
isOpen: open, | ||
open, | ||
onClose, | ||
onOpen, | ||
onToggle | ||
}; | ||
}; | ||
@@ -70,4 +80,5 @@ var usePromiseDisclosure = ({ | ||
} = {}) => { | ||
const { | ||
let { | ||
isOpen, | ||
open, | ||
onClose: onInternalClose, | ||
@@ -77,2 +88,3 @@ onOpen: onInternalOpen, | ||
} = useDisclosure(rest); | ||
open = isOpen; | ||
const rejectRef = (0, import_react.useRef)(void 0); | ||
@@ -104,3 +116,7 @@ const resolveRef = (0, import_react.useRef)(import_utils.noop); | ||
return { | ||
isOpen, | ||
/** | ||
* @deprecated Use `open` instead. | ||
*/ | ||
isOpen: open, | ||
open, | ||
onClose, | ||
@@ -116,6 +132,8 @@ onOpen, | ||
mode = "unmount", | ||
selected, | ||
wasSelected | ||
}) => { | ||
selected != null ? selected : selected = isSelected; | ||
if (!enabled) return true; | ||
if (isSelected) return true; | ||
if (selected) return true; | ||
if (mode === "keepMounted" && wasSelected) return true; | ||
@@ -122,0 +140,0 @@ return false; |
{ | ||
"name": "@yamada-ui/use-disclosure", | ||
"version": "1.1.1", | ||
"version": "1.1.2-dev-20241203094339", | ||
"description": "Yamada UI useDisclosure custom hook", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30731
317
1