1.0.0 • Published 12 months ago

react-tag-builder v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

react-tag-builder

NPM version Build npm-typescriptLicense]github-license-url

A customizable tag input component for React.

Features

  • Add tags by typing and pressing Enter.
  • Click on a tag to trigger custom behavior.
  • Customize the appearance of the input field and tags.
  • Initialize with default tags.
  • Written in TypeScript.

Installation

npm install react-tag-builder

Usage

Here's a basic example of how to use the TagInput component:

import React from 'react'
import TagInput from 'react-tag-builder'

const App: React.FC = () => {
  return (
    <div>
      <TagInput
        defaultTags={['React', 'JavaScript', 'TypeScript']}
        onChange={(tags) => console.log('Tags: ', tags)}
        onClick={(tag) => console.log('Clicked tag: ', tag)}
      />
    </div>
  )
}

export default App

Props

PropTypeDescription
defaultTagsstring[]An array of tags to initialize the input with.
onChange(tags: string[]) => voidA callback function that is called whenever the tags change.
onClick(tag: string) => voidA callback function that is called whenever a tag is clicked.
inputClassNamestringA class name to apply to the input field.
tagClassNamestringA class name to apply to the tags.
tagStyleReact.CSSPropertiesA style object to apply to the tags.
inputStyleReact.CSSPropertiesA style object to apply to the input field.
placeholderstringA placeholder to display in the input field.
separatorstringA string to use as the separator between tags.
validator(tag: string) => booleanA function that returns true if the tag is valid.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT