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

@gilbarbara/react-dropdown

v0.2.0

Published

Customizable dropdown for React

Downloads

577

Readme

@gilbarbara/react-dropdown

npm version CI Maintainability Test Coverage

Flexible dropdown component with search, create, and multi selection. It uses emotion for styling.

Check out the demo.

Highlights

  • 🏖 Easy to use: Just set the options prop.
  • 🛠 Flexible: Personalize the options to fit your needs.
  • 🚀 Customizable: You can use your own components to complete control the UI.
  • 🟦 Typescript: Nicely typed

Installation

npm i @gilbarbara/react-dropdown

Usage

import Dropdown from '@gilbarbara/react-dropdown';

function App() {
  const options = [
    {
      label: "Alister Chilles",
      value: "achilleso",
    },
    {
      label: "Alyosha Keerl",
      value: "akeerl6",
    },
  ];
  
  return <Dropdown options={options} />;
}

API

The only required props is options.

Base props

| Prop | Type | Default | Description | | ---------------------- | --------------------------------------------------------- | ----------- | ------------------------------------------------------------ | | autoFocus | boolean | true | Focus the input when the menu opens.(if searchable is true) | | className | string | | A custom class name for the Dropdown root. | | clearOnClose | boolean | true | Clear the input when the menu closes. | | clearOnSelect | boolean | true | Clear the input when an item is selected. | | closeOnScroll | boolean | false | Close the menu when the user scrolls. | | closeOnSelect | boolean | false | Close the menu when an item is selected. | | comparatorFn | (previousValues: Option[], values: Option[]) => boolean | | Overrides the internal comparator function. | | create | boolean | false | Create an option from the search string if no results are found.(Fires the onCreate callback) | | direction | Direction | 'ltr' | The text direction of the component. | | disabled | boolean | false | Disable the Dropdown. | | hiddenInput | HiddenInput | | Add an input with type hidden to the component with the selected value(s). | | hideHandle | boolean | false | Hide the handle. | | keepSelectedInList | boolean | true | Keep the selected item(s) in the list. | | labels | Partial<Labels> | | Component labels. | | loading | boolean | false | Show a spinner while loading data. | | menuPosition | Position | 'bottom' | The menu position. | | multi | boolean | false | Select multiple options. | | open | boolean | | Control the menu visibility. | | options (required) | Option[] | | The dropdown options. | | placeholder | string | 'Select...' | The placeholder of the input. | | searchBy | OptionKeys | 'label' | The field to search. | | searchFn | (props: ComponentProps) => Option[] | | Overrides the internal search function. | | searchable | boolean | true | Search the options. | | secondaryPlaceholder | string | | The placeholder on the search field if a value is selected (if searchable is true). | | showClearButton | boolean | false | Show a button to clear the selection. | | showSeparator | boolean | False | Show a separator between the content and handle. | | style | CSSProperties | | Set the style on the component root. | | styles | Partial<Styles> | | The styling of the component. (color, background, border, etc.) | | values | Option[] | | The selected values. |

Callback props

| Prop | Type | Description | | --------------- | --------------------------------------------- | ---------------------------------------------------- | | onChange | (value: Option[]) => void | Values change callback. | | onClearAll | () => void | Clear all values callback (with custom components). | | onClickSelector | (isOpen: boolean) => void | Click selector callback. | | onClose | () => void | Close dropdown callback. | | onCreate | (search: string, close: () => void) => void | Create option callback. | | onOpen | () => void | Open dropdown callback. | | onSelectAll | () => void | Select all values callback (with custom components). |

Custom components

| Prop | Type | Description | | ------------------ | ------------------------------------------------------- | --------------------------- | | clearComponent | (props: ComponentProps) => JSX.Element | Custom Clear component. | | contentComponent | (props: ComponentProps) => JSX.Element | Custom Content component. | | handleComponent | (props: ComponentProps) => JSX.Element | Custom Handle component. | | inputComponent | (props: InputComponentProps) => JSX.Element | Custom Input component. | | loaderComponent | (props: Pick<ComponentProps, 'props'>) => JSX.Element | Custom Loader component. | | menuComponent | (props: ComponentProps) => JSX.Element | Custom Menu component. | | menuItemComponent | (props: ItemComponentProps) => JSX.Element | Custom MenuItem component. | | noDataComponent | (props: ComponentProps) => JSX.Element | Custom NoData component. | | optionComponent | (props: OptionComponentProps) => JSX.Element | Custom Option component. | | separatorComponent | (props: ComponentProps) => JSX.Element | Custom Separator component. |

*All the types are available here.

Credits

Inspired by react-dropdown-select and react-select.

License

MIT