UNPKG

@react-md/menu

Version:

Create menus that auto-position themselves within the viewport and adhere to the accessibility guidelines

66 lines 1.85 kB
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); }; import { jsx as _jsx } from "react/jsx-runtime"; import { createContext, useContext, useMemo } from "react"; /** * @internal * @remarks \@since 5.0.0 */ var context = 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 */ export function useMenuVisibility() { return useContext(context); } /** * @internal * @remarks \@since 5.0.0 */ export function MenuVisibilityProvider(_a) { var visible = _a.visible, setVisible = _a.setVisible, children = _a.children; var value = useMemo(function () { return ({ visible: visible, setVisible: setVisible, }); }, [visible, setVisible]); return _jsx(Provider, __assign({ value: value }, { children: children })); } //# sourceMappingURL=MenuVisibilityProvider.js.map