material-ui-popup-state
Version:
easiest way to create menus, popovers, and poppers with material-ui
2 lines (1 loc) • 27.5 kB
Source Map (JSON)
{"version":3,"file":"hooks.mjs","names":["useCallback","useState","useRef","useEffect","React","useEvent","printedWarnings","warn","key","message","console","error","initCoreState","isOpen","setAnchorElUsed","anchorEl","undefined","anchorPosition","hovered","focused","_openEventType","_childPopupState","_deferNextOpen","_deferNextClose","_react","defaultPopupId","useId","usePopupState","parentPopupState","popupId","variant","disableAutoFocus","isMounted","current","state","_setState","setState","setAnchorEl","toggle","eventOrAnchorEl","close","open","event","Element","element","currentTarget","type","clientX","clientY","left","top","doOpen","setTimeout","_setChildPopupState","popupState","newState","doClose","setOpen","nextOpen","onMouseLeave","relatedTarget","isElementInPopup","onBlur","Boolean","anchorRef","controlAriaProps","bindTrigger","onClick","onTouchStart","bindContextMenu","onContextMenu","e","preventDefault","bindToggle","bindHover","onMouseOver","bindFocus","onFocus","bindDoubleClick","onDoubleClick","bindPopover","usePopoverPosition","id","anchorReference","onClose","disableEnforceFocus","disableRestoreFocus","bindMenu","autoFocus","disableAutoFocusItem","bindPopper","bindDialog","getPopup","rootNode","getRootNode","document","getElementById","isAncestor","parent","child","parentElement"],"sources":["src/hooks.ts"],"sourcesContent":["/* eslint-env browser */\n\nimport {\n type SyntheticEvent,\n type MouseEvent,\n type TouchEvent,\n type FocusEvent,\n useCallback,\n useState,\n useRef,\n useEffect,\n} from 'react'\nimport * as React from 'react'\nimport { type PopoverPosition, type PopoverReference } from '@mui/material'\nimport { useEvent } from './useEvent'\n\nconst printedWarnings: Record<string, boolean> = {}\n\nfunction warn(key: string, message: string) {\n if (printedWarnings[key]) return\n printedWarnings[key] = true\n console.error('[material-ui-popup-state] WARNING', message)\n}\n\nexport type Variant = 'popover' | 'popper' | 'dialog'\n\nexport type PopupState = {\n open: (eventOrAnchorEl?: SyntheticEvent | Element | null) => void\n close: (eventOrAnchorEl?: SyntheticEvent | Element | null) => void\n toggle: (eventOrAnchorEl?: SyntheticEvent | Element | null) => void\n onBlur: (event: FocusEvent) => void\n onMouseLeave: (event: MouseEvent) => void\n setOpen: (\n open: boolean,\n eventOrAnchorEl?: SyntheticEvent | Element | null\n ) => void\n isOpen: boolean\n anchorEl: Element | undefined\n anchorPosition: PopoverPosition | undefined\n setAnchorEl: (anchorEl: Element | null | undefined) => any\n setAnchorElUsed: boolean\n disableAutoFocus: boolean\n popupId: string | undefined\n variant: Variant\n _openEventType: string | null | undefined\n _childPopupState: PopupState | null | undefined\n _setChildPopupState: (popupState: PopupState | null | undefined) => void\n}\n\nexport type CoreState = {\n isOpen: boolean\n setAnchorElUsed: boolean\n anchorEl: Element | undefined\n anchorPosition: PopoverPosition | undefined\n hovered: boolean\n focused: boolean\n _openEventType: string | null | undefined\n _childPopupState: PopupState | null | undefined\n _deferNextOpen: boolean\n _deferNextClose: boolean\n}\n\nexport const initCoreState: CoreState = {\n isOpen: false,\n setAnchorElUsed: false,\n anchorEl: undefined,\n anchorPosition: undefined,\n hovered: false,\n focused: false,\n _openEventType: null,\n _childPopupState: null,\n _deferNextOpen: false,\n _deferNextClose: false,\n}\n\n// https://github.com/jcoreio/material-ui-popup-state/issues/138\n// Webpack prod build doesn't like it if we refer to React.useId conditionally,\n// but aliasing to a variable like this works\nconst _react = React\nconst defaultPopupId =\n 'useId' in _react ?\n () => _react.useId()\n // istanbul ignore next\n : () => undefined\n\nexport function usePopupState({\n parentPopupState,\n popupId = defaultPopupId(),\n variant,\n disableAutoFocus,\n}: {\n parentPopupState?: PopupState | null | undefined\n popupId?: string | null\n variant: Variant\n disableAutoFocus?: boolean | null | undefined\n}): PopupState {\n const isMounted = useRef(true)\n\n useEffect((): (() => void) => {\n isMounted.current = true\n return () => {\n isMounted.current = false\n }\n }, [])\n\n const [state, _setState] = useState(initCoreState)\n\n const setState = useCallback(\n (state: CoreState | ((prevState: CoreState) => CoreState)) => {\n if (isMounted.current) _setState(state)\n },\n []\n )\n\n const setAnchorEl = useCallback(\n (anchorEl: Element | null | undefined) =>\n setState((state) => ({\n ...state,\n setAnchorElUsed: true,\n anchorEl: anchorEl ?? undefined,\n })),\n []\n )\n\n const toggle = useEvent(\n (eventOrAnchorEl?: SyntheticEvent | Element | null) => {\n if (state.isOpen) close(eventOrAnchorEl)\n else open(eventOrAnchorEl)\n return state\n }\n )\n\n const open = useEvent((eventOrAnchorEl?: SyntheticEvent | Element | null) => {\n const event =\n eventOrAnchorEl instanceof Element ? undefined : eventOrAnchorEl\n const element =\n eventOrAnchorEl instanceof Element ? eventOrAnchorEl\n : eventOrAnchorEl?.currentTarget instanceof Element ?\n eventOrAnchorEl.currentTarget\n : undefined\n\n if (event?.type === 'touchstart') {\n setState((state) => ({ ...state, _deferNextOpen: true }))\n return\n }\n\n const clientX = (event as MouseEvent | undefined)?.clientX\n const clientY = (event as MouseEvent | undefined)?.clientY\n const anchorPosition =\n typeof clientX === 'number' && typeof clientY === 'number' ?\n { left: clientX, top: clientY }\n : undefined\n\n const doOpen = (state: CoreState): CoreState => {\n if (!eventOrAnchorEl && !state.setAnchorElUsed && variant !== 'dialog') {\n warn(\n 'missingEventOrAnchorEl',\n 'eventOrAnchorEl should be defined if setAnchorEl is not used'\n )\n }\n\n if (parentPopupState) {\n if (!parentPopupState.isOpen) return state\n setTimeout(() => parentPopupState._setChildPopupState(popupState))\n }\n\n const newState: CoreState = {\n ...state,\n isOpen: true,\n anchorPosition,\n hovered: event?.type === 'mouseover' || state.hovered,\n focused: event?.type === 'focus' || state.focused,\n _openEventType: event?.type,\n }\n\n if (!state.setAnchorElUsed) {\n if (event?.currentTarget) {\n newState.anchorEl = event.currentTarget as any\n } else if (element) {\n newState.anchorEl = element\n }\n }\n\n return newState\n }\n\n setState((state: CoreState): CoreState => {\n if (state._deferNextOpen) {\n setTimeout(() => setState(doOpen), 0)\n return { ...state, _deferNextOpen: false }\n } else {\n return doOpen(state)\n }\n })\n })\n\n const doClose = (state: CoreState): CoreState => {\n const { _childPopupState } = state\n setTimeout(() => {\n _childPopupState?.close()\n parentPopupState?._setChildPopupState(null)\n })\n return { ...state, isOpen: false, hovered: false, focused: false }\n }\n\n const close = useEvent(\n (eventOrAnchorEl?: SyntheticEvent | Element | null) => {\n const event =\n eventOrAnchorEl instanceof Element ? undefined : eventOrAnchorEl\n\n if (event?.type === 'touchstart') {\n setState((state) => ({ ...state, _deferNextClose: true }))\n return\n }\n\n setState((state: CoreState): CoreState => {\n if (state._deferNextClose) {\n setTimeout(() => setState(doClose), 0)\n return { ...state, _deferNextClose: false }\n } else {\n return doClose(state)\n }\n })\n }\n )\n\n const setOpen = useCallback(\n (\n nextOpen: boolean,\n eventOrAnchorEl?: SyntheticEvent<any> | Element | null\n ) => {\n if (nextOpen) {\n open(eventOrAnchorEl)\n } else {\n close(eventOrAnchorEl)\n }\n },\n []\n )\n\n const onMouseLeave = useEvent((event: MouseEvent) => {\n const { relatedTarget } = event\n setState((state: CoreState): CoreState => {\n if (\n state.hovered &&\n !(\n relatedTarget instanceof Element &&\n isElementInPopup(relatedTarget, popupState)\n )\n ) {\n if (state.focused) {\n return { ...state, hovered: false }\n } else {\n return doClose(state)\n }\n }\n return state\n })\n })\n\n const onBlur = useEvent((event?: FocusEvent) => {\n if (!event) return\n const { relatedTarget } = event\n setState((state: CoreState): CoreState => {\n if (\n state.focused &&\n !(\n relatedTarget instanceof Element &&\n isElementInPopup(relatedTarget, popupState)\n )\n ) {\n if (state.hovered) {\n return { ...state, focused: false }\n } else {\n return doClose(state)\n }\n }\n return state\n })\n })\n\n const _setChildPopupState = useCallback(\n (_childPopupState: PopupState | null | undefined) =>\n setState((state) => ({ ...state, _childPopupState })),\n []\n )\n\n const popupState: PopupState = {\n ...state,\n setAnchorEl,\n popupId: popupId ?? undefined,\n variant,\n open,\n close,\n toggle,\n setOpen,\n onBlur,\n onMouseLeave,\n disableAutoFocus:\n disableAutoFocus ?? Boolean(state.hovered || state.focused),\n _setChildPopupState,\n }\n\n return popupState\n}\n\n/**\n * Creates a ref that sets the anchorEl for the popup.\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\nexport function anchorRef({\n setAnchorEl,\n}: PopupState): (el: Element | null | undefined) => any {\n return setAnchorEl\n}\n\ntype ControlAriaProps = {\n 'aria-controls'?: string\n 'aria-describedby'?: string\n 'aria-haspopup'?: true\n}\n\nfunction controlAriaProps({\n isOpen,\n popupId,\n variant,\n}: PopupState): ControlAriaProps {\n return {\n ...(variant === 'popover' ?\n {\n 'aria-haspopup': true,\n 'aria-controls': isOpen ? popupId : undefined,\n }\n : variant === 'popper' ?\n { 'aria-describedby': isOpen ? popupId : undefined }\n : undefined),\n }\n}\n\n/**\n * Creates props for a component that opens the popup when clicked.\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\nexport function bindTrigger(popupState: PopupState): ControlAriaProps & {\n onClick: (event: MouseEvent) => void\n onTouchStart: (event: TouchEvent) => void\n} {\n return {\n ...controlAriaProps(popupState),\n onClick: popupState.open,\n onTouchStart: popupState.open,\n }\n}\n\n/**\n * Creates props for a component that opens the popup on its contextmenu event (right click).\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\nexport function bindContextMenu(popupState: PopupState): ControlAriaProps & {\n onContextMenu: (event: MouseEvent) => void\n} {\n return {\n ...controlAriaProps(popupState),\n onContextMenu: (e: MouseEvent) => {\n e.preventDefault()\n popupState.open(e)\n },\n }\n}\n\n/**\n * Creates props for a component that toggles the popup when clicked.\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\nexport function bindToggle(popupState: PopupState): ControlAriaProps & {\n onClick: (event: MouseEvent) => void\n onTouchStart: (event: TouchEvent) => void\n} {\n return {\n ...controlAriaProps(popupState),\n onClick: popupState.toggle,\n onTouchStart: popupState.toggle,\n }\n}\n\n/**\n * Creates props for a component that opens the popup while hovered.\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\nexport function bindHover(popupState: PopupState): ControlAriaProps & {\n onTouchStart: (event: TouchEvent) => any\n onMouseOver: (event: MouseEvent) => any\n onMouseLeave: (event: MouseEvent) => any\n} {\n const { open, onMouseLeave } = popupState\n return {\n ...controlAriaProps(popupState),\n onTouchStart: open,\n onMouseOver: open,\n onMouseLeave,\n }\n}\n\n/**\n * Creates props for a component that opens the popup while focused.\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\nexport function bindFocus(popupState: PopupState): ControlAriaProps & {\n onFocus: (event: FocusEvent) => any\n onBlur: (event: FocusEvent) => any\n} {\n const { open, onBlur } = popupState\n return {\n ...controlAriaProps(popupState),\n onFocus: open,\n onBlur,\n }\n}\n\n/**\n * Creates props for a component that opens the popup while double click.\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\nexport function bindDoubleClick({\n isOpen,\n open,\n popupId,\n variant,\n}: PopupState): {\n 'aria-controls'?: string\n 'aria-describedby'?: string\n 'aria-haspopup'?: true\n onDoubleClick: (event: MouseEvent) => any\n} {\n return {\n // $FlowFixMe\n [variant === 'popover' ? 'aria-controls' : 'aria-describedby']:\n isOpen ? popupId : null,\n 'aria-haspopup': variant === 'popover' ? true : undefined,\n onDoubleClick: open,\n }\n}\n\n/**\n * Creates props for a `Popover` component.\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\nexport function bindPopover({\n isOpen,\n anchorEl,\n anchorPosition,\n close,\n popupId,\n onMouseLeave,\n disableAutoFocus,\n _openEventType,\n}: PopupState): {\n id?: string\n anchorEl?: Element | null\n anchorPosition?: PopoverPosition\n anchorReference: PopoverReference\n open: boolean\n onClose: () => void\n onMouseLeave: (event: MouseEvent) => void\n disableAutoFocus?: boolean\n disableEnforceFocus?: boolean\n disableRestoreFocus?: boolean\n} {\n const usePopoverPosition = _openEventType === 'contextmenu'\n return {\n id: popupId,\n anchorEl,\n anchorPosition,\n anchorReference: usePopoverPosition ? 'anchorPosition' : 'anchorEl',\n open: isOpen,\n onClose: close,\n onMouseLeave,\n ...(disableAutoFocus && {\n disableAutoFocus: true,\n disableEnforceFocus: true,\n disableRestoreFocus: true,\n }),\n }\n}\n\n/**\n * Creates props for a `Menu` component.\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\n\n/**\n * Creates props for a `Popover` component.\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\nexport function bindMenu({\n isOpen,\n anchorEl,\n anchorPosition,\n close,\n popupId,\n onMouseLeave,\n disableAutoFocus,\n _openEventType,\n}: PopupState): {\n id?: string\n anchorEl?: Element | null\n anchorPosition?: PopoverPosition\n anchorReference: PopoverReference\n open: boolean\n onClose: () => void\n onMouseLeave: (event: MouseEvent) => void\n autoFocus?: boolean\n disableAutoFocusItem?: boolean\n disableAutoFocus?: boolean\n disableEnforceFocus?: boolean\n disableRestoreFocus?: boolean\n} {\n const usePopoverPosition = _openEventType === 'contextmenu'\n return {\n id: popupId,\n anchorEl,\n anchorPosition,\n anchorReference: usePopoverPosition ? 'anchorPosition' : 'anchorEl',\n open: isOpen,\n onClose: close,\n onMouseLeave,\n ...(disableAutoFocus && {\n autoFocus: false,\n disableAutoFocusItem: true,\n disableAutoFocus: true,\n disableEnforceFocus: true,\n disableRestoreFocus: true,\n }),\n }\n}\n/**\n * Creates props for a `Popper` component.\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\nexport function bindPopper({\n isOpen,\n anchorEl,\n popupId,\n onMouseLeave,\n}: PopupState): {\n id?: string\n anchorEl?: Element | null\n open: boolean\n onMouseLeave: (event: MouseEvent) => void\n} {\n return {\n id: popupId,\n anchorEl,\n open: isOpen,\n onMouseLeave,\n }\n}\n\n/**\n * Creates props for a `Dialog` component.\n *\n * @param {object} popupState the argument passed to the child function of\n * `PopupState`\n */\nexport function bindDialog({ isOpen, close }: PopupState): {\n open: boolean\n onClose: (event: SyntheticEvent) => any\n} {\n return {\n open: isOpen,\n onClose: close,\n }\n}\n\nfunction getPopup(\n element: Element,\n { popupId }: PopupState\n): Element | null | undefined {\n if (!popupId) return null\n const rootNode: any =\n typeof element.getRootNode === 'function' ? element.getRootNode() : document\n if (typeof rootNode.getElementById === 'function') {\n return rootNode.getElementById(popupId)\n }\n return null\n}\n\nfunction isElementInPopup(element: Element, popupState: PopupState): boolean {\n const { anchorEl, _childPopupState } = popupState\n return (\n isAncestor(anchorEl, element) ||\n isAncestor(getPopup(element, popupState), element) ||\n (_childPopupState != null && isElementInPopup(element, _childPopupState))\n )\n}\n\nfunction isAncestor(\n parent: Element | null | undefined,\n child: Element | null | undefined\n): boolean {\n if (!parent) return false\n while (child) {\n if (child === parent) return true\n child = child.parentElement\n }\n return false\n}\n"],"mappings":"AAAA;;AAEA,SAKEA,WAAW,EACXC,QAAQ,EACRC,MAAM,EACNC,SAAS,QACJ,OAAO;AACd,OAAO,KAAKC,KAAK,MAAM,OAAO;AAE9B,SAASC,QAAQ;AAEjB,MAAMC,eAAwC,GAAG,CAAC,CAAC;AAEnD,SAASC,IAAIA,CAACC,GAAW,EAAEC,OAAe,EAAE;EAC1C,IAAIH,eAAe,CAACE,GAAG,CAAC,EAAE;EAC1BF,eAAe,CAACE,GAAG,CAAC,GAAG,IAAI;EAC3BE,OAAO,CAACC,KAAK,CAAC,mCAAmC,EAAEF,OAAO,CAAC;AAC7D;AAwCA,OAAO,MAAMG,aAAwB,GAAG;EACtCC,MAAM,EAAE,KAAK;EACbC,eAAe,EAAE,KAAK;EACtBC,QAAQ,EAAEC,SAAS;EACnBC,cAAc,EAAED,SAAS;EACzBE,OAAO,EAAE,KAAK;EACdC,OAAO,EAAE,KAAK;EACdC,cAAc,EAAE,IAAI;EACpBC,gBAAgB,EAAE,IAAI;EACtBC,cAAc,EAAE,KAAK;EACrBC,eAAe,EAAE;AACnB,CAAC;;AAED;AACA;AACA;AACA,MAAMC,MAAM,GAAGpB,KAAK;AACpB,MAAMqB,cAAc,GAClB,OAAO,IAAID,MAAM,GACf,MAAMA,MAAM,CAACE,KAAK,CAAC;AACnB;AAAA,EACA,MAAMV,SAAS;AAEnB,OAAO,SAASW,aAAaA,CAAC;E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