package.dist.cjs.hooks.use-disclosure.cjs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of react Show documentation
Show all versions of react Show documentation
Responsive and accessible React UI components built with React and Emotion
The newest version!
"use strict";
"use client";
'use strict';
var React = require('react');
var useCallbackRef = require('./use-callback-ref.cjs');
function useDisclosure(props = {}) {
const { onClose: onCloseProp, onOpen: onOpenProp, open: openProp } = props;
const handleOpen = useCallbackRef.useCallbackRef(onOpenProp);
const handleClose = useCallbackRef.useCallbackRef(onCloseProp);
const [openState, setopen] = React.useState(props.defaultOpen || false);
const open = openProp !== void 0 ? openProp : openState;
const isControlled = openProp !== void 0;
const onClose = React.useCallback(() => {
if (!isControlled) {
setopen(false);
}
handleClose?.();
}, [isControlled, handleClose]);
const onOpen = React.useCallback(() => {
if (!isControlled) {
setopen(true);
}
handleOpen?.();
}, [isControlled, handleOpen]);
const onToggle = React.useCallback(() => {
if (open) {
onClose();
} else {
onOpen();
}
}, [open, onOpen, onClose]);
return {
open,
onOpen,
onClose,
onToggle
};
}
exports.useDisclosure = useDisclosure;
© 2015 - 2025 Weber Informatics LLC | Privacy Policy