|
| 1 | +# react-tag-input-component |
| 2 | + |
| 3 | +lightweight component for tag(s) input |
| 4 | + |
| 5 | +[](https://github.com/harshzalavadiya/react-tag-input-component/actions) |
| 6 | +[](https://npm.im/react-tag-input-component) |
| 7 | +[](https://bundlephobia.com/result?p=react-tag-input-component@latest) |
| 8 | + |
| 9 | +also see [multi select component](https://github.com/harshzalavadiya/react-multi-select-component) |
| 10 | + |
| 11 | +## ✨ Features |
| 12 | + |
| 13 | +- 🍃 Lightweight (2KB including styles 😎) |
| 14 | +- 💅 Themeable |
| 15 | +- ✌ Written w/ TypeScript |
| 16 | + |
| 17 | +## 🔧 Installation |
| 18 | + |
| 19 | +```bash |
| 20 | +npm i react-tag-input-component # npm |
| 21 | +yarn add react-tag-input-component # yarn |
| 22 | +``` |
| 23 | + |
| 24 | +## 📦 Example |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +```tsx |
| 29 | +import React, { useState } from "react"; |
| 30 | +import TagsInput from "react-tag-input-component"; |
| 31 | + |
| 32 | +const Example = () => { |
| 33 | + const [selected, setSelected] = useState(["papaya"]); |
| 34 | + |
| 35 | + return ( |
| 36 | + <div> |
| 37 | + <h1>Add Fruits</h1> |
| 38 | + <pre>{JSON.stringify(selected)}</pre> |
| 39 | + <TagsInput |
| 40 | + value={selected} |
| 41 | + onChange={setSelected} |
| 42 | + seprators={["Enter", ","]} |
| 43 | + name="fruits" |
| 44 | + placeHolder="enter fruits" |
| 45 | + /> |
| 46 | + <em>press enter or comma to add new tag</em> |
| 47 | + </div> |
| 48 | + ); |
| 49 | +}; |
| 50 | + |
| 51 | +export default Example; |
| 52 | +``` |
| 53 | + |
| 54 | +## 👀 Props |
| 55 | + |
| 56 | +| Prop | Description | Type | Default | |
| 57 | +| ------------- | ------------------------------------- | ----------------------- | ----------- | |
| 58 | +| `name` | value for name of input | `string` | | |
| 59 | +| `placeholder` | placeholder for text input | `string` | | |
| 60 | +| `value` | initial tags | `string[]` | `[]` | |
| 61 | +| `onChange` | onChange callback (added/removed) | `string[]` | | |
| 62 | +| `onBlur` | input `onBlur` callback | `event` | | |
| 63 | +| `seprators` | when to add tag (i.e. `Space`, `,`) | `string[]` | `["Enter"]` | |
| 64 | +| `onExisting` | if tag is already added then callback | `(tag: string) => void` | | |
| 65 | +| `onRemoved` | on tag removed callback | `(tag: string) => void` | | |
| 66 | + |
| 67 | +## 💅 Themeing |
| 68 | + |
| 69 | +You can override CSS variables to customize the appearance |
| 70 | + |
| 71 | +```css |
| 72 | +.rti--container { |
| 73 | + --rti-bg: "#fff", |
| 74 | + --rti-border: "#ccc", |
| 75 | + --rti-main: "#3182ce", |
| 76 | + --rti-radius: "0.375rem", |
| 77 | + --rti-s: "0.5rem", /* spacing */ |
| 78 | + --rti-tag: "#edf2f7", |
| 79 | + --rti-tag-remove: "#e53e3e", |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +> use `!important` if CSS variables are not getting applied |
| 84 | +
|
| 85 | +## 🤠 Credits |
| 86 | + |
| 87 | +- [TypeScript](https://github.com/microsoft/typescript) |
| 88 | +- [TSDX](https://github.com/jaredpalmer/tsdx) |
| 89 | +- [Goober](https://github.com/cristianbote/goober) |
| 90 | + |
| 91 | +## 📜 License |
| 92 | + |
| 93 | +MIT © [harshzalavadiya](https://github.com/harshzalavadiya) |
0 commit comments