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-custom-chips

v1.0.1

Published

A very lightweight and custom react chips

Downloads

131

Readme

License Version npm bundle size (minified) npm type definitions

🍟 react-custom-chips 🍟

A lightweight and customizable input field which can contain multiple nice aligned "chips" components.

It also provides a debounced input showing the result in a list, which can be controlled with arrow keys.

Getting Started 🏂

Install

  npm i react-custom-chips

Import in component 🖥️

import CustomChips from 'react-custom-chips'

Use it as a simple Component 🔑

import CustomChips from 'react-custom-chips'

...

const onChange = (chipsData) => {
  /* ... */
}

return (
  <CustomChips
    fetchSearchSuggestions={anyApiCall}
    onChange={onChange}
  />
)

Supported properties

  renderItem?: (selected: boolean, value: ChipData, handleSelect: (val: ChipData) => void) => JSX.Element;
  onChange?: (item: ChipData[]) => void;
  renderChip?: (chip: RemovableChipData) => JSX.Element;
  inputPlaceholder?: string;
  chipsData?: ChipData[];
  emptyMessage?: string;
  fetchSearchSuggestions?: (value: string) => Promise<ChipData[]>;
  searchIcon?: JSX.Element;
  suggestionList?: ChipData[];
  chipsWrapperClassName?: string;
  loadingSpinner?: JSX.Element;

ChipsData Format:

id: string
name: string

renderChip(chip): Element (optional)

A function that gets the data about one chip in the ChipData format and returns a JSX Element which will be the rendered chip. A default chip element is provided by the component.

renderItem(selected, value, handleSelect): Element (optional)

A function that gets the data of one element of the suggestion list and returns an element representing one part of the rendered suggestionlist.
the selected parameter is boolean representing if the element is selected right now. the handleSelect function needs to be added to every element in order to make it possible to add it as a chip. There is also a default element provided by the component.

onChange(items): void

A function that gets called when the list of chips has changed. It gets an array of the chipsData, representing the current status of the chips.

inputPlaceholder: string (optional)

The placeholder of the input. There is a text provided by the component

chipsData: ChipData[]

An array representing the initial list of chips in the component. Changing this will not update the component.

emptyMessage: string (optional)

If the suggestion list is empty there is a text show. This string is representing this text. There is default text provided by the component.

fetchSearchSuggestions(value: string): Promise<ChipData[]> (optional)

This function gets called when the input changes. It needs to return a promise with the new suggestion list in the chipsData format. It will get a string which is the text from the input field. The function is debounced by in input field.

searchIcon: Element (optional)

An Element for the left side of the input ( most likely an icon ). There is also a default icon provided by the component.

suggestionList: ChipData[] (optional)

If there is no fetching suggestions function, you can also pass a static list of elements, which will always be displayed fully, when changing the input field.

chipsWrapperClassName: string (optional)

A className for styling the chips wrapper.

loadingSpinner: JSX.Element (optional)

Pass in an Element that will be shown as a loading spinner

inputClassName: string (optional)

A class that will be added to the input component to be styled.

noIcon: boolena (optional)

If set to true the icon in the search will not be shown. By default there will be a simple search icon.