@wordpress/components
Version:
UI components for WordPress.
1 lines • 8.71 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","names":["useContextSystem","useContext","Context","isRTLFn","Ariakit","useMemo","contextConnectWithoutRef","Item","RadioItem","CheckboxItem","Group","GroupLabel","Separator","ItemLabel","ItemHelpText","Popover","TriggerButton","SubmenuTriggerItem"],"sources":["../../src/menu/index.tsx"],"sourcesContent":["import * as Ariakit from '@ariakit/react';\nimport { useContext, useMemo } from '@wordpress/element';\nimport { isRTL as isRTLFn } from '@wordpress/i18n';\nimport { useContextSystem, contextConnectWithoutRef } from '../context';\nimport type { ContextProps, Props } from './types';\nimport { Context } from './context';\nimport { Item } from './item';\nimport { CheckboxItem } from './checkbox-item';\nimport { RadioItem } from './radio-item';\nimport { Group } from './group';\nimport { GroupLabel } from './group-label';\nimport { Separator } from './separator';\nimport { ItemLabel } from './item-label';\nimport { ItemHelpText } from './item-help-text';\nimport { TriggerButton } from './trigger-button';\nimport { SubmenuTriggerItem } from './submenu-trigger-item';\nimport { Popover } from './popover';\n\nconst UnconnectedMenu = ( props: Props ) => {\n\tconst {\n\t\tchildren,\n\t\tdefaultOpen = false,\n\t\topen,\n\t\tonOpenChange,\n\t\tplacement,\n\n\t\t// From internal components context\n\t\tvariant,\n\t} = useContextSystem<\n\t\t// @ts-expect-error TODO: missing 'className' in MenuProps\n\t\ttypeof props & Pick< ContextProps, 'variant' >\n\t>( props, 'Menu' );\n\n\tconst parentContext = useContext( Context );\n\n\tconst rtl = isRTLFn();\n\n\t// If an explicit value for the `placement` prop is not passed,\n\t// apply a default placement of `bottom-start` for the root menu popover,\n\t// and of `right-start` for nested menu popovers.\n\tlet computedPlacement =\n\t\tplacement ?? ( parentContext?.store ? 'right-start' : 'bottom-start' );\n\t// Swap left/right in case of RTL direction\n\tif ( rtl ) {\n\t\tif ( /right/.test( computedPlacement ) ) {\n\t\t\tcomputedPlacement = computedPlacement.replace(\n\t\t\t\t'right',\n\t\t\t\t'left'\n\t\t\t) as typeof computedPlacement;\n\t\t} else if ( /left/.test( computedPlacement ) ) {\n\t\t\tcomputedPlacement = computedPlacement.replace(\n\t\t\t\t'left',\n\t\t\t\t'right'\n\t\t\t) as typeof computedPlacement;\n\t\t}\n\t}\n\n\tconst menuStore = Ariakit.useMenuStore( {\n\t\tparent: parentContext?.store,\n\t\topen,\n\t\tdefaultOpen,\n\t\tplacement: computedPlacement,\n\t\tfocusLoop: true,\n\t\tsetOpen( willBeOpen ) {\n\t\t\tonOpenChange?.( willBeOpen );\n\t\t},\n\t\trtl,\n\t} );\n\n\tconst contextValue = useMemo(\n\t\t() => ( { store: menuStore, variant } ),\n\t\t[ menuStore, variant ]\n\t);\n\n\treturn (\n\t\t<Context.Provider value={ contextValue }>{ children }</Context.Provider>\n\t);\n};\n\n/**\n * Menu is a collection of React components that combine to render\n * ARIA-compliant [menu](https://www.w3.org/WAI/ARIA/apg/patterns/menu/) and\n * [menu button](https://www.w3.org/WAI/ARIA/apg/patterns/menubutton/) patterns.\n *\n * `Menu` itself is a wrapper component and context provider.\n * It is responsible for managing the state of the menu and its items, and for\n * rendering the `Menu.TriggerButton` (or the `Menu.SubmenuTriggerItem`)\n * component, and the `Menu.Popover` component.\n *\n * This component is deprecated. When building for the Gutenberg repo, use `Menu` from `@wordpress/ui` instead. Otherwise, continue using `DropdownMenu` for now.\n *\n * @deprecated\n */\nexport const Menu = Object.assign(\n\tcontextConnectWithoutRef( UnconnectedMenu, 'Menu' ),\n\t{\n\t\tContext: Object.assign( Context, {\n\t\t\tdisplayName: 'Menu.Context',\n\t\t} ),\n\t\t/**\n\t\t * Renders a menu item inside the `Menu.Popover` or `Menu.Group` components.\n\t\t *\n\t\t * It can optionally contain one instance of the `Menu.ItemLabel` component\n\t\t * and one instance of the `Menu.ItemHelpText` component.\n\t\t */\n\t\tItem: Object.assign( Item, {\n\t\t\tdisplayName: 'Menu.Item',\n\t\t} ),\n\t\t/**\n\t\t * Renders a radio menu item inside the `Menu.Popover` or `Menu.Group`\n\t\t * components.\n\t\t *\n\t\t * It can optionally contain one instance of the `Menu.ItemLabel` component\n\t\t * and one instance of the `Menu.ItemHelpText` component.\n\t\t */\n\t\tRadioItem: Object.assign( RadioItem, {\n\t\t\tdisplayName: 'Menu.RadioItem',\n\t\t} ),\n\t\t/**\n\t\t * Renders a checkbox menu item inside the `Menu.Popover` or `Menu.Group`\n\t\t * components.\n\t\t *\n\t\t * It can optionally contain one instance of the `Menu.ItemLabel` component\n\t\t * and one instance of the `Menu.ItemHelpText` component.\n\t\t */\n\t\tCheckboxItem: Object.assign( CheckboxItem, {\n\t\t\tdisplayName: 'Menu.CheckboxItem',\n\t\t} ),\n\t\t/**\n\t\t * Renders a group for menu items.\n\t\t *\n\t\t * It should contain one instance of `Menu.GroupLabel` and one or more\n\t\t * instances of `Menu.Item`, `Menu.RadioItem`, or `Menu.CheckboxItem`.\n\t\t */\n\t\tGroup: Object.assign( Group, {\n\t\t\tdisplayName: 'Menu.Group',\n\t\t} ),\n\t\t/**\n\t\t * Renders a label in a menu group.\n\t\t *\n\t\t * This component should be wrapped with `Menu.Group` so the\n\t\t * `aria-labelledby` is correctly set on the group element.\n\t\t */\n\t\tGroupLabel: Object.assign( GroupLabel, {\n\t\t\tdisplayName: 'Menu.GroupLabel',\n\t\t} ),\n\t\t/**\n\t\t * Renders a divider between menu items or menu groups.\n\t\t */\n\t\tSeparator: Object.assign( Separator, {\n\t\t\tdisplayName: 'Menu.Separator',\n\t\t} ),\n\t\t/**\n\t\t * Renders a menu item's label text. It should be wrapped with `Menu.Item`,\n\t\t * `Menu.RadioItem`, or `Menu.CheckboxItem`.\n\t\t */\n\t\tItemLabel: Object.assign( ItemLabel, {\n\t\t\tdisplayName: 'Menu.ItemLabel',\n\t\t} ),\n\t\t/**\n\t\t * Renders a menu item's help text. It should be wrapped with `Menu.Item`,\n\t\t * `Menu.RadioItem`, or `Menu.CheckboxItem`.\n\t\t */\n\t\tItemHelpText: Object.assign( ItemHelpText, {\n\t\t\tdisplayName: 'Menu.ItemHelpText',\n\t\t} ),\n\t\t/**\n\t\t * Renders a dropdown menu element that's controlled by a sibling\n\t\t * `Menu.TriggerButton` component. It renders a popover and automatically\n\t\t * focuses on items when the menu is shown.\n\t\t *\n\t\t * The only valid children of `Menu.Popover` are `Menu.Item`,\n\t\t * `Menu.RadioItem`, `Menu.CheckboxItem`, `Menu.Group`, `Menu.Separator`,\n\t\t * and `Menu` (for nested dropdown menus).\n\t\t */\n\t\tPopover: Object.assign( Popover, {\n\t\t\tdisplayName: 'Menu.Popover',\n\t\t} ),\n\t\t/**\n\t\t * Renders a menu button that toggles the visibility of a sibling\n\t\t * `Menu.Popover` component when clicked or when using arrow keys.\n\t\t */\n\t\tTriggerButton: Object.assign( TriggerButton, {\n\t\t\tdisplayName: 'Menu.TriggerButton',\n\t\t} ),\n\t\t/**\n\t\t * Renders a menu item that toggles the visibility of a sibling\n\t\t * `Menu.Popover` component when clicked or when using arrow keys.\n\t\t *\n\t\t * This component is used to create a nested dropdown menu.\n\t\t */\n\t\tSubmenuTriggerItem: Object.assign( SubmenuTriggerItem, {\n\t\t\tdisplayName: 'Menu.SubmenuTriggerItem',\n\t\t} ),\n\t}\n);\n\nexport default Menu;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,mBAAoB,UAAkB;CAC3C,MAAM,EACL,UACA,cAAc,OACd,MACA,cACA,WAGA,aAAA,GACGA,oBAAAA,iBAAAA,CAGD,OAAO,MAAO;CAEjB,MAAM,iBAAA,GAAgBC,mBAAAA,WAAAA,CAAYC,cAAAA,OAAQ;CAE1C,MAAM,OAAA,GAAMC,gBAAAA,MAAAA,CAAQ;CAKpB,IAAI,oBACH,cAAe,eAAe,QAAQ,gBAAgB;CAEvD,IAAK,KAAM;EACV,IAAK,QAAQ,KAAM,iBAAkB,GACpC,oBAAoB,kBAAkB,QACrC,SACA,MACD;OACM,IAAK,OAAO,KAAM,iBAAkB,GAC1C,oBAA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