Skip to content

Commit a7c4ca4

Browse files
author
jfusco
committed
Adding documentation to the README file - adding allowDupes option in tags component - fixing eslint task
1 parent 79063f3 commit a7c4ca4

File tree

5 files changed

+246
-11
lines changed

5 files changed

+246
-11
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Prakhar Srivastav
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.

README.md

Lines changed: 198 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,199 @@
11
# react-tags
2-
> Simple tagging component for React projects.
2+
3+
![npm][npm-version-image]
4+
[![peerDependency Status][peer-dep-image]][peer-dep-url]
5+
[![devDependency Status][dev-dep-image]][dev-dep-url]
6+
7+
> Simple tagging component for React projects.
8+
9+
## Getting Started ##
10+
11+
#### Installation
12+
From the root of your project.
13+
```sh
14+
npm install react-tags --save
15+
```
16+
17+
## Usage
18+
Simple implementation of tags. See [options available](#options) below.
19+
```js
20+
import React, { Component } from 'react';
21+
import { render } from 'react-dom';
22+
import Tags from 'react-tags';
23+
24+
class Application extends Component{
25+
constructor(props){
26+
super(props);
27+
28+
this.state = {
29+
tags: ['hello', 'world']
30+
}
31+
}
32+
33+
onTagsChange(tags){
34+
console.log(`new tags: ${tags}`);
35+
}
36+
37+
render(){
38+
return (
39+
<div>
40+
<Tags
41+
initialTags={this.state.tags}
42+
placeholder="Add a tag"
43+
change={this.onTagsChange} />
44+
</div>
45+
);
46+
}
47+
}
48+
49+
render(<Application />, document.getElementById('application'));
50+
```
51+
52+
<a name="options"></a>
53+
#### Options
54+
* **[`initialTags`](#initialTags)**
55+
* **[`placeholder`](#placeholder)**
56+
* **[`change`](#change)**
57+
* **[`added`](#added)**
58+
* **[`readOnly`](#readOnly)**
59+
* **[`removeTagWithDeleteKey`](#removeTagWithDeleteKey)**
60+
* **[`removeTagIcon`](#removeTagIcon)**
61+
* **[`allowDupes`](#allowDupes)**
62+
* **[`id`](#id)**
63+
64+
<a name="initialTags"></a>
65+
##### initialTags ~ optional ~ default `[]`
66+
An `array` of tags to be passed in and rendered right away in the component
67+
```js
68+
const tags = ['hello', 'world'];
69+
70+
<Tags initialTags={tags} />
71+
```
72+
73+
<a name="placeholder"></a>
74+
##### placeholder ~ optional ~ default `null`
75+
A `string` used as placeholder text in the tags input field
76+
```js
77+
<Tags placeholder="Add a tag" />
78+
```
79+
80+
<a name="change"></a>
81+
##### change ~ optional
82+
A `function` fired anytime there is a change - returns the new `array` of tags
83+
```js
84+
onTagsChange(tags){
85+
console.log(`new tags: ${tags}`);
86+
}
87+
88+
<Tags change={this.onTagsChange} />
89+
```
90+
91+
<a name="added"></a>
92+
##### added ~ optional
93+
A `function` fired when a new tag is added - returns a `string` of the new tag
94+
```js
95+
onTagAdded(tag){
96+
console.log(`new tag: ${tags}`);
97+
}
98+
99+
<Tags added={this.onTagAdded} />
100+
```
101+
102+
<a name="removed"></a>
103+
##### removed ~ optional
104+
A `function` fired when a new tag is deleted - returns a `string` of the tag that was deleted
105+
```js
106+
onTagRemoved(tag){
107+
console.log(`deleted tag: ${tag}`);
108+
}
109+
110+
<Tags removed={this.onTagRemoved} />
111+
```
112+
113+
<a name="readOnly"></a>
114+
##### readOnly ~ optional ~ default `false`
115+
A `boolean` that sets the tag component to read only mode. No adding or removing tags and pointer events
116+
```js
117+
<Tags readOnly={true} />
118+
```
119+
120+
<a name="removeTagWithDeleteKey"></a>
121+
##### removeTagWithDeleteKey ~ optional ~ default `true`
122+
A `boolean` that allows tags to be removed with the delete key when the input field is empty
123+
```js
124+
<Tags removeTagWithDeleteKey={true} />
125+
```
126+
127+
<a name="removeTagIcon"></a>
128+
##### removeTagIcon ~ optional ~ default `"x"`
129+
The `element` to be used for the delete icon
130+
```js
131+
const removeIcon = () => {
132+
return (
133+
<i class="my-custom-icon"></i>
134+
);
135+
}
136+
137+
<Tags removeTagsIcon={removeIcon()} />
138+
```
139+
140+
<a name="allowDupes"></a>
141+
##### allowDupes ~ optional ~ default `false`
142+
A `boolean` that allows tags to be added more than once
143+
```js
144+
<Tags allowDupes={false} />
145+
```
146+
147+
<a name="id"></a>
148+
##### id ~ optional ~ default `null`
149+
The `string` to be used for the ID of the component
150+
```js
151+
<Tags id="my-tags-component" />
152+
```
153+
154+
## Styling
155+
#### Installation
156+
Import the main SCSS file in to your application SCSS files
157+
```scss
158+
@import "node_modules/react-tags/src/scss/react-tags";
159+
```
160+
161+
There are a few variables set to `!default` that can be overriden. If you need to change it more just override the actual styles.
162+
163+
**Any overriden variables needs to go above the `@import` statement to take effect**
164+
```scss
165+
//-- Global UI
166+
$tag-base-height
167+
$tag-base-font-size
168+
$tag-base-border-radius
169+
$tag-base-font-color
170+
$tag-base-margin
171+
$tag-base-font-family
172+
173+
//-- Tags
174+
$tag-background-color
175+
$tag-background-hover-color
176+
$tag-remove-color
177+
$tag-remove-font-size
178+
$tag-remove-hover-color
179+
180+
//-- Input
181+
$tag-input-bg-color
182+
$tag-input-border
183+
$tag-input-placeholder-color
184+
```
185+
186+
If you don't care to override variables and just want to override actual styles you may choose to import the minified compiled version of the css instead
187+
```scss
188+
@import "node_modules/react-tags/dist/react-tags.min.css";
189+
```
190+
191+
## License ##
192+
193+
* [MIT License](http://www.opensource.org/licenses/mit-license.php)
194+
195+
[npm-version-image]: https://img.shields.io/npm/v/npm.svg?maxAge=2592000
196+
[dev-dep-image]: https://david-dm.org/JFusco/react-tags/dev-status.svg
197+
[dev-dep-url]: https://david-dm.org/JFusco/react-tags#info=devDependencies
198+
[peer-dep-image]: https://david-dm.org/JFusco/react-tags/peer-status.svg
199+
[peer-dep-url]: https://david-dm.org/JFusco/react-tags#info=peerDependencies

gulp/tasks/eslint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module.exports = (gulp, $) => {
44
gulp.task('eslint', () => {
55
return gulp.src('./src/**/*.js', {read: false})
6-
.pipe($.shell('eslint --fix --ignore-path .eslintignore ./src/js/!*'))
6+
.pipe($.shell('eslint --fix --ignore-path .eslintignore ./src/js/*'))
77
.pipe($.filelog('Fixing JS'));
88
});
99
};

package.json

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
{
22
"name": "react-tags",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Simple tagging component",
55
"main": "dist-components/Tags.js",
6+
"license": "MIT",
67
"repository": {
78
"type": "git",
89
"url": "https://github.com/JFusco/react-tags"
910
},
11+
"author": {
12+
"name": "Joe Fusco",
13+
"email": "jfusco311@gmail.com"
14+
},
15+
"keywords": [
16+
"react",
17+
"tags",
18+
"react component",
19+
"tagging",
20+
"tag input",
21+
"es6"
22+
],
1023
"peerDependencies": {
1124
"react": "^15.2.1",
1225
"react-addons-update": "^15.2.1"
@@ -18,24 +31,24 @@
1831
"babel-preset-es2015": "^6.9.0",
1932
"babel-preset-react": "^6.11.1",
2033
"babel-register": "^6.9.0",
21-
"babel-eslint": "~6.0.4",
34+
"babel-eslint": "^6.1.2",
2235
"gulp-sass": "^2.3.2",
2336
"gulp-shell": "^0.5.2",
24-
"http-server": "^0.9.0",
25-
"react": "^15.2.1",
26-
"react-addons-update": "^15.2.1",
27-
"webpack": "^1.13.1",
2837
"gulp": "^3.9.1",
2938
"gulp-rename": "^1.2.2",
30-
"gulp-eslint": "~2.0.0",
39+
"gulp-eslint": "^3.0.1",
3140
"gulp-load-plugins": "~1.2.4",
3241
"gulp-clean-css": "^2.0.11",
33-
"gulp-scss-lint": "^0.3.9",
42+
"gulp-scss-lint": "^0.4.0",
3443
"gulp-scss-lint-stylish": "^1.0.1",
3544
"gulp-util": "~3.0.7",
3645
"gulp-watch": "~4.3.6",
37-
"run-sequence": "^1.2.1",
3846
"gulp-filelog": "~0.4.1",
47+
"http-server": "^0.9.0",
48+
"react": "^15.2.1",
49+
"react-addons-update": "^15.2.1",
50+
"webpack": "^1.13.1",
51+
"run-sequence": "^1.2.1",
3952
"minimist": "~1.2.0"
4053
}
4154
}

src/js/Tags.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export default class Tags extends Component{
4646
addTag(){
4747
const value = this.input.value.trim();
4848

49+
if (!this.props.allowDupes){
50+
if (this.state.tags.indexOf(value) >= 0) return;
51+
}
52+
4953
this.setState({
5054
tags: update(this.state.tags, {$push: [value] })
5155
}, () => {

0 commit comments

Comments
 (0)