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

react-tag-buttons

v0.0.2

Published

A simple tags list where tags can be toggled between selected and deselected state like radio buttons

Downloads

52

Readme

react-tag-button

TagButtons is a simple uncontrolled react component that has a list of tags which toggles between selected and deselected state. By default, basic styles are applied, but can be overridden depending on your design requirements.

Demo

A Demo is available here.

Installation

  1. Install react-tag-buttons using npm. npm install react-tag-buttons
  2. Import react-input-range to use TagButtons component.
  3. Optionally, import react-tag-buttons/lib/css/styles.css if you want to apply the default styling.

Usage

Basic implementation:

import React from 'react';
import ReactDOM from 'react-dom';
import TagButtons from 'react-tag-buttons';


const tagsList = [
    {id:1, text:"Apple"},
    {id:2, text:"Ball"},
    {id:3, text:"Cat"},
    {id:4, text:"Dog"},
    {id:5, text:"Engineer"}
];

class App extends Component {
    constructor(props){
        super(props);

        this.state = {
            selectedDataSource: []
        };
    }

    onTagClick = (currSelectedState, id, text) => {
        let {selectedDataSource} = this.state;
        if(!currSelectedState){
            selectedDataSource.push({id:id, text:text});
        }else{
            selectedDataSource = selectedDataSource.filter((item)=>{return item.id !== id});
        }
        this.setState({
            selectedDataSource: selectedDataSource
        });
    };

    render() {
        const {selectedDataSource} = this.state;

        return (
            <div>
                <TagButtons
                    dataSource={tagsList}
                    selectedDataSource={selectedDataSource}
                    onTagClick={this.onTagClick}
                />
                <div>
                    <h4>Selected Tags</h4>
                    <div>
                        {selectedDataSource.map((item)=>{return <p>{item.text}</p>})}
                    </div>
                </div>
            </div>
        );
    }
}

ReactDOM.render(
  <App />,
  document.getElementById('app')
);

API

TagButtons#props

dataSource: array

List of objects which is to be displayed as tags. e.g

dataSource = [{
  ssn : 123456789,
  name: "Ashwin"
}]

dataSourceConfig: object

This is the configuration for our item in dataSource. It is an object which takes three properties:

id :- that property of item object in our dataSource which has the unique id
text :- that property of the item object in our dataSource which has the text
view :- that property of the item object in our dataSource which has the jsx to be rendered

e.g

dataSourceConfig = {
  id: "ssn",
  text: "name"
}

custom view e.g

dataSource = [{
  ssn : 123456789,
  name: "Ashwin",
  display: <div><p>Ashwin</p></div>
}]

dataSourceConfig = {
  id: "ssn",
  text: "name",
  view: "display"
}

onTagClick: function

Called everytime a tag is clicked.

classPrefix: string

Adds a prefix to the all the classes, default is "selectable"

Future scope

I have plans to introduce more configurations and options and also add in diffent types of styles for tags and list