UNPKG

@wordpress/components

Version:
62 lines (61 loc) • 1.69 kB
import { check } from "@wordpress/icons"; import MenuItem from "../menu-item/index.mjs"; import { Fragment, jsx } from "react/jsx-runtime"; // packages/components/src/menu-items-choice/index.tsx const noop = () => {}; /** * `MenuItemsChoice` functions similarly to a set of `MenuItem`s, but allows the user to select one option from a set of multiple choices. * * * ```jsx * import { MenuGroup, MenuItemsChoice } from '@wordpress/components'; * import { useState } from '@wordpress/element'; * * const MyMenuItemsChoice = () => { * const [ mode, setMode ] = useState( 'visual' ); * const choices = [ * { * value: 'visual', * label: 'Visual editor', * }, * { * value: 'text', * label: 'Code editor', * }, * ]; * * return ( * <MenuGroup label="Editor"> * <MenuItemsChoice * choices={ choices } * value={ mode } * onSelect={ ( newMode ) => setMode( newMode ) } * /> * </MenuGroup> * ); * }; * ``` */ function MenuItemsChoice({ choices = [], onHover = noop, onSelect, value }) { return /* @__PURE__ */ jsx(Fragment, { children: choices.map((item) => { const isSelected = value === item.value; return /* @__PURE__ */ jsx(MenuItem, { role: "menuitemradio", disabled: item.disabled, icon: isSelected ? check : null, info: item.info, isSelected, shortcut: item.shortcut, className: "components-menu-items-choice", onClick: () => { if (!isSelected) onSelect(item.value); }, onMouseEnter: () => onHover(item.value), onMouseLeave: () => onHover(null), "aria-label": item["aria-label"], children: item.label }, item.value); }) }); } export { MenuItemsChoice as default }; //# sourceMappingURL=index.mjs.map