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

rp-chip-input

v0.2.8

Published

A web component that implements a chip input and autocomplete, inspired by angular chip input

Downloads

5

Readme

Published on webcomponents.org

chip-input

A pure web component implementation of a chip input inspired by angular's similar component.

It is currently under early development, but I'm using it in more than one production application.

Check out the demo here

Installation

npm install chip-input

Usage

This component is written using es6/7 features, so if you're not using an evergreen browser you'll need to transpile with babel or similar.

For webpack/rollup/polymer etc... just:

import {ComponentChipInput} from 'chip-input';

After that, you can use it like you would any web component with the framework (or vanilla) of your choice, i.e. for lit-element:

render() {
    return html`
        <app-chip-input></app-chip-input>
    `;
}

Properties

chips

An array of strings that can be used to get/set the chips.

autocomplete

An async function that's called when autocomplete is triggered. Return a promise that resolves with an array of strings to display in the autocomplete dropdown.

render() {
    return html`
        <app-chip-input .autocomplete=${(input) => this.handleAutoComplete(input)}></app-chip-input>
    `;
}

async handleAutoComplete(input) {
    ...fetch something...
    return [some array of strings]
}

start_icon

A string that's used for the icon to show at the beginning of the input. Should be a url for an icon, data urls are fine.

end_icon

A string that's used for the icon to show at the end of the input. Should be a url for an icon, data urls are fine.

search_icon

Since it is a common use case for chip inputs to be used for searching, we have a built-in search icon that can be optionally displayed. This is just to save you some time hunting down a search icon, if you like the one that's included. Some syling options are available for the icon so you can tweak color/stroke. The search icon is inline-svg, so it's very easy to add/tweak styling.

Customizing

The main reason this component exists is for a simple, easy to understand and tweak chip input component. The code is (hopefully) straight forward and everything is implemented in just two classes, ComponentChipInput and ComponentChip. It should be simple to fork and customize, though in most cases this shouldn't be necessary. If you do end up forking and enhancing, please consider issuing a PR with your changes.

As is typical with web components, appearance is controlled via css variables:

  • --chip-input-border-radius
  • --chip-input-border-color
  • --chip-input-border-width
  • --chip-input-font-size
  • --chip-input-search-icon-stroke
  • --chip-input-autocomplete-background
  • --chip-input-autocomplete-border
  • --chip-input-autocomplete-border-radius
  • --chip-input-autocomplete-font-size
  • --chip-input-autocomplete-hover-background-color
  • --chip-background-color
  • --chip-height
  • --chip-padding
  • --chip-border-color
  • --chip-border-width
  • --chip-font-size
  • --chip-icon-height
  • --chip-icon-width
  • --chip-close-icon-height
  • --chip-close-icon-width
  • --chip-close-icon-fill
  • --chip-close-icon-hover-fill

Contributing

Yes, please!

License

MIT license, enjoy and share.