├── .babelrc
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── example.gif
├── package.json
├── public
├── favicon.ico
├── index.html
└── manifest.json
└── src
├── examples
└── App.js
├── index.js
├── lib
├── TagInput.js
├── index.js
└── styled
│ ├── Input.js
│ ├── Tag.js
│ ├── TagDelete.js
│ └── Wrapper.js
├── setupTests.js
└── test
└── TagInput.test.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["react-app"]
3 | }
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # testing
7 | /coverage
8 |
9 | # production
10 | /build
11 |
12 | # misc
13 | .DS_Store
14 | .env.local
15 | .env.development.local
16 | .env.test.local
17 | .env.production.local
18 |
19 | npm-debug.log*
20 | yarn-debug.log*
21 | yarn-error.log*
22 |
23 | /dist
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "stable"
4 | cache:
5 | directories:
6 | - node_modules
7 | script:
8 | - npm test
9 | - npm run build
10 | after_script:
11 | - npm run coverage
12 | - npm i coveralls && cat ./coverage/lcov.info | coveralls
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Kevin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # React Tag Input
2 |
3 | A simple (but fully customizable) react tag input component built using styled components.
4 |
5 | [](https://travis-ci.com/leekevinyg/react-tag-input)
6 | [](https://coveralls.io/github/leekevinyg/react-tag-input?branch=master)
7 | [](https://badge.fury.io/js/reactjs-tag-input)
8 |
9 | - Demo
10 | - Installation
11 | - Usage
12 | - API
13 |
14 |
15 | # Demo
16 |
17 | [](https://leekevinyg.github.io/react-tag-input/)
18 |
19 | [Interactive Demo](https://leekevinyg.github.io/react-tag-input/)
20 |
21 |
22 | # Installation
23 |
24 | ```npm i reactjs-tag-input --save```
25 |
26 |
27 | # Usage
28 |
29 | ```
30 |
31 | import { TagInput } from 'reactjs-tag-input'
32 |
33 | class Example extends React.Component {
34 | constructor(props) {
35 | super(props);
36 | this.state = {tags: []}
37 | this.onTagsChanged = this.onTagsChanged.bind(this);
38 | }
39 |
40 | onTagsChanged(tags) {
41 | this.setState({tags})
42 | }
43 |
44 | render() {
45 | return
46 | }
47 | }
48 |
49 | ```
50 |
51 | An example with pre-rendered tags can be found [here](https://github.com/leekevinyg/react-tag-input/blob/master/src/examples/App.js).
52 |
53 |
54 | # API
55 |
56 | This component exposes the following props:
57 |
58 | * **tags (required)**
59 |
60 | An array of tags to be rendered in the input. If not empty, this must be an array of js objects. The objects are required to have a ```displayValue``` property specifying what should be displayed in the tag input to represent the item.
61 |
62 | * **onTagsChanged (required)**
63 |
64 | A function that gets called when tags are added or deleted in the input. The function gets the new tag array as it's argument.
65 |
66 | * **onInputChanged**
67 |
68 | A function that gets passed to the internal input ```onChange``` attribute.
69 |
70 | * **wrapperStyle**
71 |
72 | A js template string to be used to override the default component wrapper styles. The example below will override the wrapper ```background``` and disable the default ```box-shadow```. The template string can be anything that you would normally pass down as a [styled-component](https://www.styled-components.com/docs/basics#getting-started "Styled Component") configuration.
73 |
74 | ```
75 |
79 |
80 | ```
81 |
82 | * **inputStyle**
83 |
84 | A js template string to be used to override the default component input styles. The example below will override the input ```background``` color and override the placeholder text styling in webkit based browsers. The template string can be anything that you would normally pass down as a [styled-component](https://www.styled-components.com/docs/basics#getting-started "Styled Component") configuration.
85 |
86 | ```
87 |
95 |
96 | ```
97 |
98 | * **tagStyle**
99 |
100 | A js template string to be used to override the default component tag styles. The example below will override the tag ```background``` color. The template string can be anything that you would normally pass down as a [styled-component](https://www.styled-components.com/docs/basics#getting-started "Styled Component") configuration.
101 |
102 | ```
103 |
106 |
107 | ```
108 |
109 | * **tagDeleteStyle**
110 |
111 | A js template string to be used to override the default component that is rendered next to each tag for deletion purposes. The example below will override the tag ```font-size``` property. The template string can be anything that you would normally pass down as a [styled-component](https://www.styled-components.com/docs/basics#getting-started "Styled Component") configuration.
112 |
113 | ```
114 |
117 |
118 | ```
119 |
120 | * **hideInputPlaceholderTextIfTagsPresent**
121 |
122 | A boolean flag to indicate whether the input placeholder text should be hidden if there are tags present. Defaults to true.
123 |
124 | * **tagDeleteIcon**
125 |
126 | A react component that will be rendered next to each tag to allow for the deletion of it. Defaults to ' x'.
127 |
128 | ```
129 | import CustomTagDeleteIcon from './assets/TagDeleteIcon.png';
130 |
131 |
132 | ```
133 |
134 | * **addTagOnEnterKeyPress**
135 |
136 | A boolean flag to control whether hitting the enter will will add a tag into the input. Defaults to true.
137 |
138 | ```
139 |
140 |
141 | ```
142 | * **placeholder**
143 |
144 | Defaults to "Type something and hit enter...", but can be overridden with this prop
145 |
146 | ```
147 |
148 | ```
149 |
150 | # Contributing
151 |
152 | To start up a dev env that runs the example react app utilizing the component, checkout the project from the [github homepage](https://github.com/leekevinyg/react-tag-input) and run:
153 |
154 | * ``` npm install ```
155 | * ``` npm start ```
156 |
157 | To build the example app:
158 |
159 | * ``` npm run build-examples ```
160 |
161 | The output of the above command is what is running at the [interactive demo](https://leekevinyg.github.io/react-tag-input/).
162 |
163 | To build for an npm registry:
164 |
165 | * ``` npm run build ```.
166 |
167 | When this command is run from ```src/lib```, contents in the ```src/lib``` folder will be bundled and outputted to the ```dist``` folder, which can be deployed to an npm registry of your choice.
168 |
--------------------------------------------------------------------------------
/example.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leekevinyg/react-tag-input/037a05e7d35fcb461e357a989e92b5fab7670d4a/example.gif
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "reactjs-tag-input",
3 | "version": "2.0.13",
4 | "homepage": "http://leekevinyg.github.io/react-tag-input",
5 | "repository": "https://github.com/leekevinyg/react-tag-input",
6 | "license": "MIT",
7 | "keywords": [
8 | "react",
9 | "tag",
10 | "tags",
11 | "input",
12 | "pills",
13 | "pill",
14 | "javascript"
15 | ],
16 | "main": "dist/index.js",
17 | "module": "dist/index.js",
18 | "files": [
19 | "dist"
20 | ],
21 | "devDependencies": {
22 | "babel-cli": "^6.26.0",
23 | "enzyme": "^3.8.0",
24 | "enzyme-adapter-react-16": "^1.7.1",
25 | "gh-pages": "^2.0.1",
26 | "react": "^16.3.2",
27 | "react-dom": "^16.3.2",
28 | "react-scripts": "1.1.4",
29 | "react-test-renderer": "^16.3.2"
30 | },
31 | "peerDependencies": {
32 | "react": "^16.3.2",
33 | "react-dom": "^16.3.2"
34 | },
35 | "scripts": {
36 | "start": "react-scripts start",
37 | "build-examples": "react-scripts build",
38 | "test": "react-scripts test --env=jsdom",
39 | "coverage": "npm run test -- --coverage",
40 | "eject": "react-scripts eject",
41 | "build": "rm -rf dist && NODE_ENV=production babel src/lib --out-dir dist --copy-files --ignore __tests__,spec.js,test.js,__snapshots__",
42 | "predeploy": "npm run build-examples",
43 | "deploy": "gh-pages -d build"
44 | },
45 | "dependencies": {
46 | "prop-types": "^15.6.2",
47 | "styled-components": "^4.1.3"
48 | },
49 | "jest": {
50 | "collectCoverageFrom": [
51 | "src/lib/**/*.{js}"
52 | ]
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leekevinyg/react-tag-input/037a05e7d35fcb461e357a989e92b5fab7670d4a/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |