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

@burtner/select

v6.7.4

Published

A select input made with React js and Tailwind CSS

Downloads

6

Readme

NPM

React tailwindcss select

React-tailwindcss-select is a simple component ready to be inserted into your project. This component inspired by React-select is a select input made with Tailwindcss and React.

Features

  • [x] Select field for a single item
  • [x] Selection field for multiple items
  • [x] Optional button to clear the field
  • [x] Optional search for an item
  • [x] Optional deactivation of an option
  • [X] TypeScript support
  • [ ] Group items
  • [ ] Customization of the select field style
  • [ ] Fixed Options (multiple items select)

Why

A select with the above features is above all indispensable in many projects. On a project using tailwindcss, when I install react-select or other such packages, the style of the latter is affected by that of tailwind.

Rather than looking for a component that uses tailwind, I preferred to make my own based on react-select which I like (and also because I generally like to reinvent the wheel 😅).

Online Demo

You can find the online demo at here

Install

You can use yarn

yarn add react-tailwindcss-select

Or via npm

npm install react-tailwindcss-select

make sure you have installed the peer dependencies as well with the below versions.

"react": "^18.2.0"

Usage

This component also exports a tiny CSS file built by tailwind. All CSS classes used in designing and customizing the select component are all custom tailwind classes which ensures that an existing tailwind project would not need to include this CSS file again.

STEP 1 ADD TO TAILWIND

A tailwind project would only have to import the react component using import Select from 'react-tailwindcss-select' and specify the component in the tailwind configuration to generate the styles of the classes used by react-tailwindcss-select.

Use this code to add the component to the tailwind configuration

// in your tailwind.config.js
module.exports = {
    // ...
    content: ["./src/**/*.{js,jsx,ts,tsx}", "./node_modules/react-tailwindcss-select/dist/index.esm.js"],
    // ...
}

STEP 2 ADD TO COMPONENTS

import {useState} from 'react';
import Select from 'react-tailwindcss-select';

const options = [
    {value: "fox", label: "🦊 Fox"},
    {value: "Butterfly", label: "🦋 Butterfly"},
    {value: "Honeybee", label: "🐝 Honeybee"},
];

const App = () => {
    const [animal, setAnimal] = useState(null);
    
    const handleChange = (value) => {
        console.log("value:", value);
        setAnimal(value);
    };
    
    return (
        <Select
            value={animal}
            onChange={handleChange}
            options={options}
        />
    );
};

export default App;

Props

This table shows all the options available in react-tailwindcss-select.

| Option | Type | Default | Description | |--------------------------|------------|--------------------|----------------------------------------------------------------------------------| | isClearable | Boolean | true | Indicates if you can empty the select field. | | isDisabled | Boolean | false | Indicates if you can disable the select field. | | isMultiple | Boolean | false | Indicates if you can do a multiple selection. | | isSearchable | Boolean | true | Indicates if you can search the elements of the select field. | | loading | Boolean | false | Indicates if you want a loader to appear in the field. | | menuIsOpen | Boolean | false | Indicates if you want the options menu to be displayed by default. | | noOptionsMessage | String | No results found | Default message when there is no option in the select field. | | onChange | Function | | This callback, if present, is triggered when the select field value is modified. | | options | Array | [] | All options available in the select field. | | placeholder | String | Select... | The placeholder shown for the select field. | | searchInputPlaceholder | String | Search... | The placeholder shown for the search input field. | | value | Object | null | Current value of select field. |

onChange

This callback, if present, is triggered when the select field value is modified. This callback takes as a parameter the current value(s) selected. These values respect the same structure as the elements of the options.

(currentValue) => {
    console.log("currentValue:", currentValue);
};

options

All options are available in the select field. Each option element must have a value property that serves as an identifier for the element, a label property that is the text that is displayed in the options list, and an optional disabled property to specify whether the element is active.

// default element
const options =  [ {value: "fox", label: "🦊 Fox"} ];
// default element with `disabled`
const options =  [ {value: "fox", label: "🦊 Fox", disabled: true} ];

value

The current value of the select field. These objects must follow the same structure as an options element. Thus, the following would work:

// default element Simple Select
const value =  {value: "fox", label: "🦊 Fox"};
// default element with `disabled` Simple Select
const value =  {value: "fox", label: "🦊 Fox", disabled: true};
// default element Multiple Select
const value =  [ {value: "fox", label: "🦊 Fox"} ];
// default element with `disabled` Multiple Select
const value =  [ {value: "fox", label: "🦊 Fox", disabled: true} ];

Thanks

This component is inspired by the excellent react-select library by Jed Watson.

I thank you in advance for your contribution to this project.

License

MIT Licensed.