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-categorized-tag-input-3

v3.0.0

Published

React.js component for making tag autocompletion inputs with categorized results.

Downloads

3

Readme

react-categorized-tag-input Build Status

React.js component for making tag autocompletion inputs with categorized results with no dependencies and 10KB minified.

Note: v1.x versions only work with react 0.14.0 or higher. For compatibility with previous versions use the v0.x versions.

Install

npm install react-categorized-tag-input

Include

With webpack, browserify, etc (recommended way):

import TagInput from 'react-categorized-tag-input';

or (if you are not yet using ES2015, which you should)

var TagInput = require('react-categorized-tag-input');

With other tools: Just include the categorized-tag-input.js file in your HTML and your good to go. It is already minified.

If you want to use the default style you have to include the categorized-tag-input.css file. It is plain CSS, no LESS, no SASS, no dependencies.

As a personal suggestion, I recommend webpack. You would just need to require('node_modules/react-categorized-tag-input/categorized-tag-input.css');.

Usage

To use this component we will assume the imported variable name is TagInput. The props are very straightforward.

|Name | Type | Description | default| |-----|------|-------------|--------| |addNew|boolean|If true, allows the user to create new tags that are not set in the dataset|true| |categories|Array of objects|Dataset with categories and items|Required| |transformTag|function|A function that will receive the tag object (which has at least keys title and category) and must return a string. This string will be displayed to the user. Useful if you need to apply a transformation to the tags.|(tag) => tag.title| |value|Array of tags. Tags are objects with (at least) keys title and category, where category is the id of a category in the array passed in for the categories prop|Array with the initial tags|[]| |onBlur|function|Callback for when the input loses focus|noop| |onChange|function|Callback for when the input changes. It does not get an event as parameter, it gets the array of tags after the change.|noop| |placeholder|string|A placeholder will be given in the input box.|Add a tag| |getTagStyle|function| A function from the tag text (string) to an object with any or all of the following keys: base, content and delete. The values are React style objects. This example renders 1-letter long tags in red: text => text.length === 1 ? {base: {color: "red"}} : {} | () => ({}) | |getCreateNewText|function| A function that returns the text to display when the user types an unrecognized tag, given a title and text.| (title, text) => Create new ${title} "${text}" | |getTagStyle|function| A function from the tag (object with at least the keys title and category) to an object with any or all of the following keys: base, content and delete. The values are React style objects. This example renders 1-letter long tags in red: text => text.length === 1 ? {base: {color: "red"}} : {} | () => ({}) |

The tag object

Tag objects look like this:

{
  title: 'String to used to identify the tag',
  category: 'id of the category for the tag'

}

The category object

The category object for the dataset looks like this:

{
  id: 'string or number identifying the category',
  type: 'word to describe the category. Will be used on the create new tag button. E.g: "Create new animal foo"',
  title: 'Title displayed on the category row',
  items: ['Array', 'With', 'Tags'],
  single: optional boolean. If is true the row will be treated as one-valued row. It does not have the option of adding new items to the category
}

Create the object

<TagInput categories={myCategories} addNew={true}
    transformTag={tagTransformer}
    onBlur={onBlur}
    onChange={onChange} />

Get the value

You can either use the onChange callback or use the value() method of the component. It will return the existing tags as an array of strings.

How to use the rendered component

When you click on the input you will be able to write on it. Right away, a panel with the categories with matches will be shown. You can navigate through categories and options using the arrow keys to change the selected tag. Backspace when there is nothing written erases the last tag. Enter and , add the currently selected tag to the input.