0.0.2 • Published 2 years ago

react-field-tag v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ReactFieldTag

React library for tag inputs

NPM JavaScript Style Guide

Install

npm install --save react-field-tag

Usage

import React from 'react'

import ReactFieldTag from 'react-field-tag'

/// add below line to use default styling
import 'react-field-tag/dist/index.css'

const App = () => {
  const [tags, setTags] = React.useState<Array<string>>([]);

  const onAdd = (tag: string) => {
    setTags([...tags, tag]);
  }

  const onDelete = (index: number) => {
    setTags(tags.filter((_, i) => i !== index));
  }

  return <ReactFieldTag tags={tags} onAdd={onAdd} onDelete={onDelete} />
}

export default App

Demo

Demo

Table of contents

StyleClasses

Type declaration

NameTypeDescription
root?stringstyle class for the whole input and tag container
input?stringstyle class for input
tags?stringstyle class for tags container
tag?stringstyle class for tag(s)

ReactFieldTagProps

Type declaration

NameTypeDescriptionDefault
tagsArray of stringan array of tags-
delimiter?stringdetermines a point at which the string separates into tags,
classes?StyleClassesstyle classes for styling-
closeIcon?ReactElementelement to be used as close iconx (close icon from icons8)
onAddfunctiona callback function called when a new tag is to be added-
onDeletefunctiona callback function called on deleting a tag-

License

MIT © iamdipanshusingh