This package includes containers relating to Menu in the
Garden Design System.
Installation
npm install @zendeskgarden/container-menu
Usage
Check out storybook for live examples.
import { useMenu } from '@zendeskgarden/container-menu';
const Menu = () => {
const triggerRef = useRef();
const menuRef = useRef();
const items = [
{ value: 'value-1', label: 'One' },
{ value: 'value-2', label: 'Two' },
{ value: 'value-3', label: 'Three' }
];
const { isExpanded, getTriggerProps, getMenuProps, getItemProps, getSeparatorProps } = useMenu({
triggerRef,
menuRef,
items
});
return (
<>
<button {...getTriggerProps()}>Menu</button>
<ul {...getMenuProps()} style={{ visibility: isExpanded ? 'visible' : 'hidden' }}>
{items.map(item => (
<li key={item.value} {...getItemProps({ item })}>
{item.label}
</li>
))}
</ul>
</>
);
};
import { MenuContainer } from '@zendeskgarden/container-menu';
const Menu = () => {
const triggerRef = useRef();
const menuRef = useRef();
const items = [
{ value: 'value-1', label: 'One' },
{ value: 'value-2', label: 'Two' },
{ value: 'value-3', label: 'Three' }
];
return (
<MenuContainer triggerRef={triggerRef} menuRef={menuRef} items={items}>
{({ isExpanded, getTriggerProps, getMenuProps, getItemProps, getSeparatorProps }) => (
<>
<button {...getTriggerProps()}>Menu</button>
<ul {...getMenuProps()} style={{ visibility: isExpanded ? 'visible' : 'hidden' }}>
{items.map(item => (
<li key={item.value} {...getItemProps({ item })}>
{item.label}
</li>
))}
</ul>
</>
)}
</MenuContainer>
);
};