All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.cjs.hooks.use-disclosure.cjs Maven / Gradle / Ivy

Go to download

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