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-multi-checkbox-select

v1.2.0

Published

React JS component for multi-select field with checkboxes

Downloads

14

Readme

React Component for multi-select field with checkboxes

This package allows you to have a component for multiple select field which has checkboxes before each option. This package is very easy to use and let you customise the style whatever you want.

Installation

  • npm i react-multi-checkbox-select

Importing the required files

  • import 'react-multi-checkbox-select/lib/multi-checkbox-select.css';
  • import MultiCheckboxSelect from 'react-multi-checkbox-select';
Example usage
  <MultiCheckboxSelect
        name={"multi_checkboxes_select"}
        onChange={(name, isChecked, selectedValue, selectedValues) => {     
                    //name is the name of the field passed using name property
                    //isChecked decides if the checkbox clicked was selected or not
                    //selected value is the value of the checkbox that was clicked
                    //selectedValues is the array of the values of all the checked checkboxes including the new ones
                    this.setState({
                        selectedMultiCheckboxesSelectValues: selectedValues
                    })
             }}
        onRemove={(name, valueToBeRemoved, selectedValuesAfterRemoving) => {
                    //name is the name of the field passed using name property
                    //valueToBeRemoved is the value that was just removed
                    //selectedValuesAfterRemoving is the array of values of all the selected values
                    this.setState({
                          selectedMultiCheckboxesSelectValues: selectedValuesAfterRemoving
                    })
              }}
        onClose={() => {
                   //on some occasions, you might want to detect when the dropdown is clsoed for example, the dropdown is closed when the user click on the screen outside of the fied
        }}
        onOpen={() => {
                    //this will be called when the select dropdown is opened
        }}
        values={this.state.selectedMultiCheckboxesSelectValues}
        defaultText={"Select countries"}
        options={this.state.countryList}
  />
  

Using custom checkboxes

Sometimes, you might want to use you own components for the checkboxes. You can do so by using the customCheckedCheckbox and customUncheckedCheckbox props.

customCheckedCheckbox={<CheckedCheckboxComponent />}
customUncheckedCheckbox={<UncheckedCheckboxComponent />}

Note: you need to provide both props, customCheckedCheckbox and customUncheckedCheckbox if you are using custom components for the checkboxes.

This is what it looks like after some basic customising on the CSS. You can style it to look like to whatever you want.

Screenshot 1

alt text

Screenshot 2

alt text

Props/ Attributes

  • name - "Name for the field which will be used when you submit the form to the server."
  • values - "Currently selected array of values. Format - [1, 2, 3]."
  • defaultText - "Label that will be displayed when there is no option selected yet."
  • options - "Options for the select field. The type must be array in this format, [ { value: 1, label: 'Myanmar' }, { value: 2, label: 'England' } ]."

Callbacks

  • onChange - "This will be triggered each time a checkbox has been ticked or un-ticked."
  • onRemove - "This will be triggered each time a selected item has been removed."
  • onClose - "This will be triggered when the select dropdown is closed."

The followinggs are all the props and callbacks

MultiCheckboxSelect.propTypes = {
    id: PropTypes.string,
    name: PropTypes.string,
    className: PropTypes.string,
    options: PropTypes.array,
    values: PropTypes.array,
    defaultText: PropTypes.string,
    onChange: PropTypes.func,
    onRemove: PropTypes.func,
    onOpen: PropTypes.func,
    onClose: PropTypes.func
}