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

react-dropdown-button

v1.0.11

Published

A carefully crafted drop-down button for React

Downloads

91

Readme

react-dropdown-button

A carefully crafted drop-down button for React

See drop-down demo.

Install

$ npm install react-dropdown-button --save

Description

The drop-down button uses two other React components:

It smartly places the drop-down menu to fit into the document. You can customize how the menu is aligned to the button. With one function, you can respond to a click in the menu at any nesting level.

Worth trying out, see the demo page.

Changelog

See Changelog

Usage


var DDButton = require('react-dropdown-button')

var saveItems = [
	{
		label: 'PDF'
	},
	'-', // a separator
	{
		label: '.DOCX'
	},
	{
		label: 'ODF',
		onClick: function(){
			console.log('save as ODF')
		}
	}
]

function onClick(event, itemProps){
	console.log('You clicked: ' + itemProps.data.label +
	 ' at index ' + itemProps.index)
}

<DDButton items={saveItems} onChildClick={onClick}>
	Save as
</DDButton>

Also see zippyui/react-button

Props

You have the same props as for the react-button, so see docs. Besides the button specific props, you can specify the items prop as an array of objects to be passed to the menu component.

  • items: Array - an array of menu items for the menu of this drop-down button

  • menuProps: Object - props to be passed to the menu component

  • menu: ReactElement - instead of menuProps, you can directly pass in a menu instance

  • onMenuClick: Function(event, itemProps) - called when a menu item, at any nesting level has been clicked.

    Takes the following args:

    • event - The click event
    • itemProps - an object which represents the props with which the menu item has been rendered. You can check itemProps.index to take the index of the item in it's parent menu. If the drop-down button has been given a items array, the itemProps object also has a data property, which is the item object.

Besides this, every menu item can have an onClick: Function prop that is called when that item is clicked.

  • alignPositions: Array/String - you can specify how you want the menu to be aligned to the button. By default, the align position is 'tl-bl', which means: align the top-left corner of the menu to the bottom-left corner of the button. Examples of valid values: 'br-tr' - align the bottom-right of the menu to the top-right of the button; 'tl-tr' - align the top-left of the menu to the top-right of the button. In case you specify an array of alignPositions, it will try all of those until one is found for which there is enough space in the document element. If, for example, the first position would render the menu outside the document, then the second position is used, and so on
  • hideMenuOnClick: Boolean - defaults to true, which means that when a menu item is clicked, the drop-down menu is hidden. Specify false if you don't want this behavior
  • arrowPosition: String - either 'right' (the default), or 'left'
  • alignOffset: Object({left, top}) - specify a different offset to align the menu to a different distance from the button.
  • block: Boolean - defaults to false - whether to render the button as block level.
  • renderMenu: Boolean - if you will specify false, the button will not render the drop-down menu. This can be useful if you choose to render the menu at a higher level, by using the onMenuChange callback prop
  • onMenuChange: Function(menu, thisButton) - called whenever the menu should be shown or hidden. NOTE: menu can either be a ReactElement or a null reference, depending on whether the menu should be displayed or not

The drop-down button contains two items: the button and the menu. Those items are wrapped inside a <div>, called the wrapper.

  • wrapperFactory: Function(props) - a factory function to return a wrapper around the button and the menu. If undefined is returned, it is assumed you just wanted to modify some wrapper props before rendering, and a <div> will be rendered with these props.
  • wrapperStyle: Object - a style object for the button wrapper
  • wrapperProps: Object - props to be applied to the wrapper

Contributing

$ npm install
$ npm run dev # to start webpack-dev-server
$ npm run serve # to start http-server on port 9091

now navigate to localhost:9091

License

MIT