braid-design-system
Version:
Themeable design system for the SEEK Group
33 lines (32 loc) • 850 B
JavaScript
const react = require("react");
const lib_hooks_useFallbackId_cjs = require("../../hooks/useFallbackId.cjs");
const useDisclosure = ({
id,
expanded: expandedProp,
onToggle
}) => {
const [expandedFallback, setExpandedFallback] = react.useState(false);
const expanded = expandedProp ?? expandedFallback;
const resolvedId = lib_hooks_useFallbackId_cjs.useFallbackId(id);
return {
buttonProps: {
"aria-controls": resolvedId,
"aria-expanded": expanded,
onClick: () => {
const newValue = !expanded;
if (expandedProp === void 0) {
setExpandedFallback(newValue);
}
if (typeof onToggle === "function") {
onToggle(newValue);
}
}
},
contentProps: {
id: resolvedId
},
expanded
};
};
exports.useDisclosure = useDisclosure;
;