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

stork-tags

v2.1.5

Published

The best and most efficient tags selector in the galaxy

Downloads

1

Readme

tags-input

GitHub license GitHub issues Bower version

What is it? The best and most efficient tags selector in the galaxy. Has the most essential features without redundant bloat.

Why? Because all other tags-input or multi-select components are too opinionated or too restricted to <select> style.

TOC

Usage

Initiate the Tags Input with new StorkTagsInput(options). This will return a tags object for further adjusting the tags-input later.

Options

element: the HTML DOM Element that will hold the tags-input. Example: { element: document.getElementById('my_autocomplete') }

suggestionsHandler: a Function handling what suggestions/autocomplete results are shown according to the user's input. Example:

var suggestions_handler = function suggestions_handler(text, chosenTags, callback) {
  if(text.indexOf('dollar') > -1) {
    callback([{
      label: 'Currencies',
      field: 'currencies',
      items: [
        { label: 'US Dollar', value: 'USD' },
        { label: 'Australian Dollar', value: 'AUD' },
        { label: 'Canadian Dollar', value: 'CAD' },
        { label: 'Singapore Dollar', value: 'SGD' }
      ]
    }]);
    return;
  }

  callback([]);
};

inputMinWidth [optional]: the minimum width the search input is allowed to be. defaults to 60px. Example: { inputMinWidth: 75 }

rechooseRemove [optional]: whether re-choosing from the suggestions list an item that is already chosen will remove this item from the tags. defaults to false. Example: { rechooseRemove: true }

placeholder [optional]: The placeholder text that will be displayed on an empty tags input. Example: { placeholder: 'Type here..' }

persistentPlaceholder [optional]: The placeholder text always be displayed. Example: { persistentPlaceholder: true }

multiline [optional]: Enables the tags container to become multiline as the number of tags exceed the line width: { multiline: true }

showGroups [optional]: Enables to show tag's group inside the tag: { showGroups: true }

maxlength [optional]: The maximum length of characters the user is allowed to type per tag. defaults to 50. Example: { maxlength: 65 }

maxTags [optional]: The maximum allowed number of chosen tags. Beyond this amount the suggestions handler will not be triggered at all. Example: { maxTags: 7 }

persistentSuggestions [optional]: After adding or removing a tag, the default suggestions will keep being triggered. Example: { persistentSuggestions: true }

multiValues [optional]: Can allow or disallow multiple values per tag. defaults to true. Example: { multiValues: false }

Methods

addTag(tagObj): adds a new tag to the chosen tags list. arguments: tagObj {object} - tagObj.value, tagObj.label, tagObj.groupField (optional), tagObj.groupLabel (optional).

removeTag(index): remove a tag from the chosenTags. arguments: index {integer} - the position of the tag in the chosenTags array.

addEventListener(type, listener, optionsUseCapture): adds an event listener to the DOM Element of the tags-input. arguments: type {string}, listener {function}, optionsUseCapture {boolean|object}. Example:

myTags.addEventListener("tag-added", function(e) {
  console.log('added tag:', e.detail); // logs: {obj: {tag values}, index: #}
}, false);

Events

tag-added: when a new tag has been chosen and added to the list. this event has a detail containing the tag JS object, the specific value added to this tag and its index in the array. Example:

myTags.addEventListener("tag-added", function(e) {
  console.log('added tag:', e.detail); // logs: {obj: {values: ['hi'], labels: ['hi'], groupField: '', groupLabel: '', elm: LI}, value: 'hi', index: 0}
}, false);

tag-removed: when a tag is removed the list or a value is removed from a tag. this event has a detail containing the tag JS object and its previous index in the array. if only a value was removed but the tag still remains with other values then also a 'value' property along the detail object. Example:

myTags.addEventListener("tag-removed", function(e) {
  console.log('tag removed:', e.detail); // logs: {obj: {values: ['hi'], labels: ['hi'], groupField: '', groupLabel: '', elm: LI}, index: 0}
  console.log('tag value removed:', e.detail); // logs: {obj: {values: ['hi','you'], labels: ['hi','you'], groupField: '', groupLabel: '', elm: LI}, value: 'there', index: 0}
}, false);

all-tags-removed: when all tags are removed at once. this event has a detail contains all of the removed tags. Example:

myTags.addEventListener("all-tags-removed", function(e) {
  console.log('all tags removed:', e.detail); // logs: {removedTags: [
    {values: ['hi'], labels: ['hi'], groupField: '', groupLabel: '', elm: LI},
    {values: ['you'], labels: ['you'], groupField: '', groupLabel: '', elm: LI}
  ]}
}, false);

Code Example

<div id="tagsInput" style="width: 400px; height: 32px;"></div>
var i, j, regex;
var suggestions_handler = function suggestions_handler(text, chosenTags, callback) {
  if(text.indexOf('dollar') > -1) {
      callback([{
        label: 'Currencies',
        field: 'currencies',
        items: [
          { label: 'US Dollar', value: 'USD' },
          { label: 'Australian Dollar', value: 'AUD' },
          { label: 'Canadian Dollar', value: 'CAD' },
          { label: 'Singapore Dollar', value: 'SGD' }
        ]
      }]);
      return;
    }

    callback([]);
};

var testTags = new StorkTagsInput({
  element: document.getElementById('tagsInput'),
  suggestionsHandler: suggestions_handler,
  rechooseRemove: true,
  inputMinWidth: 70
});

testTags.addTag({ value: 'AUD', label: 'Australian Dollar', groupField: 'currencies', groupLabel: 'Currencies' });

testTags.addEventListener('tag-added', function(e) {
  console.log('added tag:', e.detail);
}, false);
testTags.addEventListener('tag-removed', function(e) {
  console.log('removed tag:', e.detail);
}, false);

Demo

View demo on plunker