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

ship-components-tag-input

v1.1.0

Published

Material Design Input and Typeahead for Tags (or "Chips" in Material Design speak)

Downloads

10

Readme

ship-components-tag-input

JavaScript Material Design React Multi-Select Box. Exports a commonjs module that can be used with webpack. Source is in ES6 and an ES5 version is available using Babel.

npm Build Status Coverage devDependencies

Docs & Help

Here is the list of options you can use.

Docs

filterable

{bool} True by default. Enables an option to let user search inside the text input for a match.

darkTheme

{bool} False by default.

orderOptionsBy

{string} 'titles' by default. User can pass a prop to order the dropdown result list based on that prop. For instance if your option object looks like:

options = {
  id: 1,
  title: 'Option 1'
}
<!-- User can pass 'id' to order by id or 'title' to order by titles  -->

togglePosition

{string} 'left' by default.

noOptionsMessage

{string} empty by default.

toggleSwitchStyle

{string} 'search' by default. Please refer to ship-components-icon for the list of icons you can pass in.

Usage

ES6/JSX (Recommended)

The component is written using ES6/JSX therefore Babel is recommended to use it. The below example is based on using webpack and babel-loader.

/**
 * ES6 TagInput Example
 */
import React from 'react';
import Immutable from 'immutable';
import TagInput from 'ship-components-tag-input';

export default class ExampleClass extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      value: new Immutable.List()

    };
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(tag) {
    this.setState({
      value: tag
    });
  }

  render() {
    const options = [
      {
        id: 3,
        title: 'Option 1',
        searchString: 'Option 1'
      },
      {
        id: 2,
        title: 'Option 2',
        searchString: 'Option 2'
      },
      {
        id: 1,
        title: 'Option 3',
        searchString: 'Option 3'
      }
    ];

    return (
      <div className='form-group'>
        <TagInput
          filterable                                     // True by default
          darkTheme                                     // False by default

          orderOptionsBy='id'                           // 'titles' by default
          placeholder='Choose Tag Inputs'               // 'Select...' by default
          togglePosition='right'                        // 'left' by default
          noOptionsMessage='There are no more tags...'  // '' by default
          toggleSwitchStyle='library_add'               // 'search' by default

          value={this.state.value}
          onChange={this.handleChange}                  // REQUIRED
        />
      </div>
    );
  }
}

ReactDOM.render(<Examples />, document.getElementById('examples'));

Development

More examples can be found in the examples/ folder. A development server can be run with:

$ git clone https://github.com/ship-components/ship-components-tag-input.git
$ npm install
$ npm test

which will live reload any changes you make and serve them at http://localhost:8080.

Webpack Configuration

This module is designed to be used with webpack. Below are is a sample of how to setup the loaders in webpack 3:

/**
 * Relevant Webpack Configuration
 */
{
  [...]
  module: {
    rules: [
      {
        test: /\.(jsx?|es6)$/,
        enforce: 'pre',
        exclude: /(node_modules|dist)/,
        include: /src\/.*/,
        use: 'eslint-loader'
      },
      // ES6/JSX for App
      {
        test: /\.(jsx?|es6)$/,
        exclude: [
          /node_modules/
        ],
        use: 'babel-loader'
      },
      {
        test: /\.(jsx?|es6)$/,
        include: [
          /ship-components-.*\/src/
        ],
        use: 'babel-loader'
      },
      {
        test: /\.(png|woff|woff2|eot|ttf|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: '[path][name].[ext]'
            }
          }
        ]
      },
      // CSS Modules
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            {
              loader: 'css-loader',
              options: {
                modules: true,
                importLoaders: 1,
                localIdentName: '[name]--[local]'
              }
            },
            {
              // CSS Modules
              loader: 'postcss-loader',
              options: {
                plugins: () => [
                  require('postcss-nested')(),
                  require('postcss-simple-vars')({
                    /**
                     * Default variables. Should be overridden in mail build system
                     * @type {Object}
                     */
                    variables: {
                      'primary-color': '#38b889',
                      'opacity-disabled': '0.58',
                      'base-grid-size': '4px'
                    }
                  }),
                  require('postcss-color-hex-alpha')(),
                  require('postcss-color-function')(),
                  require('postcss-calc')(),
                  require('autoprefixer')()
                ]
              }
            }
          ]
        })
      }
    ]
  },

  plugins: [
    new webpack.LoaderOptionsPlugin({
      options: {
        context: __dirname,
        eslint: {
          // Strict linting enforcing
          failOnWarning: true
        }
      }
    }),
    new ExtractTextPlugin({
      filename: '[name].css',
      disable: false,
      allChunks: true
    })
  ],
  [...]
}

Tests

  • npm run test: to run the tests
  • npm run test:update: to run the tests and update the snapshots
  • npm run test:watchAll: to run the tests and watch all tests
  1. npm install
  2. npm test

History

  • 1.1.0 - Adds a selectItemBy prop in order to be able to deselect items based on what the props passes in
  • 1.0.13 - Updated ship-components-utility to newer version
  • 1.0.11 - Removed invalid css comment, removed unneeded "engines", applied audit fixes
  • 1.0.9 - Fixes the behavior for multiple=false
  • 1.0.8 - Disable filtering when results are fetched from server
  • 1.0.7 - Fixes search results with short filterText
  • 1.0.6 - Fixes the behavior of the enter key
  • 1.0.5 - Prevent tabbing to the toggle switch
  • 1.0.4 - Fixes the behavior of the tab key
  • 1.0.3 - Fixes the label overlapping the entered filter text on blur.
  • 1.0.2 - Fixes the broken input layout due to the invert feature
  • 1.0.0 - Upgrade to React 16
  • 0.7.0 - Feature: prop invert to change the component display order
  • 0.6.3 - Bugfix: Fixed bug when pressing enter without an option highlighted.
  • 0.6.2 - Bugfix: Fixed label position for when selected tags span multiple lines.
  • 0.6.1 - Bugfix: Fixed disappearing label when input has value.
  • 0.6.0 - Feature: prop function fetchOptions for custom ajax on filter input. CSS fix: dropdown requires no extra styling to look like examples.
  • 0.5.3 - CSS fix: dropdown can be wider than text input.
  • 0.5.0 - Adds unit tests.
  • 0.4.3 - Fixes the bug where updating the options in parent component don't change in TagInput component(componentWillReceiveProps).
  • 0.4.1 - Fixes bug where Dropdown is not positioned dynamically based on input height.
  • 0.4.0 - Adds an option to let use pass in the value as a prop. The state of tags is now handled inside the parent.
  • 0.3.0 - Adds a functionality to fetch options from a URL instead of passing options as a prop (Internal use only).
  • 0.2.1 - Aligns the component with the rest of ship-components in terms of UI and the functionality.
  • 0.1.0 - Initial

License

The MIT License (MIT)

Copyright (c) 2017 SHIP

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.