@fluentui/react-menu 0.0.0-nightly-20230317-1454.1 → 0.0.0-nightly-20230322-0439.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.swcrc +2 -11
- package/CHANGELOG.json +116 -23
- package/CHANGELOG.md +36 -14
- package/lib/Menu.js +1 -1
- package/lib/MenuDivider.js +1 -1
- package/lib/MenuGroup.js +1 -1
- package/lib/MenuGroupHeader.js +1 -1
- package/lib/MenuItem.js +1 -1
- package/lib/MenuItemCheckbox.js +1 -1
- package/lib/MenuItemRadio.js +1 -1
- package/lib/MenuList.js +1 -1
- package/lib/MenuPopover.js +1 -1
- package/lib/MenuSplitGroup.js +1 -1
- package/lib/MenuTrigger.js +1 -1
- package/lib/components/Menu/Menu.js +5 -5
- package/lib/components/Menu/Menu.types.js +1 -1
- package/lib/components/Menu/index.js +5 -5
- package/lib/components/Menu/renderMenu.js +2 -2
- package/lib/components/Menu/useMenu.js +35 -28
- package/lib/components/Menu/useMenu.js.map +1 -1
- package/lib/components/MenuDivider/MenuDivider.js +6 -6
- package/lib/components/MenuDivider/index.js +5 -5
- package/lib/components/MenuDivider/renderMenuDivider.js +2 -2
- package/lib/components/MenuDivider/useMenuDivider.js +6 -6
- package/lib/components/MenuDivider/useMenuDividerStyles.js +3 -3
- package/lib/components/MenuGroup/MenuGroup.js +7 -7
- package/lib/components/MenuGroup/index.js +6 -6
- package/lib/components/MenuGroup/renderMenuGroup.js +3 -3
- package/lib/components/MenuGroup/useMenuGroup.js +7 -7
- package/lib/components/MenuGroup/useMenuGroupContextValues.js +1 -1
- package/lib/components/MenuGroup/useMenuGroupStyles.js +2 -2
- package/lib/components/MenuGroupHeader/MenuGroupHeader.js +6 -6
- package/lib/components/MenuGroupHeader/index.js +5 -5
- package/lib/components/MenuGroupHeader/renderMenuGroupHeader.js +2 -2
- package/lib/components/MenuGroupHeader/useMenuGroupHeader.js +5 -5
- package/lib/components/MenuGroupHeader/useMenuGroupHeaderStyles.js +3 -3
- package/lib/components/MenuItem/MenuItem.js +6 -6
- package/lib/components/MenuItem/index.js +5 -5
- package/lib/components/MenuItem/renderMenuItem.js +2 -2
- package/lib/components/MenuItem/useCharacterSearch.js +6 -5
- package/lib/components/MenuItem/useCharacterSearch.js.map +1 -1
- package/lib/components/MenuItem/useMenuItem.js +27 -24
- package/lib/components/MenuItem/useMenuItem.js.map +1 -1
- package/lib/components/MenuItem/useMenuItemStyles.js +26 -13
- package/lib/components/MenuItem/useMenuItemStyles.js.map +1 -1
- package/lib/components/MenuItemCheckbox/MenuItemCheckbox.js +6 -6
- package/lib/components/MenuItemCheckbox/index.js +5 -5
- package/lib/components/MenuItemCheckbox/renderMenuItemCheckbox.js +2 -2
- package/lib/components/MenuItemCheckbox/useMenuItemCheckbox.js +12 -10
- package/lib/components/MenuItemCheckbox/useMenuItemCheckbox.js.map +1 -1
- package/lib/components/MenuItemCheckbox/useMenuItemCheckboxStyles.js +8 -8
- package/lib/components/MenuItemRadio/MenuItemRadio.js +6 -6
- package/lib/components/MenuItemRadio/index.js +5 -5
- package/lib/components/MenuItemRadio/renderMenuItemRadio.js +2 -2
- package/lib/components/MenuItemRadio/useMenuItemRadio.js +12 -10
- package/lib/components/MenuItemRadio/useMenuItemRadio.js.map +1 -1
- package/lib/components/MenuItemRadio/useMenuItemRadioStyles.js +8 -8
- package/lib/components/MenuList/MenuList.js +7 -7
- package/lib/components/MenuList/MenuList.types.js +1 -1
- package/lib/components/MenuList/index.js +6 -6
- package/lib/components/MenuList/renderMenuList.js +3 -3
- package/lib/components/MenuList/useMenuList.js +24 -19
- package/lib/components/MenuList/useMenuList.js.map +1 -1
- package/lib/components/MenuList/useMenuListStyles.js +2 -2
- package/lib/components/MenuPopover/MenuPopover.js +6 -6
- package/lib/components/MenuPopover/index.js +5 -5
- package/lib/components/MenuPopover/renderMenuPopover.js +3 -3
- package/lib/components/MenuPopover/useMenuPopover.js +21 -19
- package/lib/components/MenuPopover/useMenuPopover.js.map +1 -1
- package/lib/components/MenuPopover/useMenuPopoverStyles.js +3 -3
- package/lib/components/MenuSplitGroup/MenuSplitGroup.js +6 -6
- package/lib/components/MenuSplitGroup/index.js +5 -5
- package/lib/components/MenuSplitGroup/renderMenuSplitGroup.js +2 -2
- package/lib/components/MenuSplitGroup/useMenuSplitGroup.js +13 -12
- package/lib/components/MenuSplitGroup/useMenuSplitGroup.js.map +1 -1
- package/lib/components/MenuSplitGroup/useMenuSplitGroupStyles.js +4 -4
- package/lib/components/MenuTrigger/MenuTrigger.js +4 -4
- package/lib/components/MenuTrigger/MenuTrigger.types.js +1 -1
- package/lib/components/MenuTrigger/index.js +4 -4
- package/lib/components/MenuTrigger/renderMenuTrigger.js +2 -2
- package/lib/components/MenuTrigger/useMenuTrigger.js +29 -29
- package/lib/components/MenuTrigger/useMenuTrigger.js.map +1 -1
- package/lib/components/index.js +2 -2
- package/lib/contexts/menuContext.js +3 -3
- package/lib/contexts/menuGroupContext.js +4 -3
- package/lib/contexts/menuGroupContext.js.map +1 -1
- package/lib/contexts/menuListContext.js +2 -2
- package/lib/contexts/menuTriggerContext.js +3 -2
- package/lib/contexts/menuTriggerContext.js.map +1 -1
- package/lib/index.js +16 -16
- package/lib/selectable/index.js +2 -2
- package/lib/selectable/types.js +1 -1
- package/lib/selectable/useCheckmarkStyles.js +1 -1
- package/lib/utils/index.js +1 -1
- package/lib/utils/useIsSubmenu.js +3 -3
- package/lib/utils/useOnMenuEnter.js +6 -5
- package/lib/utils/useOnMenuEnter.js.map +1 -1
- package/lib-commonjs/Menu.js.map +1 -1
- package/lib-commonjs/MenuDivider.js.map +1 -1
- package/lib-commonjs/MenuGroup.js.map +1 -1
- package/lib-commonjs/MenuGroupHeader.js.map +1 -1
- package/lib-commonjs/MenuItem.js.map +1 -1
- package/lib-commonjs/MenuItemCheckbox.js.map +1 -1
- package/lib-commonjs/MenuItemRadio.js.map +1 -1
- package/lib-commonjs/MenuList.js.map +1 -1
- package/lib-commonjs/MenuPopover.js.map +1 -1
- package/lib-commonjs/MenuSplitGroup.js.map +1 -1
- package/lib-commonjs/MenuTrigger.js.map +1 -1
- package/lib-commonjs/components/Menu/Menu.js +1 -1
- package/lib-commonjs/components/Menu/Menu.js.map +1 -1
- package/lib-commonjs/components/Menu/Menu.types.js.map +1 -1
- package/lib-commonjs/components/Menu/index.js.map +1 -1
- package/lib-commonjs/components/Menu/renderMenu.js.map +1 -1
- package/lib-commonjs/components/Menu/useMenu.js +31 -25
- package/lib-commonjs/components/Menu/useMenu.js.map +1 -1
- package/lib-commonjs/components/MenuDivider/MenuDivider.js +1 -1
- package/lib-commonjs/components/MenuDivider/MenuDivider.js.map +1 -1
- package/lib-commonjs/components/MenuDivider/index.js.map +1 -1
- package/lib-commonjs/components/MenuDivider/renderMenuDivider.js.map +1 -1
- package/lib-commonjs/components/MenuDivider/useMenuDivider.js +4 -4
- package/lib-commonjs/components/MenuDivider/useMenuDivider.js.map +1 -1
- package/lib-commonjs/components/MenuDivider/useMenuDividerStyles.js +1 -1
- package/lib-commonjs/components/MenuDivider/useMenuDividerStyles.js.map +1 -1
- package/lib-commonjs/components/MenuGroup/MenuGroup.js +1 -1
- package/lib-commonjs/components/MenuGroup/MenuGroup.js.map +1 -1
- package/lib-commonjs/components/MenuGroup/index.js.map +1 -1
- package/lib-commonjs/components/MenuGroup/renderMenuGroup.js.map +1 -1
- package/lib-commonjs/components/MenuGroup/useMenuGroup.js +5 -5
- package/lib-commonjs/components/MenuGroup/useMenuGroup.js.map +1 -1
- package/lib-commonjs/components/MenuGroup/useMenuGroupContextValues.js.map +1 -1
- package/lib-commonjs/components/MenuGroup/useMenuGroupStyles.js +1 -1
- package/lib-commonjs/components/MenuGroup/useMenuGroupStyles.js.map +1 -1
- package/lib-commonjs/components/MenuGroupHeader/MenuGroupHeader.js +1 -1
- package/lib-commonjs/components/MenuGroupHeader/MenuGroupHeader.js.map +1 -1
- package/lib-commonjs/components/MenuGroupHeader/index.js.map +1 -1
- package/lib-commonjs/components/MenuGroupHeader/renderMenuGroupHeader.js.map +1 -1
- package/lib-commonjs/components/MenuGroupHeader/useMenuGroupHeader.js +2 -2
- package/lib-commonjs/components/MenuGroupHeader/useMenuGroupHeader.js.map +1 -1
- package/lib-commonjs/components/MenuGroupHeader/useMenuGroupHeaderStyles.js +1 -1
- package/lib-commonjs/components/MenuGroupHeader/useMenuGroupHeaderStyles.js.map +1 -1
- package/lib-commonjs/components/MenuItem/MenuItem.js +1 -1
- package/lib-commonjs/components/MenuItem/MenuItem.js.map +1 -1
- package/lib-commonjs/components/MenuItem/index.js.map +1 -1
- package/lib-commonjs/components/MenuItem/renderMenuItem.js.map +1 -1
- package/lib-commonjs/components/MenuItem/useCharacterSearch.js +4 -3
- package/lib-commonjs/components/MenuItem/useCharacterSearch.js.map +1 -1
- package/lib-commonjs/components/MenuItem/useMenuItem.js +17 -14
- package/lib-commonjs/components/MenuItem/useMenuItem.js.map +1 -1
- package/lib-commonjs/components/MenuItem/useMenuItemStyles.js +38 -8
- package/lib-commonjs/components/MenuItem/useMenuItemStyles.js.map +1 -1
- package/lib-commonjs/components/MenuItemCheckbox/MenuItemCheckbox.js +1 -1
- package/lib-commonjs/components/MenuItemCheckbox/MenuItemCheckbox.js.map +1 -1
- package/lib-commonjs/components/MenuItemCheckbox/index.js.map +1 -1
- package/lib-commonjs/components/MenuItemCheckbox/renderMenuItemCheckbox.js.map +1 -1
- package/lib-commonjs/components/MenuItemCheckbox/useMenuItemCheckbox.js +7 -5
- package/lib-commonjs/components/MenuItemCheckbox/useMenuItemCheckbox.js.map +1 -1
- package/lib-commonjs/components/MenuItemCheckbox/useMenuItemCheckboxStyles.js +5 -5
- package/lib-commonjs/components/MenuItemCheckbox/useMenuItemCheckboxStyles.js.map +1 -1
- package/lib-commonjs/components/MenuItemRadio/MenuItemRadio.js +1 -1
- package/lib-commonjs/components/MenuItemRadio/MenuItemRadio.js.map +1 -1
- package/lib-commonjs/components/MenuItemRadio/index.js.map +1 -1
- package/lib-commonjs/components/MenuItemRadio/renderMenuItemRadio.js.map +1 -1
- package/lib-commonjs/components/MenuItemRadio/useMenuItemRadio.js +7 -5
- package/lib-commonjs/components/MenuItemRadio/useMenuItemRadio.js.map +1 -1
- package/lib-commonjs/components/MenuItemRadio/useMenuItemRadioStyles.js +5 -5
- package/lib-commonjs/components/MenuItemRadio/useMenuItemRadioStyles.js.map +1 -1
- package/lib-commonjs/components/MenuList/MenuList.js +1 -1
- package/lib-commonjs/components/MenuList/MenuList.js.map +1 -1
- package/lib-commonjs/components/MenuList/MenuList.types.js.map +1 -1
- package/lib-commonjs/components/MenuList/index.js.map +1 -1
- package/lib-commonjs/components/MenuList/renderMenuList.js.map +1 -1
- package/lib-commonjs/components/MenuList/useMenuList.js +20 -15
- package/lib-commonjs/components/MenuList/useMenuList.js.map +1 -1
- package/lib-commonjs/components/MenuList/useMenuListStyles.js +1 -1
- package/lib-commonjs/components/MenuList/useMenuListStyles.js.map +1 -1
- package/lib-commonjs/components/MenuPopover/MenuPopover.js +1 -1
- package/lib-commonjs/components/MenuPopover/MenuPopover.js.map +1 -1
- package/lib-commonjs/components/MenuPopover/index.js.map +1 -1
- package/lib-commonjs/components/MenuPopover/renderMenuPopover.js.map +1 -1
- package/lib-commonjs/components/MenuPopover/useMenuPopover.js +14 -12
- package/lib-commonjs/components/MenuPopover/useMenuPopover.js.map +1 -1
- package/lib-commonjs/components/MenuPopover/useMenuPopoverStyles.js +1 -1
- package/lib-commonjs/components/MenuPopover/useMenuPopoverStyles.js.map +1 -1
- package/lib-commonjs/components/MenuSplitGroup/MenuSplitGroup.js +1 -1
- package/lib-commonjs/components/MenuSplitGroup/MenuSplitGroup.js.map +1 -1
- package/lib-commonjs/components/MenuSplitGroup/index.js.map +1 -1
- package/lib-commonjs/components/MenuSplitGroup/renderMenuSplitGroup.js.map +1 -1
- package/lib-commonjs/components/MenuSplitGroup/useMenuSplitGroup.js +8 -7
- package/lib-commonjs/components/MenuSplitGroup/useMenuSplitGroup.js.map +1 -1
- package/lib-commonjs/components/MenuSplitGroup/useMenuSplitGroupStyles.js +2 -2
- package/lib-commonjs/components/MenuSplitGroup/useMenuSplitGroupStyles.js.map +1 -1
- package/lib-commonjs/components/MenuTrigger/MenuTrigger.js +1 -1
- package/lib-commonjs/components/MenuTrigger/MenuTrigger.js.map +1 -1
- package/lib-commonjs/components/MenuTrigger/MenuTrigger.types.js.map +1 -1
- package/lib-commonjs/components/MenuTrigger/index.js.map +1 -1
- package/lib-commonjs/components/MenuTrigger/renderMenuTrigger.js.map +1 -1
- package/lib-commonjs/components/MenuTrigger/useMenuTrigger.js +21 -21
- package/lib-commonjs/components/MenuTrigger/useMenuTrigger.js.map +1 -1
- package/lib-commonjs/components/index.js.map +1 -1
- package/lib-commonjs/contexts/menuContext.js +1 -1
- package/lib-commonjs/contexts/menuContext.js.map +1 -1
- package/lib-commonjs/contexts/menuGroupContext.js +3 -2
- package/lib-commonjs/contexts/menuGroupContext.js.map +1 -1
- package/lib-commonjs/contexts/menuListContext.js.map +1 -1
- package/lib-commonjs/contexts/menuTriggerContext.js +2 -1
- package/lib-commonjs/contexts/menuTriggerContext.js.map +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/selectable/index.js.map +1 -1
- package/lib-commonjs/selectable/types.js.map +1 -1
- package/lib-commonjs/selectable/useCheckmarkStyles.js.map +1 -1
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/useIsSubmenu.js.map +1 -1
- package/lib-commonjs/utils/useOnMenuEnter.js +3 -2
- package/lib-commonjs/utils/useOnMenuEnter.js.map +1 -1
- package/package.json +13 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","usePositioningMouseTarget","usePositioning","resolvePositioningShorthand","useControllableState","useId","useOnClickOutside","useEventCallback","useOnScrollOutside","useFluent_unstable","useFluent","elementContains","useFocusFinders","useMenuContext_unstable","MENU_ENTER_EVENT","useOnMenuMouseEnter","useIsSubmenu","submenuFallbackPositions","useMenu_unstable","props","isSubmenu","hoverDelay","inline","hasCheckmarks","hasIcons","closeOnScroll","openOnContext","persistOnItemClick","openOnHover","defaultCheckedValues","mountNode","triggerId","contextTarget","setContextTarget","positioningState","position","align","target","undefined","fallbackPositions","positioning","children","Children","toArray","process","env","NODE_ENV","length","console","warn","menuTrigger","menuPopover","targetRef","triggerRef","containerRef","menuPopoverRef","open","setOpen","useMenuOpenState","defaultOpen","onOpenChange","checkedValues","onCheckedValueChange","useMenuSelectableState","components","setCheckedValues","state","defaultState","initialState","e","name","checkedItems","currentValue","targetDocument","parentSetOpen","context","data","shouldHandleCloseRef","useRef","setOpenTimeout","enteringTriggerRef","setOpenState","trySetOpen","event","CustomEvent","type","detail","nativeEvent","current","bubble","clearTimeout","Event","persist","contains","setTimeout","disabled","element","refs","filter","Boolean","callback","useEffect","findFirstFocusable","focusFirst","useCallback","firstFocusable","focus"],"sources":["../../../src/components/Menu/useMenu.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n usePositioningMouseTarget,\n usePositioning,\n resolvePositioningShorthand,\n PositioningShorthandValue,\n} from '@fluentui/react-positioning';\nimport {\n useControllableState,\n useId,\n useOnClickOutside,\n useEventCallback,\n useOnScrollOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { elementContains } from '@fluentui/react-portal';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nimport { useMenuContext_unstable } from '../../contexts/menuContext';\nimport { MENU_ENTER_EVENT, useOnMenuMouseEnter } from '../../utils/index';\nimport { useIsSubmenu } from '../../utils/useIsSubmenu';\nimport type { MenuOpenChangeData, MenuOpenEvent, MenuProps, MenuState } from './Menu.types';\n\n// If it's not possible to position the submenu in smaller viewports, try\n// and fallback to this order of positions\nconst submenuFallbackPositions: PositioningShorthandValue[] = [\n 'after',\n 'after-bottom',\n 'before-top',\n 'before',\n 'before-bottom',\n 'above',\n];\n\n/**\n * Create the state required to render Menu.\n *\n * The returned state can be modified with hooks such as useMenuStyles,\n * before being passed to renderMenu_unstable.\n *\n * @param props - props from this instance of Menu\n */\nexport const useMenu_unstable = (props: MenuProps): MenuState => {\n const isSubmenu = useIsSubmenu();\n const {\n hoverDelay = 500,\n inline = false,\n hasCheckmarks = false,\n hasIcons = false,\n closeOnScroll = false,\n openOnContext = false,\n persistOnItemClick = false,\n openOnHover = isSubmenu,\n defaultCheckedValues,\n mountNode = null,\n } = props;\n const triggerId = useId('menu');\n const [contextTarget, setContextTarget] = usePositioningMouseTarget();\n\n const positioningState = {\n position: isSubmenu ? 'after' : 'below',\n align: isSubmenu ? 'top' : 'start',\n target: props.openOnContext ? contextTarget : undefined,\n fallbackPositions: isSubmenu ? submenuFallbackPositions : undefined,\n ...resolvePositioningShorthand(props.positioning),\n } as const;\n\n const children = React.Children.toArray(props.children) as React.ReactElement[];\n\n if (process.env.NODE_ENV !== 'production') {\n if (children.length === 0) {\n // eslint-disable-next-line no-console\n console.warn('Menu must contain at least one child');\n }\n\n if (children.length > 2) {\n // eslint-disable-next-line no-console\n console.warn('Menu must contain at most two children');\n }\n }\n\n let menuTrigger: React.ReactElement | undefined = undefined;\n let menuPopover: React.ReactElement | undefined = undefined;\n if (children.length === 2) {\n menuTrigger = children[0];\n menuPopover = children[1];\n } else if (children.length === 1) {\n menuPopover = children[0];\n }\n\n const { targetRef: triggerRef, containerRef: menuPopoverRef } = usePositioning(positioningState);\n\n // TODO Better way to narrow types ?\n const [open, setOpen] = useMenuOpenState({\n hoverDelay,\n isSubmenu,\n setContextTarget,\n closeOnScroll,\n menuPopoverRef,\n triggerRef,\n open: props.open,\n defaultOpen: props.defaultOpen,\n onOpenChange: props.onOpenChange,\n openOnContext,\n });\n\n const [checkedValues, onCheckedValueChange] = useMenuSelectableState({\n checkedValues: props.checkedValues,\n defaultCheckedValues,\n onCheckedValueChange: props.onCheckedValueChange,\n });\n\n return {\n inline,\n hoverDelay,\n triggerId,\n isSubmenu,\n openOnHover,\n contextTarget,\n setContextTarget,\n hasCheckmarks,\n hasIcons,\n closeOnScroll,\n menuTrigger,\n menuPopover,\n mountNode,\n triggerRef,\n menuPopoverRef,\n components: {},\n openOnContext,\n open,\n setOpen,\n checkedValues,\n onCheckedValueChange,\n persistOnItemClick,\n };\n};\n\n/**\n * Adds appropriate state values and handlers for selectable items\n * i.e checkboxes and radios\n */\nconst useMenuSelectableState = (\n props: Pick<MenuProps, 'checkedValues' | 'defaultCheckedValues' | 'onCheckedValueChange'>,\n) => {\n const [checkedValues, setCheckedValues] = useControllableState({\n state: props.checkedValues,\n defaultState: props.defaultCheckedValues,\n initialState: {},\n });\n const onCheckedValueChange: MenuState['onCheckedValueChange'] = useEventCallback((e, { name, checkedItems }) => {\n props.onCheckedValueChange?.(e, { name, checkedItems });\n\n setCheckedValues(currentValue => ({\n ...currentValue,\n [name]: checkedItems,\n }));\n });\n\n return [checkedValues, onCheckedValueChange] as const;\n};\n\nconst useMenuOpenState = (\n state: Pick<\n MenuState,\n | 'isSubmenu'\n | 'menuPopoverRef'\n | 'setContextTarget'\n | 'triggerRef'\n | 'openOnContext'\n | 'closeOnScroll'\n | 'hoverDelay'\n > &\n Pick<MenuProps, 'open' | 'defaultOpen' | 'onOpenChange'>,\n) => {\n const { targetDocument } = useFluent();\n const parentSetOpen = useMenuContext_unstable(context => context.setOpen);\n const onOpenChange: MenuProps['onOpenChange'] = useEventCallback((e, data) => state.onOpenChange?.(e, data));\n\n const shouldHandleCloseRef = React.useRef(false);\n const setOpenTimeout = React.useRef(0);\n const enteringTriggerRef = React.useRef(false);\n\n const [open, setOpenState] = useControllableState({\n state: state.open,\n defaultState: state.defaultOpen,\n initialState: false,\n });\n\n const trySetOpen = useEventCallback((e: MenuOpenEvent, data: MenuOpenChangeData) => {\n const event = e instanceof CustomEvent && e.type === MENU_ENTER_EVENT ? e.detail.nativeEvent : e;\n onOpenChange?.(event, { ...data });\n if (data.open && e.type === 'contextmenu') {\n state.setContextTarget(e as React.MouseEvent);\n }\n\n if (!data.open) {\n state.setContextTarget(undefined);\n shouldHandleCloseRef.current = true;\n }\n\n if (data.bubble) {\n parentSetOpen(e, { ...data });\n }\n\n setOpenState(data.open);\n });\n\n const setOpen = useEventCallback((e: MenuOpenEvent, data: MenuOpenChangeData) => {\n clearTimeout(setOpenTimeout.current);\n if (!(e instanceof Event) && e.persist) {\n // < React 17 still uses pooled synthetic events\n e.persist();\n }\n\n if (e.type === 'mouseleave' || e.type === 'mouseenter' || e.type === 'mousemove' || e.type === MENU_ENTER_EVENT) {\n if (state.triggerRef.current?.contains(e.target as HTMLElement)) {\n enteringTriggerRef.current = e.type === 'mouseenter' || e.type === 'mousemove';\n }\n\n // FIXME leaking Node timeout type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n setOpenTimeout.current = setTimeout(() => trySetOpen(e, data), state.hoverDelay);\n } else {\n trySetOpen(e, data);\n }\n });\n\n useOnClickOutside({\n contains: elementContains,\n disabled: !open,\n element: targetDocument,\n refs: [state.menuPopoverRef, !state.openOnContext && state.triggerRef].filter(\n Boolean,\n ) as React.MutableRefObject<HTMLElement>[],\n callback: event => setOpen(event, { open: false, type: 'clickOutside', event }),\n });\n\n // only close on scroll for context, or when closeOnScroll is specified\n const closeOnScroll = state.openOnContext || state.closeOnScroll;\n useOnScrollOutside({\n contains: elementContains,\n element: targetDocument,\n callback: event => setOpen(event, { open: false, type: 'scrollOutside', event }),\n refs: [state.menuPopoverRef, !state.openOnContext && state.triggerRef].filter(\n Boolean,\n ) as React.MutableRefObject<HTMLElement>[],\n disabled: !open || !closeOnScroll,\n });\n\n useOnMenuMouseEnter({\n element: targetDocument,\n callback: event => {\n // When moving from a menu directly back to its trigger, this handler can close the menu\n // Explicitly check a flag to see if this situation happens\n if (!enteringTriggerRef.current) {\n setOpen(event, { open: false, type: 'menuMouseEnter', event });\n }\n },\n disabled: !open,\n refs: [state.menuPopoverRef],\n });\n\n // Clear timeout on unmount\n // Setting state after a component unmounts can cause memory leaks\n React.useEffect(() => {\n return () => {\n clearTimeout(setOpenTimeout.current);\n };\n }, []);\n\n // Manage focus for open state\n const { findFirstFocusable } = useFocusFinders();\n const focusFirst = React.useCallback(() => {\n const firstFocusable = findFirstFocusable(state.menuPopoverRef.current);\n firstFocusable?.focus();\n }, [findFirstFocusable, state.menuPopoverRef]);\n\n React.useEffect(() => {\n if (open) {\n focusFirst();\n } else {\n if (shouldHandleCloseRef.current) {\n // We know that React effects are sync so we focus the trigger here\n // after any event handler (event handlers will update state and re-render).\n // Since the browser only performs the default behaviour for the Tab key once\n // keyboard events have fully bubbled up the window, the browser will move\n // focus to the next tabbable element before/after the trigger if needed.\n // If the Tab key was not pressed, focus will remain on the trigger as expected.\n state.triggerRef.current?.focus();\n }\n }\n\n shouldHandleCloseRef.current = false;\n }, [state.triggerRef, state.isSubmenu, open, focusFirst]);\n\n return [open, setOpen] as const;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SACEC,yBAAyB,EACzBC,cAAc,EACdC,2BAA2B,QAEtB;AACP,SACEC,oBAAoB,EACpBC,KAAK,EACLC,iBAAiB,EACjBC,gBAAgB,EAChBC,kBAAkB,QACb;AACP,SAASC,kBAAA,IAAsBC,SAAS,QAAQ;AAChD,SAASC,eAAe,QAAQ;AAChC,SAASC,eAAe,QAAQ;AAChC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,gBAAgB,EAAEC,mBAAmB,QAAQ;AACtD,SAASC,YAAY,QAAQ;AAG7B;AACA;AACA,MAAMC,wBAAA,GAAwD,CAC5D,SACA,gBACA,cACA,UACA,iBACA,QACD;AAED;;;;;;;;AAQA,OAAO,MAAMC,gBAAA,GAAoBC,KAAA,IAAgC;EAC/D,MAAMC,SAAA,GAAYJ,YAAA;EAClB,MAAM;IACJK,UAAA,GAAa;IACbC,MAAA,GAAS,KAAK;IACdC,aAAA,GAAgB,KAAK;IACrBC,QAAA,GAAW,KAAK;IAChBC,aAAA,GAAgB,KAAK;IACrBC,aAAA,GAAgB,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,GAAiBH,kBAAA,CAAmBpC,KAAA,CAAMX,cAAc,CAACiC,OAAO;IACtEiB,cAAA,EAAgBC,KAAA;EAClB,GAAG,CAACJ,kBAAA,EAAoBpC,KAAA,CAAMX,cAAc,CAAC;EAE7CvD,KAAA,CAAMqG,SAAS,CAAC,MAAM;IACpB,IAAI7C,IAAA,EAAM;MACR+C,UAAA;IACF,OAAO;MACL,IAAI1B,oBAAA,CAAqBW,OAAO,EAAE;QAChC;QACA;QACA;QACA;QACA;QACA;QACAtB,KAAA,CAAMb,UAAU,CAACmC,OAAO,EAAEkB,KAAA;MAC5B;IACF;IAEA7B,oBAAA,CAAqBW,OAAO,GAAG,KAAK;EACtC,GAAG,CAACtB,KAAA,CAAMb,UAAU,EAAEa,KAAA,CAAM9C,SAAS,EAAEoC,IAAA,EAAM+C,UAAA,CAAW;EAExD,OAAO,CAAC/C,IAAA,EAAMC,OAAA,CAAQ;AACxB"}
|
|
1
|
+
{"version":3,"names":["React","usePositioningMouseTarget","usePositioning","resolvePositioningShorthand","useControllableState","useId","useOnClickOutside","useEventCallback","useOnScrollOutside","useFluent_unstable","useFluent","elementContains","useFocusFinders","useMenuContext_unstable","MENU_ENTER_EVENT","useOnMenuMouseEnter","useIsSubmenu","submenuFallbackPositions","useMenu_unstable","props","isSubmenu","hoverDelay","inline","hasCheckmarks","hasIcons","closeOnScroll","openOnContext","persistOnItemClick","openOnHover","defaultCheckedValues","mountNode","triggerId","contextTarget","setContextTarget","positioningState","position","align","target","undefined","fallbackPositions","positioning","children","Children","toArray","process","env","NODE_ENV","length","console","warn","menuTrigger","menuPopover","targetRef","triggerRef","containerRef","menuPopoverRef","open","setOpen","useMenuOpenState","defaultOpen","onOpenChange","checkedValues","onCheckedValueChange","useMenuSelectableState","components","setCheckedValues","state","defaultState","initialState","e","name","checkedItems","_props_onCheckedValueChange","call","currentValue","targetDocument","parentSetOpen","context","data","_state_onOpenChange","shouldHandleCloseRef","useRef","setOpenTimeout","enteringTriggerRef","setOpenState","trySetOpen","event","CustomEvent","type","detail","nativeEvent","current","bubble","clearTimeout","Event","persist","_state_triggerRef_current","contains","setTimeout","disabled","element","refs","filter","Boolean","callback","useEffect","findFirstFocusable","focusFirst","useCallback","firstFocusable","focus"],"sources":["../../../src/components/Menu/useMenu.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n usePositioningMouseTarget,\n usePositioning,\n resolvePositioningShorthand,\n PositioningShorthandValue,\n} from '@fluentui/react-positioning';\nimport {\n useControllableState,\n useId,\n useOnClickOutside,\n useEventCallback,\n useOnScrollOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { elementContains } from '@fluentui/react-portal';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nimport { useMenuContext_unstable } from '../../contexts/menuContext';\nimport { MENU_ENTER_EVENT, useOnMenuMouseEnter } from '../../utils/index';\nimport { useIsSubmenu } from '../../utils/useIsSubmenu';\nimport type { MenuOpenChangeData, MenuOpenEvent, MenuProps, MenuState } from './Menu.types';\n\n// If it's not possible to position the submenu in smaller viewports, try\n// and fallback to this order of positions\nconst submenuFallbackPositions: PositioningShorthandValue[] = [\n 'after',\n 'after-bottom',\n 'before-top',\n 'before',\n 'before-bottom',\n 'above',\n];\n\n/**\n * Create the state required to render Menu.\n *\n * The returned state can be modified with hooks such as useMenuStyles,\n * before being passed to renderMenu_unstable.\n *\n * @param props - props from this instance of Menu\n */\nexport const useMenu_unstable = (props: MenuProps): MenuState => {\n const isSubmenu = useIsSubmenu();\n const {\n hoverDelay = 500,\n inline = false,\n hasCheckmarks = false,\n hasIcons = false,\n closeOnScroll = false,\n openOnContext = false,\n persistOnItemClick = false,\n openOnHover = isSubmenu,\n defaultCheckedValues,\n mountNode = null,\n } = props;\n const triggerId = useId('menu');\n const [contextTarget, setContextTarget] = usePositioningMouseTarget();\n\n const positioningState = {\n position: isSubmenu ? 'after' : 'below',\n align: isSubmenu ? 'top' : 'start',\n target: props.openOnContext ? contextTarget : undefined,\n fallbackPositions: isSubmenu ? submenuFallbackPositions : undefined,\n ...resolvePositioningShorthand(props.positioning),\n } as const;\n\n const children = React.Children.toArray(props.children) as React.ReactElement[];\n\n if (process.env.NODE_ENV !== 'production') {\n if (children.length === 0) {\n // eslint-disable-next-line no-console\n console.warn('Menu must contain at least one child');\n }\n\n if (children.length > 2) {\n // eslint-disable-next-line no-console\n console.warn('Menu must contain at most two children');\n }\n }\n\n let menuTrigger: React.ReactElement | undefined = undefined;\n let menuPopover: React.ReactElement | undefined = undefined;\n if (children.length === 2) {\n menuTrigger = children[0];\n menuPopover = children[1];\n } else if (children.length === 1) {\n menuPopover = children[0];\n }\n\n const { targetRef: triggerRef, containerRef: menuPopoverRef } = usePositioning(positioningState);\n\n // TODO Better way to narrow types ?\n const [open, setOpen] = useMenuOpenState({\n hoverDelay,\n isSubmenu,\n setContextTarget,\n closeOnScroll,\n menuPopoverRef,\n triggerRef,\n open: props.open,\n defaultOpen: props.defaultOpen,\n onOpenChange: props.onOpenChange,\n openOnContext,\n });\n\n const [checkedValues, onCheckedValueChange] = useMenuSelectableState({\n checkedValues: props.checkedValues,\n defaultCheckedValues,\n onCheckedValueChange: props.onCheckedValueChange,\n });\n\n return {\n inline,\n hoverDelay,\n triggerId,\n isSubmenu,\n openOnHover,\n contextTarget,\n setContextTarget,\n hasCheckmarks,\n hasIcons,\n closeOnScroll,\n menuTrigger,\n menuPopover,\n mountNode,\n triggerRef,\n menuPopoverRef,\n components: {},\n openOnContext,\n open,\n setOpen,\n checkedValues,\n onCheckedValueChange,\n persistOnItemClick,\n };\n};\n\n/**\n * Adds appropriate state values and handlers for selectable items\n * i.e checkboxes and radios\n */\nconst useMenuSelectableState = (\n props: Pick<MenuProps, 'checkedValues' | 'defaultCheckedValues' | 'onCheckedValueChange'>,\n) => {\n const [checkedValues, setCheckedValues] = useControllableState({\n state: props.checkedValues,\n defaultState: props.defaultCheckedValues,\n initialState: {},\n });\n const onCheckedValueChange: MenuState['onCheckedValueChange'] = useEventCallback((e, { name, checkedItems }) => {\n props.onCheckedValueChange?.(e, { name, checkedItems });\n\n setCheckedValues(currentValue => ({\n ...currentValue,\n [name]: checkedItems,\n }));\n });\n\n return [checkedValues, onCheckedValueChange] as const;\n};\n\nconst useMenuOpenState = (\n state: Pick<\n MenuState,\n | 'isSubmenu'\n | 'menuPopoverRef'\n | 'setContextTarget'\n | 'triggerRef'\n | 'openOnContext'\n | 'closeOnScroll'\n | 'hoverDelay'\n > &\n Pick<MenuProps, 'open' | 'defaultOpen' | 'onOpenChange'>,\n) => {\n const { targetDocument } = useFluent();\n const parentSetOpen = useMenuContext_unstable(context => context.setOpen);\n const onOpenChange: MenuProps['onOpenChange'] = useEventCallback((e, data) => state.onOpenChange?.(e, data));\n\n const shouldHandleCloseRef = React.useRef(false);\n const setOpenTimeout = React.useRef(0);\n const enteringTriggerRef = React.useRef(false);\n\n const [open, setOpenState] = useControllableState({\n state: state.open,\n defaultState: state.defaultOpen,\n initialState: false,\n });\n\n const trySetOpen = useEventCallback((e: MenuOpenEvent, data: MenuOpenChangeData) => {\n const event = e instanceof CustomEvent && e.type === MENU_ENTER_EVENT ? e.detail.nativeEvent : e;\n onOpenChange?.(event, { ...data });\n if (data.open && e.type === 'contextmenu') {\n state.setContextTarget(e as React.MouseEvent);\n }\n\n if (!data.open) {\n state.setContextTarget(undefined);\n shouldHandleCloseRef.current = true;\n }\n\n if (data.bubble) {\n parentSetOpen(e, { ...data });\n }\n\n setOpenState(data.open);\n });\n\n const setOpen = useEventCallback((e: MenuOpenEvent, data: MenuOpenChangeData) => {\n clearTimeout(setOpenTimeout.current);\n if (!(e instanceof Event) && e.persist) {\n // < React 17 still uses pooled synthetic events\n e.persist();\n }\n\n if (e.type === 'mouseleave' || e.type === 'mouseenter' || e.type === 'mousemove' || e.type === MENU_ENTER_EVENT) {\n if (state.triggerRef.current?.contains(e.target as HTMLElement)) {\n enteringTriggerRef.current = e.type === 'mouseenter' || e.type === 'mousemove';\n }\n\n // FIXME leaking Node timeout type\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n setOpenTimeout.current = setTimeout(() => trySetOpen(e, data), state.hoverDelay);\n } else {\n trySetOpen(e, data);\n }\n });\n\n useOnClickOutside({\n contains: elementContains,\n disabled: !open,\n element: targetDocument,\n refs: [state.menuPopoverRef, !state.openOnContext && state.triggerRef].filter(\n Boolean,\n ) as React.MutableRefObject<HTMLElement>[],\n callback: event => setOpen(event, { open: false, type: 'clickOutside', event }),\n });\n\n // only close on scroll for context, or when closeOnScroll is specified\n const closeOnScroll = state.openOnContext || state.closeOnScroll;\n useOnScrollOutside({\n contains: elementContains,\n element: targetDocument,\n callback: event => setOpen(event, { open: false, type: 'scrollOutside', event }),\n refs: [state.menuPopoverRef, !state.openOnContext && state.triggerRef].filter(\n Boolean,\n ) as React.MutableRefObject<HTMLElement>[],\n disabled: !open || !closeOnScroll,\n });\n\n useOnMenuMouseEnter({\n element: targetDocument,\n callback: event => {\n // When moving from a menu directly back to its trigger, this handler can close the menu\n // Explicitly check a flag to see if this situation happens\n if (!enteringTriggerRef.current) {\n setOpen(event, { open: false, type: 'menuMouseEnter', event });\n }\n },\n disabled: !open,\n refs: [state.menuPopoverRef],\n });\n\n // Clear timeout on unmount\n // Setting state after a component unmounts can cause memory leaks\n React.useEffect(() => {\n return () => {\n clearTimeout(setOpenTimeout.current);\n };\n }, []);\n\n // Manage focus for open state\n const { findFirstFocusable } = useFocusFinders();\n const focusFirst = React.useCallback(() => {\n const firstFocusable = findFirstFocusable(state.menuPopoverRef.current);\n firstFocusable?.focus();\n }, [findFirstFocusable, state.menuPopoverRef]);\n\n React.useEffect(() => {\n if (open) {\n focusFirst();\n } else {\n if (shouldHandleCloseRef.current) {\n // We know that React effects are sync so we focus the trigger here\n // after any event handler (event handlers will update state and re-render).\n // Since the browser only performs the default behaviour for the Tab key once\n // keyboard events have fully bubbled up the window, the browser will move\n // focus to the next tabbable element before/after the trigger if needed.\n // If the Tab key was not pressed, focus will remain on the trigger as expected.\n state.triggerRef.current?.focus();\n }\n }\n\n shouldHandleCloseRef.current = false;\n }, [state.triggerRef, state.isSubmenu, open, focusFirst]);\n\n return [open, setOpen] as const;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SACEC,yBAAyB,EACzBC,cAAc,EACdC,2BAA2B,QAEtB;AACP,SACEC,oBAAoB,EACpBC,KAAK,EACLC,iBAAiB,EACjBC,gBAAgB,EAChBC,kBAAkB,QACb;AACP,SAASC,kBAAA,IAAsBC,SAAS,QAAQ;AAChD,SAASC,eAAe,QAAQ;AAChC,SAASC,eAAe,QAAQ;AAChC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,gBAAgB,EAAEC,mBAAmB,QAAQ;AACtD,SAASC,YAAY,QAAQ;AAG7B;AACA;AACA,MAAMC,wBAAA,GAAwD,CAC5D,SACA,gBACA,cACA,UACA,iBACA,QACD;AAED;;;;;;;;AAQA,OAAO,MAAMC,gBAAA,GAAoBC,KAAA,IAAgC;EAC/D,MAAMC,SAAA,GAAYJ,YAAA;EAClB,MAAM;IACJK,UAAA,GAAa;IACbC,MAAA,GAAS,KAAK;IACdC,aAAA,GAAgB,KAAK;IACrBC,QAAA,GAAW,KAAK;IAChBC,aAAA,GAAgB,KAAK;IACrBC,aAAA,GAAgB,KAAK;IACrBC,kBAAA,GAAqB,KAAK;IAC1BC,WAAA,GAAcR,SAAA;IACdS,oBAAA;IACAC,SAAA,GAAY;EAAI,CACjB,GAAGX,KAAA;EACJ,MAAMY,SAAA,GAAY1B,KAAA,CAAM;EACxB,MAAM,CAAC2B,aAAA,EAAeC,gBAAA,CAAiB,GAAGhC,yBAAA;EAE1C,MAAMiC,gBAAA,GAAmB;IACvBC,QAAA,EAAUf,SAAA,GAAY,UAAU,OAAO;IACvCgB,KAAA,EAAOhB,SAAA,GAAY,QAAQ,OAAO;IAClCiB,MAAA,EAAQlB,KAAA,CAAMO,aAAa,GAAGM,aAAA,GAAgBM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KAAK;EACvB,GAAG,CAACJ,kBAAA,EAAoBxC,KAAA,CAAMX,cAAc,CAAC;EAE7CvD,KAAA,CAAMyG,SAAS,CAAC,MAAM;IACpB,IAAIjD,IAAA,EAAM;MACRmD,UAAA;IACF,OAAO;MACL,IAAI3B,oBAAA,CAAqBW,OAAO,EAAE;;QAChC;QACA;QACA;QACA;QACA;QACA;QACAK,yBAAA;QAAA,CAAAA,yBAAA,GAAA9B,KAAA,CAAMb,UAAU,CAACsC,OAAO,cAAxBK,yBAAA,uBAAAA,yBAAA,CAA0Bc,KAAA;MAC5B;IACF;IAEA9B,oBAAA,CAAqBW,OAAO,GAAG,KAAK;EACtC,GAAG,CAACzB,KAAA,CAAMb,UAAU,EAAEa,KAAA,CAAM9C,SAAS,EAAEoC,IAAA,EAAMmD,UAAA,CAAW;EAExD,OAAO,CAACnD,IAAA,EAAMC,OAAA,CAAQ;AACxB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { useMenuDivider_unstable } from
|
|
3
|
-
import { useMenuDividerStyles_unstable } from
|
|
4
|
-
import { renderMenuDivider_unstable } from
|
|
5
|
-
import { useCustomStyleHooks_unstable } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useMenuDivider_unstable } from './useMenuDivider';
|
|
3
|
+
import { useMenuDividerStyles_unstable } from './useMenuDividerStyles';
|
|
4
|
+
import { renderMenuDivider_unstable } from './renderMenuDivider';
|
|
5
|
+
import { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts';
|
|
6
6
|
/**
|
|
7
7
|
* Define a styled MenuDivider, using the `useMenuDivider_unstable` hook.
|
|
8
8
|
*/
|
|
@@ -15,5 +15,5 @@ export const MenuDivider = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
15
15
|
useCustomStyles(state);
|
|
16
16
|
return renderMenuDivider_unstable(state);
|
|
17
17
|
});
|
|
18
|
-
MenuDivider.displayName =
|
|
18
|
+
MenuDivider.displayName = 'MenuDivider';
|
|
19
19
|
//# sourceMappingURL=MenuDivider.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from './MenuDivider.types';
|
|
2
|
+
export * from './MenuDivider';
|
|
3
|
+
export * from './renderMenuDivider';
|
|
4
|
+
export * from './useMenuDivider';
|
|
5
|
+
export * from './useMenuDividerStyles';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { getSlots } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { getSlots } from '@fluentui/react-utilities';
|
|
3
3
|
/**
|
|
4
4
|
* Redefine the render function to add slots. Reuse the menudivider structure but add
|
|
5
5
|
* slots to children.
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { getNativeElementProps } from
|
|
2
|
-
import * as React from
|
|
1
|
+
import { getNativeElementProps } from '@fluentui/react-utilities';
|
|
2
|
+
import * as React from 'react';
|
|
3
3
|
/**
|
|
4
4
|
* Given user props, returns state and render function for a MenuDivider.
|
|
5
5
|
*/
|
|
6
6
|
export const useMenuDivider_unstable = (props, ref) => {
|
|
7
7
|
return {
|
|
8
8
|
components: {
|
|
9
|
-
root:
|
|
9
|
+
root: 'div'
|
|
10
10
|
},
|
|
11
|
-
root: getNativeElementProps(
|
|
12
|
-
role:
|
|
13
|
-
|
|
11
|
+
root: getNativeElementProps('div', {
|
|
12
|
+
role: 'presentation',
|
|
13
|
+
'aria-hidden': true,
|
|
14
14
|
...props,
|
|
15
15
|
ref
|
|
16
16
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { shorthands, mergeClasses, __styles } from
|
|
2
|
-
import { tokens } from
|
|
1
|
+
import { shorthands, mergeClasses, __styles } from '@griffel/react';
|
|
2
|
+
import { tokens } from '@fluentui/react-theme';
|
|
3
3
|
export const menuDividerClassNames = {
|
|
4
|
-
root:
|
|
4
|
+
root: 'fui-MenuDivider'
|
|
5
5
|
};
|
|
6
6
|
const useStyles = /*#__PURE__*/__styles({
|
|
7
7
|
root: {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { useMenuGroup_unstable } from
|
|
3
|
-
import { renderMenuGroup_unstable } from
|
|
4
|
-
import { useMenuGroupContextValues_unstable } from
|
|
5
|
-
import { useMenuGroupStyles_unstable } from
|
|
6
|
-
import { useCustomStyleHooks_unstable } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useMenuGroup_unstable } from './useMenuGroup';
|
|
3
|
+
import { renderMenuGroup_unstable } from './renderMenuGroup';
|
|
4
|
+
import { useMenuGroupContextValues_unstable } from './useMenuGroupContextValues';
|
|
5
|
+
import { useMenuGroupStyles_unstable } from './useMenuGroupStyles';
|
|
6
|
+
import { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts';
|
|
7
7
|
/**
|
|
8
8
|
* Define a styled MenuGroup, using the `useMenuGroup_unstable` hook.
|
|
9
9
|
*/
|
|
@@ -17,5 +17,5 @@ export const MenuGroup = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
17
17
|
useCustomStyles(state);
|
|
18
18
|
return renderMenuGroup_unstable(state, contextValues);
|
|
19
19
|
});
|
|
20
|
-
MenuGroup.displayName =
|
|
20
|
+
MenuGroup.displayName = 'MenuGroup';
|
|
21
21
|
//# sourceMappingURL=MenuGroup.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
1
|
+
export * from './MenuGroup.types';
|
|
2
|
+
export * from './MenuGroup';
|
|
3
|
+
export * from './renderMenuGroup';
|
|
4
|
+
export * from './useMenuGroup';
|
|
5
|
+
export * from './useMenuGroupContextValues';
|
|
6
|
+
export * from './useMenuGroupStyles';
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { getSlots } from
|
|
3
|
-
import { MenuGroupContextProvider } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { getSlots } from '@fluentui/react-utilities';
|
|
3
|
+
import { MenuGroupContextProvider } from '../../contexts/menuGroupContext';
|
|
4
4
|
/**
|
|
5
5
|
* Redefine the render function to add slots. Reuse the menugroup structure but add
|
|
6
6
|
* slots to children.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { getNativeElementProps, useId } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { getNativeElementProps, useId } from '@fluentui/react-utilities';
|
|
3
3
|
/**
|
|
4
4
|
* Given user props, returns state and render function for a MenuGroup.
|
|
5
5
|
*/
|
|
6
6
|
export function useMenuGroup_unstable(props, ref) {
|
|
7
|
-
const headerId = useId(
|
|
7
|
+
const headerId = useId('menu-group');
|
|
8
8
|
return {
|
|
9
9
|
components: {
|
|
10
|
-
root:
|
|
10
|
+
root: 'div'
|
|
11
11
|
},
|
|
12
|
-
root: getNativeElementProps(
|
|
12
|
+
root: getNativeElementProps('div', {
|
|
13
13
|
ref,
|
|
14
|
-
|
|
15
|
-
role:
|
|
14
|
+
'aria-labelledby': headerId,
|
|
15
|
+
role: 'group',
|
|
16
16
|
...props
|
|
17
17
|
}),
|
|
18
18
|
headerId
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { mergeClasses } from
|
|
1
|
+
import { mergeClasses } from '@griffel/react';
|
|
2
2
|
export const menuGroupClassNames = {
|
|
3
|
-
root:
|
|
3
|
+
root: 'fui-MenuGroup'
|
|
4
4
|
};
|
|
5
5
|
export const useMenuGroupStyles_unstable = state => {
|
|
6
6
|
state.root.className = mergeClasses(menuGroupClassNames.root, state.root.className);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { useMenuGroupHeader_unstable } from
|
|
3
|
-
import { useMenuGroupHeaderStyles_unstable } from
|
|
4
|
-
import { renderMenuGroupHeader_unstable } from
|
|
5
|
-
import { useCustomStyleHooks_unstable } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useMenuGroupHeader_unstable } from './useMenuGroupHeader';
|
|
3
|
+
import { useMenuGroupHeaderStyles_unstable } from './useMenuGroupHeaderStyles';
|
|
4
|
+
import { renderMenuGroupHeader_unstable } from './renderMenuGroupHeader';
|
|
5
|
+
import { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts';
|
|
6
6
|
/**
|
|
7
7
|
* Define a styled MenuGroupHeader, using the `useMenuGroupHeader_unstable` hook.
|
|
8
8
|
*/
|
|
@@ -15,5 +15,5 @@ export const MenuGroupHeader = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
15
15
|
useCustomStyles(state);
|
|
16
16
|
return renderMenuGroupHeader_unstable(state);
|
|
17
17
|
});
|
|
18
|
-
MenuGroupHeader.displayName =
|
|
18
|
+
MenuGroupHeader.displayName = 'MenuGroupHeader';
|
|
19
19
|
//# sourceMappingURL=MenuGroupHeader.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from './MenuGroupHeader.types';
|
|
2
|
+
export * from './MenuGroupHeader';
|
|
3
|
+
export * from './renderMenuGroupHeader';
|
|
4
|
+
export * from './useMenuGroupHeader';
|
|
5
|
+
export * from './useMenuGroupHeaderStyles';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { getSlots } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { getSlots } from '@fluentui/react-utilities';
|
|
3
3
|
/**
|
|
4
4
|
* Redefine the render function to add slots. Reuse the menugroupheader structure but add
|
|
5
5
|
* slots to children.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { useMenuGroupContext_unstable } from
|
|
3
|
-
import { getNativeElementProps } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useMenuGroupContext_unstable } from '../../contexts/menuGroupContext';
|
|
3
|
+
import { getNativeElementProps } from '@fluentui/react-utilities';
|
|
4
4
|
/**
|
|
5
5
|
* Given user props, returns state and render function for a MenuGroupHeader.
|
|
6
6
|
*/
|
|
@@ -10,9 +10,9 @@ export function useMenuGroupHeader_unstable(props, ref) {
|
|
|
10
10
|
} = useMenuGroupContext_unstable();
|
|
11
11
|
return {
|
|
12
12
|
components: {
|
|
13
|
-
root:
|
|
13
|
+
root: 'div'
|
|
14
14
|
},
|
|
15
|
-
root: getNativeElementProps(
|
|
15
|
+
root: getNativeElementProps('div', {
|
|
16
16
|
ref,
|
|
17
17
|
id,
|
|
18
18
|
...props
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { mergeClasses, __styles } from
|
|
2
|
-
import { tokens } from
|
|
1
|
+
import { mergeClasses, __styles } from '@griffel/react';
|
|
2
|
+
import { tokens } from '@fluentui/react-theme';
|
|
3
3
|
export const menuGroupHeaderClassNames = {
|
|
4
|
-
root:
|
|
4
|
+
root: 'fui-MenuGroupHeader'
|
|
5
5
|
};
|
|
6
6
|
const useStyles = /*#__PURE__*/__styles({
|
|
7
7
|
root: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { useMenuItem_unstable } from
|
|
3
|
-
import { renderMenuItem_unstable } from
|
|
4
|
-
import { useMenuItemStyles_unstable } from
|
|
5
|
-
import { useCustomStyleHooks_unstable } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useMenuItem_unstable } from './useMenuItem';
|
|
3
|
+
import { renderMenuItem_unstable } from './renderMenuItem';
|
|
4
|
+
import { useMenuItemStyles_unstable } from './useMenuItemStyles';
|
|
5
|
+
import { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts';
|
|
6
6
|
/**
|
|
7
7
|
* Define a styled MenuItem, using the `useMenuItem_unstable` and `useMenuItemStyles_unstable` hook.
|
|
8
8
|
*/
|
|
@@ -15,5 +15,5 @@ export const MenuItem = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
15
15
|
useCustomStyles(state);
|
|
16
16
|
return renderMenuItem_unstable(state);
|
|
17
17
|
});
|
|
18
|
-
MenuItem.displayName =
|
|
18
|
+
MenuItem.displayName = 'MenuItem';
|
|
19
19
|
//# sourceMappingURL=MenuItem.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from './MenuItem';
|
|
2
|
+
export * from './MenuItem.types';
|
|
3
|
+
export * from './renderMenuItem';
|
|
4
|
+
export * from './useMenuItem';
|
|
5
|
+
export * from './useMenuItemStyles';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { useMenuListContext_unstable } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useMenuListContext_unstable } from '../../contexts/menuListContext';
|
|
3
3
|
export const useCharacterSearch = (state, ref) => {
|
|
4
4
|
const setFocusByFirstCharacter = useMenuListContext_unstable(context => context.setFocusByFirstCharacter);
|
|
5
5
|
const {
|
|
6
6
|
onKeyDown: originalOnKeyDown
|
|
7
7
|
} = state.root;
|
|
8
8
|
state.root.onKeyDown = e => {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
var _e_key;
|
|
10
|
+
originalOnKeyDown === null || originalOnKeyDown === void 0 ? void 0 : originalOnKeyDown(e);
|
|
11
|
+
if (((_e_key = e.key) === null || _e_key === void 0 ? void 0 : _e_key.length) > 1) {
|
|
11
12
|
return;
|
|
12
13
|
}
|
|
13
14
|
if (ref.current) {
|
|
14
|
-
setFocusByFirstCharacter
|
|
15
|
+
setFocusByFirstCharacter === null || setFocusByFirstCharacter === void 0 ? void 0 : setFocusByFirstCharacter(e, ref.current);
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
return state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useMenuListContext_unstable","useCharacterSearch","state","ref","setFocusByFirstCharacter","context","onKeyDown","originalOnKeyDown","root","e","key","length","current"],"sources":["../../../src/components/MenuItem/useCharacterSearch.ts"],"sourcesContent":["import * as React from 'react';\nimport { useMenuListContext_unstable } from '../../contexts/menuListContext';\nimport type { MenuItemState } from '../../components/index';\nimport type { ARIAButtonElementIntersection } from '@fluentui/react-aria';\n\nexport const useCharacterSearch = (state: MenuItemState, ref: React.RefObject<HTMLElement>) => {\n const setFocusByFirstCharacter = useMenuListContext_unstable(context => context.setFocusByFirstCharacter);\n\n const { onKeyDown: originalOnKeyDown } = state.root;\n\n state.root.onKeyDown = (e: React.KeyboardEvent<ARIAButtonElementIntersection>) => {\n originalOnKeyDown?.(e);\n\n if (e.key?.length > 1) {\n return;\n }\n\n if (ref.current) {\n setFocusByFirstCharacter?.(e, ref.current);\n }\n };\n\n return state;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,2BAA2B,QAAQ;AAI5C,OAAO,MAAMC,kBAAA,GAAqBA,CAACC,KAAA,EAAsBC,GAAA,KAAsC;EAC7F,MAAMC,wBAAA,GAA2BJ,2BAAA,CAA4BK,OAAA,IAAWA,OAAA,CAAQD,wBAAwB;EAExG,MAAM;IAAEE,SAAA,EAAWC;EAAiB,CAAE,GAAGL,KAAA,CAAMM,IAAI;EAEnDN,KAAA,CAAMM,IAAI,CAACF,SAAS,GAAIG,CAAA,IAA0D;
|
|
1
|
+
{"version":3,"names":["React","useMenuListContext_unstable","useCharacterSearch","state","ref","setFocusByFirstCharacter","context","onKeyDown","originalOnKeyDown","root","e","_e_key","key","length","current"],"sources":["../../../src/components/MenuItem/useCharacterSearch.ts"],"sourcesContent":["import * as React from 'react';\nimport { useMenuListContext_unstable } from '../../contexts/menuListContext';\nimport type { MenuItemState } from '../../components/index';\nimport type { ARIAButtonElementIntersection } from '@fluentui/react-aria';\n\nexport const useCharacterSearch = (state: MenuItemState, ref: React.RefObject<HTMLElement>) => {\n const setFocusByFirstCharacter = useMenuListContext_unstable(context => context.setFocusByFirstCharacter);\n\n const { onKeyDown: originalOnKeyDown } = state.root;\n\n state.root.onKeyDown = (e: React.KeyboardEvent<ARIAButtonElementIntersection>) => {\n originalOnKeyDown?.(e);\n\n if (e.key?.length > 1) {\n return;\n }\n\n if (ref.current) {\n setFocusByFirstCharacter?.(e, ref.current);\n }\n };\n\n return state;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,2BAA2B,QAAQ;AAI5C,OAAO,MAAMC,kBAAA,GAAqBA,CAACC,KAAA,EAAsBC,GAAA,KAAsC;EAC7F,MAAMC,wBAAA,GAA2BJ,2BAAA,CAA4BK,OAAA,IAAWA,OAAA,CAAQD,wBAAwB;EAExG,MAAM;IAAEE,SAAA,EAAWC;EAAiB,CAAE,GAAGL,KAAA,CAAMM,IAAI;EAEnDN,KAAA,CAAMM,IAAI,CAACF,SAAS,GAAIG,CAAA,IAA0D;QAG5EC,MAAA;IAFJH,iBAAA,aAAAA,iBAAA,uBAAAA,iBAAA,CAAoBE,CAAA;IAEpB,IAAI,EAAAC,MAAA,GAAAD,CAAA,CAAEE,GAAG,cAALD,MAAA,uBAAAA,MAAA,CAAOE,MAAM,IAAG,GAAG;MACrB;IACF;IAEA,IAAIT,GAAA,CAAIU,OAAO,EAAE;MACfT,wBAAA,aAAAA,wBAAA,uBAAAA,wBAAA,CAA2BK,CAAA,EAAGN,GAAA,CAAIU,OAAO;IAC3C;EACF;EAEA,OAAOX,KAAA;AACT"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { useEventCallback, resolveShorthand, useMergedRefs, getNativeElementProps } from
|
|
3
|
-
import { useFluent_unstable as useFluent } from
|
|
4
|
-
import { useCharacterSearch } from
|
|
5
|
-
import { useMenuTriggerContext_unstable } from
|
|
6
|
-
import { ChevronRightFilled, ChevronRightRegular, ChevronLeftFilled, ChevronLeftRegular, bundleIcon } from
|
|
7
|
-
import { useMenuListContext_unstable } from
|
|
8
|
-
import { useMenuContext_unstable } from
|
|
9
|
-
import { useARIAButtonProps } from
|
|
10
|
-
import { Enter, Space } from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useEventCallback, resolveShorthand, useMergedRefs, getNativeElementProps } from '@fluentui/react-utilities';
|
|
3
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
|
4
|
+
import { useCharacterSearch } from './useCharacterSearch';
|
|
5
|
+
import { useMenuTriggerContext_unstable } from '../../contexts/menuTriggerContext';
|
|
6
|
+
import { ChevronRightFilled, ChevronRightRegular, ChevronLeftFilled, ChevronLeftRegular, bundleIcon } from '@fluentui/react-icons';
|
|
7
|
+
import { useMenuListContext_unstable } from '../../contexts/menuListContext';
|
|
8
|
+
import { useMenuContext_unstable } from '../../contexts/menuContext';
|
|
9
|
+
import { useARIAButtonProps } from '@fluentui/react-aria';
|
|
10
|
+
import { Enter, Space } from '@fluentui/keyboard-keys';
|
|
11
11
|
const ChevronRightIcon = /*#__PURE__*/bundleIcon(ChevronRightFilled, ChevronRightRegular);
|
|
12
12
|
const ChevronLeftIcon = /*#__PURE__*/bundleIcon(ChevronLeftFilled, ChevronLeftRegular);
|
|
13
13
|
/**
|
|
@@ -17,7 +17,7 @@ export const useMenuItem_unstable = (props, ref) => {
|
|
|
17
17
|
const isSubmenuTrigger = useMenuTriggerContext_unstable();
|
|
18
18
|
const persistOnClickContext = useMenuContext_unstable(context => context.persistOnItemClick);
|
|
19
19
|
const {
|
|
20
|
-
as =
|
|
20
|
+
as = 'div',
|
|
21
21
|
disabled = false,
|
|
22
22
|
hasSubmenu = isSubmenuTrigger,
|
|
23
23
|
persistOnClick = persistOnClickContext
|
|
@@ -35,41 +35,44 @@ export const useMenuItem_unstable = (props, ref) => {
|
|
|
35
35
|
disabled,
|
|
36
36
|
persistOnClick,
|
|
37
37
|
components: {
|
|
38
|
-
root:
|
|
39
|
-
icon:
|
|
40
|
-
checkmark:
|
|
41
|
-
submenuIndicator:
|
|
42
|
-
content:
|
|
43
|
-
secondaryContent:
|
|
38
|
+
root: 'div',
|
|
39
|
+
icon: 'span',
|
|
40
|
+
checkmark: 'span',
|
|
41
|
+
submenuIndicator: 'span',
|
|
42
|
+
content: 'span',
|
|
43
|
+
secondaryContent: 'span'
|
|
44
44
|
},
|
|
45
45
|
root: getNativeElementProps(as, useARIAButtonProps(as, {
|
|
46
|
-
role:
|
|
46
|
+
role: 'menuitem',
|
|
47
47
|
...props,
|
|
48
48
|
disabled: false,
|
|
49
49
|
disabledFocusable: disabled,
|
|
50
50
|
ref: useMergedRefs(ref, innerRef),
|
|
51
51
|
onKeyDown: useEventCallback(event => {
|
|
52
|
-
|
|
52
|
+
var _props_onKeyDown;
|
|
53
|
+
(_props_onKeyDown = props.onKeyDown) === null || _props_onKeyDown === void 0 ? void 0 : _props_onKeyDown.call(props, event);
|
|
53
54
|
if (!event.isDefaultPrevented() && (event.key === Space || event.key === Enter)) {
|
|
54
55
|
dismissedWithKeyboardRef.current = true;
|
|
55
56
|
}
|
|
56
57
|
}),
|
|
57
58
|
onMouseEnter: useEventCallback(event => {
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
var _innerRef_current, _props_onMouseEnter;
|
|
60
|
+
(_innerRef_current = innerRef.current) === null || _innerRef_current === void 0 ? void 0 : _innerRef_current.focus();
|
|
61
|
+
(_props_onMouseEnter = props.onMouseEnter) === null || _props_onMouseEnter === void 0 ? void 0 : _props_onMouseEnter.call(props, event);
|
|
60
62
|
}),
|
|
61
63
|
onClick: useEventCallback(event => {
|
|
64
|
+
var _props_onClick;
|
|
62
65
|
if (!hasSubmenu && !persistOnClick) {
|
|
63
66
|
setOpen(event, {
|
|
64
67
|
open: false,
|
|
65
68
|
keyboard: dismissedWithKeyboardRef.current,
|
|
66
69
|
bubble: true,
|
|
67
|
-
type:
|
|
70
|
+
type: 'menuItemClick',
|
|
68
71
|
event
|
|
69
72
|
});
|
|
70
73
|
dismissedWithKeyboardRef.current = false;
|
|
71
74
|
}
|
|
72
|
-
props.onClick
|
|
75
|
+
(_props_onClick = props.onClick) === null || _props_onClick === void 0 ? void 0 : _props_onClick.call(props, event);
|
|
73
76
|
})
|
|
74
77
|
})),
|
|
75
78
|
icon: resolveShorthand(props.icon, {
|
|
@@ -81,7 +84,7 @@ export const useMenuItem_unstable = (props, ref) => {
|
|
|
81
84
|
submenuIndicator: resolveShorthand(props.submenuIndicator, {
|
|
82
85
|
required: hasSubmenu,
|
|
83
86
|
defaultProps: {
|
|
84
|
-
children: dir ===
|
|
87
|
+
children: dir === 'ltr' ? /*#__PURE__*/React.createElement(ChevronRightIcon, null) : /*#__PURE__*/React.createElement(ChevronLeftIcon, null)
|
|
85
88
|
}
|
|
86
89
|
}),
|
|
87
90
|
content: resolveShorthand(props.content, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useEventCallback","resolveShorthand","useMergedRefs","getNativeElementProps","useFluent_unstable","useFluent","useCharacterSearch","useMenuTriggerContext_unstable","ChevronRightFilled","ChevronRightRegular","ChevronLeftFilled","ChevronLeftRegular","bundleIcon","useMenuListContext_unstable","useMenuContext_unstable","useARIAButtonProps","Enter","Space","ChevronRightIcon","ChevronLeftIcon","useMenuItem_unstable","props","ref","isSubmenuTrigger","persistOnClickContext","context","persistOnItemClick","as","disabled","hasSubmenu","persistOnClick","hasIcons","hasCheckmarks","setOpen","dir","innerRef","useRef","dismissedWithKeyboardRef","state","components","root","icon","checkmark","submenuIndicator","content","secondaryContent","role","disabledFocusable","onKeyDown","event","isDefaultPrevented","key","current","onMouseEnter","focus","onClick","open","keyboard","bubble","type","required","defaultProps","children","createElement"],"sources":["../../../src/components/MenuItem/useMenuItem.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback, resolveShorthand, useMergedRefs, getNativeElementProps } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useCharacterSearch } from './useCharacterSearch';\nimport { useMenuTriggerContext_unstable } from '../../contexts/menuTriggerContext';\nimport {\n ChevronRightFilled,\n ChevronRightRegular,\n ChevronLeftFilled,\n ChevronLeftRegular,\n bundleIcon,\n} from '@fluentui/react-icons';\nimport { useMenuListContext_unstable } from '../../contexts/menuListContext';\nimport { useMenuContext_unstable } from '../../contexts/menuContext';\nimport type { MenuItemProps, MenuItemState } from './MenuItem.types';\nimport { ARIAButtonElement, ARIAButtonElementIntersection, useARIAButtonProps } from '@fluentui/react-aria';\nimport { Enter, Space } from '@fluentui/keyboard-keys';\n\nconst ChevronRightIcon = bundleIcon(ChevronRightFilled, ChevronRightRegular);\nconst ChevronLeftIcon = bundleIcon(ChevronLeftFilled, ChevronLeftRegular);\n\n/**\n * Returns the props and state required to render the component\n */\nexport const useMenuItem_unstable = (props: MenuItemProps, ref: React.Ref<ARIAButtonElement<'div'>>): MenuItemState => {\n const isSubmenuTrigger = useMenuTriggerContext_unstable();\n const persistOnClickContext = useMenuContext_unstable(context => context.persistOnItemClick);\n const { as = 'div', disabled = false, hasSubmenu = isSubmenuTrigger, persistOnClick = persistOnClickContext } = props;\n const hasIcons = useMenuListContext_unstable(context => context.hasIcons);\n const hasCheckmarks = useMenuListContext_unstable(context => context.hasCheckmarks);\n const setOpen = useMenuContext_unstable(context => context.setOpen);\n\n const { dir } = useFluent();\n const innerRef = React.useRef<ARIAButtonElementIntersection<'div'>>(null);\n const dismissedWithKeyboardRef = React.useRef(false);\n\n const state: MenuItemState = {\n hasSubmenu,\n disabled,\n persistOnClick,\n components: {\n root: 'div',\n icon: 'span',\n checkmark: 'span',\n submenuIndicator: 'span',\n content: 'span',\n secondaryContent: 'span',\n },\n root: getNativeElementProps(\n as,\n useARIAButtonProps(as, {\n role: 'menuitem',\n ...props,\n disabled: false,\n disabledFocusable: disabled,\n ref: useMergedRefs(ref, innerRef) as React.Ref<ARIAButtonElementIntersection<'div'>>,\n onKeyDown: useEventCallback(event => {\n props.onKeyDown?.(event);\n if (!event.isDefaultPrevented() && (event.key === Space || event.key === Enter)) {\n dismissedWithKeyboardRef.current = true;\n }\n }),\n onMouseEnter: useEventCallback(event => {\n innerRef.current?.focus();\n\n props.onMouseEnter?.(event);\n }),\n onClick: useEventCallback(event => {\n if (!hasSubmenu && !persistOnClick) {\n setOpen(event, {\n open: false,\n keyboard: dismissedWithKeyboardRef.current,\n bubble: true,\n type: 'menuItemClick',\n event,\n });\n dismissedWithKeyboardRef.current = false;\n }\n\n props.onClick?.(event);\n }),\n }),\n ),\n icon: resolveShorthand(props.icon, { required: hasIcons }),\n checkmark: resolveShorthand(props.checkmark, { required: hasCheckmarks }),\n submenuIndicator: resolveShorthand(props.submenuIndicator, {\n required: hasSubmenu,\n defaultProps: {\n children: dir === 'ltr' ? <ChevronRightIcon /> : <ChevronLeftIcon />,\n },\n }),\n content: resolveShorthand(props.content, {\n required: !!props.children,\n defaultProps: { children: props.children },\n }),\n secondaryContent: resolveShorthand(props.secondaryContent),\n };\n useCharacterSearch(state, innerRef);\n return state;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,gBAAgB,EAAEC,gBAAgB,EAAEC,aAAa,EAAEC,qBAAqB,QAAQ;AACzF,SAASC,kBAAA,IAAsBC,SAAS,QAAQ;AAChD,SAASC,kBAAkB,QAAQ;AACnC,SAASC,8BAA8B,QAAQ;AAC/C,SACEC,kBAAkB,EAClBC,mBAAmB,EACnBC,iBAAiB,EACjBC,kBAAkB,EAClBC,UAAU,QACL;AACP,SAASC,2BAA2B,QAAQ;AAC5C,SAASC,uBAAuB,QAAQ;AAExC,SAA2DC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B,KAAK;MACRO,QAAA,EAAU,KAAK;MACfmB,iBAAA,EAAmBnB,QAAA;MACnBN,GAAA,EAAKpB,aAAA,CAAcoB,GAAA,EAAKa,QAAA;MACxBa,SAAA,EAAWhD,gBAAA,CAAiBiD,KAAA,IAAS;
|
|
1
|
+
{"version":3,"names":["React","useEventCallback","resolveShorthand","useMergedRefs","getNativeElementProps","useFluent_unstable","useFluent","useCharacterSearch","useMenuTriggerContext_unstable","ChevronRightFilled","ChevronRightRegular","ChevronLeftFilled","ChevronLeftRegular","bundleIcon","useMenuListContext_unstable","useMenuContext_unstable","useARIAButtonProps","Enter","Space","ChevronRightIcon","ChevronLeftIcon","useMenuItem_unstable","props","ref","isSubmenuTrigger","persistOnClickContext","context","persistOnItemClick","as","disabled","hasSubmenu","persistOnClick","hasIcons","hasCheckmarks","setOpen","dir","innerRef","useRef","dismissedWithKeyboardRef","state","components","root","icon","checkmark","submenuIndicator","content","secondaryContent","role","disabledFocusable","onKeyDown","event","_props_onKeyDown","call","isDefaultPrevented","key","current","onMouseEnter","_innerRef_current","_props_onMouseEnter","focus","onClick","_props_onClick","open","keyboard","bubble","type","required","defaultProps","children","createElement"],"sources":["../../../src/components/MenuItem/useMenuItem.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback, resolveShorthand, useMergedRefs, getNativeElementProps } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useCharacterSearch } from './useCharacterSearch';\nimport { useMenuTriggerContext_unstable } from '../../contexts/menuTriggerContext';\nimport {\n ChevronRightFilled,\n ChevronRightRegular,\n ChevronLeftFilled,\n ChevronLeftRegular,\n bundleIcon,\n} from '@fluentui/react-icons';\nimport { useMenuListContext_unstable } from '../../contexts/menuListContext';\nimport { useMenuContext_unstable } from '../../contexts/menuContext';\nimport type { MenuItemProps, MenuItemState } from './MenuItem.types';\nimport { ARIAButtonElement, ARIAButtonElementIntersection, useARIAButtonProps } from '@fluentui/react-aria';\nimport { Enter, Space } from '@fluentui/keyboard-keys';\n\nconst ChevronRightIcon = bundleIcon(ChevronRightFilled, ChevronRightRegular);\nconst ChevronLeftIcon = bundleIcon(ChevronLeftFilled, ChevronLeftRegular);\n\n/**\n * Returns the props and state required to render the component\n */\nexport const useMenuItem_unstable = (props: MenuItemProps, ref: React.Ref<ARIAButtonElement<'div'>>): MenuItemState => {\n const isSubmenuTrigger = useMenuTriggerContext_unstable();\n const persistOnClickContext = useMenuContext_unstable(context => context.persistOnItemClick);\n const { as = 'div', disabled = false, hasSubmenu = isSubmenuTrigger, persistOnClick = persistOnClickContext } = props;\n const hasIcons = useMenuListContext_unstable(context => context.hasIcons);\n const hasCheckmarks = useMenuListContext_unstable(context => context.hasCheckmarks);\n const setOpen = useMenuContext_unstable(context => context.setOpen);\n\n const { dir } = useFluent();\n const innerRef = React.useRef<ARIAButtonElementIntersection<'div'>>(null);\n const dismissedWithKeyboardRef = React.useRef(false);\n\n const state: MenuItemState = {\n hasSubmenu,\n disabled,\n persistOnClick,\n components: {\n root: 'div',\n icon: 'span',\n checkmark: 'span',\n submenuIndicator: 'span',\n content: 'span',\n secondaryContent: 'span',\n },\n root: getNativeElementProps(\n as,\n useARIAButtonProps(as, {\n role: 'menuitem',\n ...props,\n disabled: false,\n disabledFocusable: disabled,\n ref: useMergedRefs(ref, innerRef) as React.Ref<ARIAButtonElementIntersection<'div'>>,\n onKeyDown: useEventCallback(event => {\n props.onKeyDown?.(event);\n if (!event.isDefaultPrevented() && (event.key === Space || event.key === Enter)) {\n dismissedWithKeyboardRef.current = true;\n }\n }),\n onMouseEnter: useEventCallback(event => {\n innerRef.current?.focus();\n\n props.onMouseEnter?.(event);\n }),\n onClick: useEventCallback(event => {\n if (!hasSubmenu && !persistOnClick) {\n setOpen(event, {\n open: false,\n keyboard: dismissedWithKeyboardRef.current,\n bubble: true,\n type: 'menuItemClick',\n event,\n });\n dismissedWithKeyboardRef.current = false;\n }\n\n props.onClick?.(event);\n }),\n }),\n ),\n icon: resolveShorthand(props.icon, { required: hasIcons }),\n checkmark: resolveShorthand(props.checkmark, { required: hasCheckmarks }),\n submenuIndicator: resolveShorthand(props.submenuIndicator, {\n required: hasSubmenu,\n defaultProps: {\n children: dir === 'ltr' ? <ChevronRightIcon /> : <ChevronLeftIcon />,\n },\n }),\n content: resolveShorthand(props.content, {\n required: !!props.children,\n defaultProps: { children: props.children },\n }),\n secondaryContent: resolveShorthand(props.secondaryContent),\n };\n useCharacterSearch(state, innerRef);\n return state;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,gBAAgB,EAAEC,gBAAgB,EAAEC,aAAa,EAAEC,qBAAqB,QAAQ;AACzF,SAASC,kBAAA,IAAsBC,SAAS,QAAQ;AAChD,SAASC,kBAAkB,QAAQ;AACnC,SAASC,8BAA8B,QAAQ;AAC/C,SACEC,kBAAkB,EAClBC,mBAAmB,EACnBC,iBAAiB,EACjBC,kBAAkB,EAClBC,UAAU,QACL;AACP,SAASC,2BAA2B,QAAQ;AAC5C,SAASC,uBAAuB,QAAQ;AAExC,SAA2DC,kBAAkB,QAAQ;AACrF,SAASC,KAAK,EAAEC,KAAK,QAAQ;AAE7B,MAAMC,gBAAA,gBAAmBN,UAAA,CAAWJ,kBAAA,EAAoBC,mBAAA;AACxD,MAAMU,eAAA,gBAAkBP,UAAA,CAAWF,iBAAA,EAAmBC,kBAAA;AAEtD;;;AAGA,OAAO,MAAMS,oBAAA,GAAuBA,CAACC,KAAA,EAAsBC,GAAA,KAA4D;EACrH,MAAMC,gBAAA,GAAmBhB,8BAAA;EACzB,MAAMiB,qBAAA,GAAwBV,uBAAA,CAAwBW,OAAA,IAAWA,OAAA,CAAQC,kBAAkB;EAC3F,MAAM;IAAEC,EAAA,GAAK;IAAOC,QAAA,GAAW,KAAK;IAAEC,UAAA,GAAaN,gBAAA;IAAkBO,cAAA,GAAiBN;EAAqB,CAAE,GAAGH,KAAA;EAChH,MAAMU,QAAA,GAAWlB,2BAAA,C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