npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@commercetools-uikit/dropdown-menu

v19.16.0

Published

The Dropdown Menu component represents a component that triggers the rendering of a floating menu.

Downloads

17,150

Readme

DropdownMenu

Description

This component should be used whenever you need to display a floating panel after clicking on an element.

It allows to use any component as the element used to trigger the floating panel.

The panel can be customized to render whatever is needed. However, as a common use case would be to render a list of elements and select one of them, this component provides some helpers to easily implement such use case.

Something to bear in mind is that, when the panel is open, the document scroll is blocked.

Installation

yarn add @commercetools-uikit/dropdown-menu
npm --save install @commercetools-uikit/dropdown-menu

Additionally install the peer dependencies (if not present)

yarn add react
npm --save install react

Usage

import CheckboxInput from '@commercetools-uikit/checkbox-input';
import DropdownMenu from '@commercetools-uikit/dropdown-menu';
import IconButton from '@commercetools-uikit/icon-button';
import SecondaryButton from '@commercetools-uikit/secondary-button';
import SpacingsStack from '@commercetools-uikit/spacings-stack';
import Text from '@commercetools-uikit/text';
import { ColumnsIcon, FilterIcon } from '@commercetools-uikit/icons';

export const ListDropdownExample = () => {
  return (
    <DropdownMenu
      triggerElement={<IconButton icon={<ColumnsIcon />} label="list" />}
      menuHorizontalConstraint={6}
      menuPosition="left"
      menuType="list"
    >
      <DropdownMenu.ListMenuItem onClick={() => {}}>
        Option 1
      </DropdownMenu.ListMenuItem>
      <DropdownMenu.ListMenuItem onClick={() => {}} isDisabled>
        Option 2
      </DropdownMenu.ListMenuItem>
      <DropdownMenu.ListMenuItem onClick={() => {}}>
        Option 3
      </DropdownMenu.ListMenuItem>
    </DropdownMenu>
  );
};

export const CustomDropdownExample = () => {
  return (
    <DropdownMenu
      triggerElement={
        <SecondaryButton label="Filters" iconLeft={<FilterIcon />} />
      }
      menuHorizontalConstraint={6}
      menuPosition="right"
    >
      <SpacingsStack scale="m">
        <Text.Body>Store</Text.Body>
        <CheckboxInput isChecked value="store" onChange={(event) => {}}>
          Canada (FR)
        </CheckboxInput>
      </SpacingsStack>
    </DropdownMenu>
  );
};

Properties

| Props | Type | Required | Default | Description | | -------------------------- | ----------------------------------------------------- | :------: | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | menuPosition | unionPossible values:'left' , 'right' | | 'left' | The position of the menu relative to the trigger element. | | menuMaxHeight | number | | | The maximum height for the menu in pixels. By default, the max height will be the available space between the trigger element and the bottom of the viewport. | | triggerElement | ReactElement | ✅ | | The element that triggers the dropdown. | | menuType | unionPossible values:'default' , 'list' | | 'default' | The type of the menu. The 'default' type just renders a dropdown container but the 'list' type is intended to be used with the DropdownMenu.ListMenuItem component. | | menuHorizontalConstraint | TMaxProp | | 'auto' | The horizontal constraint of the menu. | | children | ReactNode | ✅ | | The content of the dropdown. |

Additional info

ListMenuItem

When using the list floating panel, the DropdownMenu component exposes an inner sub-component called DropdownMenu.ListMenuItem that should be used to render each item in the list.

Clicking on an item will close the panel and call the onClick callback with the item's value.

Properties

| Props | Type | Required | Default | Description | | ------------ | ------------ | :------: | ------- | ------------------------------------------------- | | isDisabled | boolean | | false | Whether the item should be disabled. | | onClick | () => void | | | A callback to be called when the item is clicked. | | children | string | ✅ | | The label for the item. |