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

svelte-tags-input

v6.0.1

Published

Fully customizable Svelte component to enter tags.

Downloads

5,342

Readme

Live Demo

Install & Usage

npm install svelte-tags-input
import Tags from "svelte-tags-input";

<Tags />

Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | bind:tags | Array | [] | To get the values | | addKeys | Array | ENTER 13 | Set which keys add new values | | removeKeys | Array | BACKSPACE 8 | Set which keys remove new values | | allowPaste | Boolean | false | Enable pasting of a tag or tag group | | allowDrop | Boolean | false | Enable drag and drop of a tag or tag group | | splitWith | String | , | Choose what character split you group of tagsWork only if allowDrop or allowPaste are true | | maxTags | Number | false | Set maximum number of tags | | onlyUnique | Boolean | false | Set the entered tags to be unique | | placeholder | String | false | Set a placeholder | | autoComplete | Array or fn() | false | Set an array of elements to create a auto-complete dropdown | | autoCompleteKey | String | false | Set a key to search on autoComplete array of objects | | autoCompleteFilter | Boolean | true | If false disable auto complete filter and return endpoint response without filter | | onlyAutocomplete | Boolean | false | Only accept tags inside the auto complete list | | name | String | svelte-tags-input | Set a name attribute | | id | String | Random Unique ID | Set a id attribute | | allowBlur | Boolean | false | Enable add tag when input blur | | disable | Boolean | false | Disable input | | minChars | Number | 1 | Minimum length of search text to show autoComplete list. If 0, autoComplete list shows all results when click on input | | labelText | String | svelte-tags-input | Custom text for input label | | labelShow | Boolean | false | If true the label will be visible | | readonly | Boolean | false | If true the input show in display mode | | onTagClick | Function | empty | A function to fire when a tag is clicked | | autoCompleteShowKey | String | autoCompleteKey | A key string to show a different value from auto complete list object returned | | onTagAdded | Function | empty | Get a function to execute when tag added | | onTagRemoved | Function | empty | Get a function to execute when tag removed | | cleanOnBlur | Boolean | false | Clear input on blur (tags keeped) | | customValidation | Function | empty | Create a custom validation when tag is added |

A complete list of key codes

Full example

Live Demo

import Tags from "svelte-tags-input";

let tags = [];

const countryList = [
    "Afghanistan",
    "Albania",
    "Algeria",
    "American Samoa",
    "Andorra",
    "Angola",
    "Anguilla",
    "Antarctica",
    "Antigua and Barbuda",
    "Argentina"
    ...
];

<Tags
    bind:tags={tags}
    addKeys={[9]} // TAB Key
    maxTags={3}
    allowPaste={true}
    allowDrop={true}
    splitWith={"/"}
    onlyUnique={true}
    removeKeys={[27]} // ESC Key
    placeholder={"Svelte Tags Input full example"}
    autoComplete={countryList}
    name={"custom-name"}
    id={"custom-id"}
    allowBlur={true}
    disable={false} // Just to illustrate. No need to declare it if it's false.
    readonly={false} // Just to illustrate. No need to declare it if it's false.
    minChars={3}
    onlyAutocomplete
    labelText="Label"
    labelShow
    onTagClick={tag => console.log(tag)}
    onTagAdded={(tag, tags) => console.log(tag, tags)}
    onTagRemoved={(tag, tags) => console.log(tag, tags)}
	cleanOnBlur={true}
	customValidation={(tag) => tag === "Argentina" ? true : false }
/>

Example with autoComplete function

Live Demo

import Tags from "svelte-tags-input";

let tags = [];

const customAutocomplete = async () => {
    const list = await fetch('https://restcountries.com/v2/all?fields=name,alpha3Code,flag');
    const res = await list.json();

    return res;
}

<Tags
    bind:tags={tags}
    autoComplete={customAutocomplete}
    autoCompleteKey={"name"}
    autoCompleteShowKey={"alpha3Code"}
/>

{#each tags as country, index}
    <p>{index} - {country.name} - {country.alpha3Code} </p>
    <img src={country.flag} />
{/each}

FAQs

CHANGELOG

License

This project is open source and available under the MIT License.

Author

Agustín

2024