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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-tag-content

v0.0.3

Published

React Tag Content is a tagging component ready to drop in your React projects.

Readme

React Tag Content

This Fork of the React Tag Autocomplete project adds a new prop renderTagContent to the ReactTags component. This allows to render whatever you want inside the added tags. See the example for more information.

React Tag Autocomplete

React Tag Autocomplete is a simple tagging component ready to drop in your React projects. This is a fork of the original React Tags project by Prakhar Srivastav. This version cleans out a few options, removes the drag-and-drop re-ordering functionality and adds appropriate roles and ARIA states.

Installation

npm install --save react-tag-content

Usage

Here's a sample implementation that initializes the component with a list of initial tags and suggestions list. Apart from this, there are multiple events, handlers for which need to be set. For more details, go through the API.

var ReactTags = require('react-tag-autocomplete');

var App = React.createClass({
    getInitialState: function() {
        return {
            tags: [
                { id: 1, name: "Apples" },
                { id: 2, name: "Pears" }
            ],
            suggestions: [
                { id: 3, name: "Bananas" },
                { id: 4, name: "Mangos" },
                { id: 5, name: "Lemons" },
                { id: 6, name: "Apricots" }
            ]
        }
    },
    handleDelete: function(i) {
        var tags = this.state.tags;
        tags.splice(i, 1);
        this.setState({ tags: tags });
    },
    handleAddition: function(tag) {
        var tags = this.state.tags;
        tags.push({
            id: tags.length + 1,
            name: tag
        });
        this.setState({ tags: tags });
    },
    render: function() {
        return (
            <div>
                <ReactTags
                    tags={this.state.tags}
                    suggestions={this.state.suggestions}
                    handleDelete={this.handleDelete}
                    handleAddition={this.handleAddition} />
            </div>
        )
    }
});

React.render(<App />, document.getElementById('app'));

Options

renderTagContent (optional)

A function that returns a react component to be rendered inside an added tag. the function gets called with tag and index.

const renderTagContent = (tag, index) => <div>{`This is custom content of the tag ${tag.name}`}</div>

If you return null instead of a react component, the default tags are used (as if you hadn't supplied the prop)

tags (optional)

An array of tags that are displayed as pre-selected. Each tag must have an id and a name property. Default: [].

var tags =  [
    { id: 1, name: "Apples" },
    { id: 2, name: "Pears" }
];

suggestions (optional)

An array of suggestions that are used as basis for showing suggestions. Each suggestion must have an id and a name property and an optional disabled property. Default: [].

var suggestions = [
    { id: 3, name: "Bananas" },
    { id: 4, name: "Mangos" },
    { id: 5, name: "Lemons" },
    { id: 6, name: "Apricots", disabled: true }
];

busy (optional)

A boolean flag used to display the busy indicator or not. Useful when loading new suggestions asynchronously. Default: false.

delimiters (optional)

An array of keycodes which should terminate tags input. Default: [13, 9].

placeholder (optional)

The placeholder string shown for the input. Default: 'Add new tag'.

autofocus (optional)

Boolean parameter to control whether the text-input should be autofocused on mount. Default: true.

minQueryLength (optional)

How many characters are needed for suggestions to appear. Default: 2.

handleAddition (required)

Function called when the user wants to add a tag. Receives the tag.

function(tag) {
    // Add the tag { id, name } to the tag list
    tags.push(tag);
}

handleDelete (required)

Function called when the user wants to delete a tag. Receives the tag index.

function(i) {
    // Delete the tag at index i
    tags.splice(i, 1);
}

handleInputChange (optional)

Optional event handler when the input changes. Receives the current input value.

function(input) {
    if (this.state.busy) {
        return;
    } else {
        this.setState({ busy: true });

        fetch(`query=${input}`).then(function(result) {
            this.setState({ busy: true });
        });
    }
}

Styling

<ReactTags> does not come up with any styles. However, it is very easy to customize the look of the component the way you want it. The component provides the following classes with which you can style:-

  • ReactTags
  • ReactTags__tagInput
  • ReactTags__busy
  • ReactTags__selected
  • ReactTags__tag -- ReactTags__tag_simple -- ReactTags__tag_content -- ReactTags__tag_content_close
  • ReactTags__remove
  • ReactTags__suggestions

An example can be found in /example/styles.css.

Dev

The component is written in ES6 and uses Webpack as its build tool.

npm install
npm run dev # open http://localhost:8090

Contributing

Got ideas on how to make this better? Open an issue! I'm yet to add tests so keep your PRs on hold :grinning:

Thanks

The autocomplete dropdown is inspired by Lea Verou's awesomeplete library.