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

@haraldlons/reactjs-tag-input

v2.0.20

Published

A simple (but fully customizable) react tag input component built using styled components.

Downloads

4

Readme

React Tag Input

A simple (but fully customizable) react tag input component built using styled components.

Build Status Coverage Status npm version

  • Demo
  • Installation
  • Usage
  • API

Demo

example

Interactive Demo

Installation

npm i reactjs-tag-input --save

Usage


import { TagInput } from 'reactjs-tag-input'

class Example extends React.Component {
    constructor(props) {
        super(props);
        this.state = {tags: []}
        this.onTagsChanged = this.onTagsChanged.bind(this);
    }

    onTagsChanged(tags) {
        this.setState({tags})
    }

    render() {
        return <TagInput tags={this.state.tags} onTagsChanged={this.onTagsChanged} />
    }
}

An example with pre-rendered tags can be found here.

API

This component exposes the following props:

  • tags (required)

An array of tags to be rendered in the input. If not empty, this must be an array of js objects. The objects are required to have a displayValue property specifying what should be displayed in the tag input to represent the item.

  • onTagsChanged (required)

A function that gets called when tags are added or deleted in the input. The function gets the new tag array as it's argument.

  • onInputChanged

A function that gets passed to the internal input onChange attribute.

  • wrapperStyle

A js template string to be used to override the default component wrapper styles. The example below will override the wrapper background and disable the default box-shadow. The template string can be anything that you would normally pass down as a styled-component configuration.

  <TagInput wrapperStyle={`
    background: red;
    box-shadow: none;
  `}/>
  • inputStyle

A js template string to be used to override the default component input styles. The example below will override the input background color and override the placeholder text styling in webkit based browsers. The template string can be anything that you would normally pass down as a styled-component configuration.

  <TagInput inputStyle={`
    background: red;
    &::-webkit-input-placeholder {
      font-weight: 600;
      font-style: bold;
      color: black;
    }
  `}/>
  • tagStyle

A js template string to be used to override the default component tag styles. The example below will override the tag background color. The template string can be anything that you would normally pass down as a styled-component configuration.

  <TagInput tagStyle={`
    background: red;
  `}/>
  • tagDeleteStyle

A js template string to be used to override the default component that is rendered next to each tag for deletion purposes. The example below will override the tag font-size property. The template string can be anything that you would normally pass down as a styled-component configuration.

  <TagInput tagDeleteStyle={`
    font-size: 0.5em;
  `}/>
  • hideInputPlaceholderTextIfTagsPresent

A boolean flag to indicate whether the input placeholder text should be hidden if there are tags present. Defaults to true.

  • tagDeleteIcon

A react component that will be rendered next to each tag to allow for the deletion of it. Defaults to ' x'.

  import CustomTagDeleteIcon from './assets/TagDeleteIcon.png';
  <TagInput tagDeleteIcon={CustomTagDeleteIcon} />
  • addTagOnEnterKeyPress

A boolean flag to control whether hitting the enter will will add a tag into the input. Defaults to true.

  <TagInput addTagOnEnterKeyPress={false} />
  • placeholder

Defaults to "Type something and hit enter...", but can be overridden with this prop

  <TagInput placeholder="Hello world" />

Contributing

To start up a dev env that runs the example react app utilizing the component, checkout the project from the github homepage and run:

  • npm install
  • npm start

To build the example app:

  • npm run build-examples

The output of the above command is what is running at the interactive demo.

To build for an npm registry:

  • npm run build.

When this command is run from src/lib, contents in the src/lib folder will be bundled and outputted to the dist folder, which can be deployed to an npm registry of your choice.