@react-md/menu
Version:
Create menus that auto-position themselves within the viewport and adhere to the accessibility guidelines
71 lines • 2.12 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MenuVisibilityProvider = exports.useMenuVisibility = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
/**
* @internal
* @remarks \@since 5.0.0
*/
var context = (0, react_1.createContext)({
visible: false,
setVisible: function () {
throw new Error('"MenuVisibilityProvider" must be a parent component');
},
});
context.displayName = "MenuVisibility";
/**
* @internal
* @remarks \@since 5.0.0
*/
var Provider = context.Provider;
/**
* This hook allows you control the visibility of a parent menu. The main
* use-case for this hook is adding a custom sheet header/footer.
*
* @example
* Simple Example
* ```tsx
* function SheetFooter(): ReactElement {
* const { setVisible } = useMenuVisibility();
*
* return (
* <DialogFooter>
* <Button onClick={() => setVisible(false)}>Cancel</Button>
* </DialogFooter>
* );
* }
* ```
*
* @returns the {@link MenuVisibilityContext}
* @remarks \@since 5.0.0
*/
function useMenuVisibility() {
return (0, react_1.useContext)(context);
}
exports.useMenuVisibility = useMenuVisibility;
/**
* @internal
* @remarks \@since 5.0.0
*/
function MenuVisibilityProvider(_a) {
var visible = _a.visible, setVisible = _a.setVisible, children = _a.children;
var value = (0, react_1.useMemo)(function () { return ({
visible: visible,
setVisible: setVisible,
}); }, [visible, setVisible]);
return (0, jsx_runtime_1.jsx)(Provider, __assign({ value: value }, { children: children }));
}
exports.MenuVisibilityProvider = MenuVisibilityProvider;
//# sourceMappingURL=MenuVisibilityProvider.js.map