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-select-checked

v0.1.12

Published

A React select based on JedWatson/React-Select with checkmarks on selected options.

Downloads

387

Readme

React-Select-Checked

A React select based on JedWatson/React-Select with checkmarks on selected options.

Installation

npm install react-select-checked --save

At this point you can import react-select-checked in your application as follows:

import CheckedSelect from 'react-select-checked';

Usage

React-Select-Checked generates a hidden text field containing the selected value, so you can submit it as part of a standard form. You can also listen for changes with the onChange event property.

Options should be provided as an Array of Objects, each with a value and label property for rendering and searching. You can use a disabled property to indicate whether the option is disabled or not.

The value property of each option should be set to either a string or a number.

When the value is changed, onChange(selectedValueOrValues) will fire, allowing you to re-render with an updated value= prop.

var CheckedSelect = require('react-select-checked');

var options = [
    {label: 'Chocolate', value: 'chocolate', disabled: true},
    {label: 'Vanilla', value: 'vanilla'},
    {label: 'Strawberry', value: 'strawberry'},
    {label: 'Caramel', value: 'caramel'},
];

var currentSelection = [{label: 'Caramel', value: 'caramel'}];

function logChange(val) {
  console.log('Selected value: ', val);
  setState({currentSelection: val});
}

<CheckedSelect
  name="form-field-name"
  value={currentSelection}
  options={options}
  onChange={logChange}
/>

Async options

If you want to load options asynchronously, set async attribute to true and instead of providing an options Array, provide a loadOptions Function. The function takes two arguments String input, Function callback and will be called when the input text is changed.

When your async process finishes getting the options, pass them to callback(err, data) in a Object { options: [] }.

function logChange(val) {
  console.log('Selected value: ', val);
  setState({value: val});
}

function getOptions (input, callback) {
    setTimeout(function() {
        callback(null, {
            options: [
                { value: 'one', label: 'One' },
                { value: 'two', label: 'Two' }
            ],
            // CAREFUL! Only set this to true when there are no more options,
            // or more specific queries will not be sent to the server.
            complete: true
        });
    }, 1000);
}

<CheckedSelect
    async
    loadOptions={getOptions}
    onChange={logChange}
    placeholder="Select your favourite(s)"
    value={value}
/>

Async options with Promises

loadOptions supports Promises, which can be used in very much the same way as callbacks.

function logChange(val) {
  console.log('Selected value: ', val);
  setState({value: val});
}

function getGitHubUsers(input) {
    return fetch(
        'https://api.github.com/search/repositories?q=stars:%3E1+language:javascript&sort=stars&order=desc&type=Repositories'
    ).then(
        response => {
           return response.json();
        }).then(json => {
            let githubUsers = json.items.map(user => {
                return {
                    label: user.full_name,
                    value: user.name
                };
            });
            return { options: githubUsers };
        });
}

<CheckedSelect
    async
    loadOptions={getGitHubUsers}
    onChange={logChange}
    placeholder="Select your favourite(s)"
    value={value}
/>

Further options

| Property | Type | Default | Description | |:---|:---|:---|:---| | addAllTitle | string | 'Add all' | text to display in the Add all button | | async | bool | false | if this property is specified then a loadOptions method should also be used. | | clearAllTitle | string | 'Clear' | text to display in the Clear button | | disabled | bool | false | whether the CheckedSelect is disabled or not | | ignoreAccents | bool | true | whether to strip accents when filtering | | ignoreCase | bool | true | whether to perform case-insensitive filtering | | loadOptions | func | undefined | unction that returns a promise or calls a callback with the options: function(input, [callback]) | | name | string | undefined | field name, for hidden <input /> tag | | noResultsText | string | default in react-select (as of 4/2018, it's 'No results found') | placeholder displayed when there are no matching search results or a falsy value to hide it (can also be a react component) | | onChange | func | undefined | onChange handler: function(newOption) {} | | options | array | undefined | array of options | | placeholder | string|node | 'Please select ..' | field placeholder, displayed when there's no value |