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-lite

v0.1.0

Published

This package features two custom dropdown menu components for ReactJS.

Downloads

2

Readme

This package features two custom dropdown menu components for ReactJS.

Online demo

Single-selection | Multi-selection :-------------------------:|:-------------------------: dd-single | dd-multiple

Installation

npm install reactjs-dropdown-component --save

Make sure that you inserted the following link tag between the <head></head> tags inside /public/index.html of your react project. This is required for the FontAwesome component that the package depends on.

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />

Usage

First, import the components:

import {DropdownMultiple, Dropdown} from 'reactjs-dropdown-component';

The structure of the state for the dropdown data should be as follows:

state = {
  location: [
    {
      id: 0,
      title: 'New York',
      selected: false,
      key: 'location'
    },
    {
      id: 1,
      title: 'Dublin',
      selected: false,
      key: 'location'
    },
    {
      id: 2,
      title: 'Istanbul',
      selected: false,
      key: 'location'
    }
  ],
  fruit: [
    {
      id: 0,
      title: 'Apple',
      selected: false,
      key: 'fruit'
    },
    {
      id: 1,
      title: 'Orange',
      selected: false,
      key: 'fruit'
    },
    {
      id: 2,
      title: 'Strawberry',
      selected: false,
      key: 'fruit'
    }
  ]
}

Then you need to include a function to control the state of the parent component.

This is for the single selection dropdown:

resetThenSet = (id, key) => {
  let temp = JSON.parse(JSON.stringify(this.state[key]));
  temp.forEach(item => item.selected = false);
  temp[id].selected = true;
  this.setState({
    [key]: temp
  });
}

And this is for the multi selection dropdown:

toggleSelected = (id, key) => {
  let temp = JSON.parse(JSON.stringify(this.state[key]));
  temp[id].selected = !temp[id].selected;
  this.setState({
    [key]: temp
  });
}

Finally use the components as follows:

<Dropdown
  title="Select fruit"
  list={this.state.fruit}
  resetThenSet={this.resetThenSet}
/>

<DropdownMultiple
  titleHelper="Location"
  title="Select location"
  list={this.state.location}
  toggleItem={this.toggleSelected}
/>

Refer to the GitHub repository for the full code example.

Custom Styling

Refer to the following styling file for overriding the default styles. You can create your own styling file with the same class names in order to do your custom styling.