Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zendeskgarden/container-menu

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zendeskgarden/container-menu

Containers relating to Menu in the Garden Design System

  • 0.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@zendeskgarden/container-menu npm version

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.

useMenu

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>
    </>
  );
};

MenuContainer

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', href: '#0' },
    { value: 'value-4', label: 'Four' }
  ];

  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 =>
              item.href ? (
                <li key={item.value} role="none">
                  <a {...getItemProps({ item })}>{item.label}</a>
                </li>
              ) : (
                <li key={item.value} {...getItemProps({ item })}>
                  {item.label}
                </li>
              )
            )}
          </ul>
        </>
      )}
    </MenuContainer>
  );
};

Keywords

FAQs

Package last updated on 25 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc