Skip to content

Commit 1387452

Browse files
committed
Update build config and use class methods for event handlers
1 parent dcecad2 commit 1387452

File tree

9 files changed

+119
-117
lines changed

9 files changed

+119
-117
lines changed

.gitignore

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
coverage
2-
demo/dist
3-
lib
4-
node_modules
5-
npm-debug.log
6-
umd
1+
/coverage
2+
/demo/dist
3+
/es
4+
/lib
5+
/node_modules
6+
/umd
7+
npm-debug.log*

.travis.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ sudo: false
22

33
language: node_js
44
node_js:
5-
- 4.2
6-
7-
cache:
8-
directories:
9-
- node_modules
10-
11-
after_success:
12-
- cat ./coverage/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js
5+
- 6
136

147
branches:
158
only:

CHANGES.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# 1.2.4 / 2015-11-12
1+
**Breaking:** Now requires React >= 0.14.9.
2+
3+
Changed: use `React.Component` and the prop-types module to avoid deprecation warnings.
4+
5+
Changed: link to [unpkg](https://npmcdn.com/) for UMD build distribution.
6+
7+
# 0.4.2 / 2015-11-12
28

39
Changed UMD build directory.
410

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015 Jonny Buchanan
1+
Copyright (c) 2017 Jonny Buchanan
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# react-filtered-multiselect
22

33
[![Travis][build-badge]][build]
4-
[![Codecov][coverage-badge]][coverage]
54
[![npm package][npm-badge]][npm]
65

76
A `<FilteredMultiSelect/>` React component, for making and adding to selections using a filtered multi-select.
@@ -34,31 +33,31 @@ Double-clicking will add the selected option to the selection.
3433

3534
**Node**
3635

37-
````
36+
```
3837
npm install react-filtered-multiselect
3938
```
4039

4140
```javascript
42-
var FilteredMultiSelect = require('react-filtered-multiselect')
43-
// or
4441
import FilteredMultiSelect from 'react-filtered-multiselect'
42+
// or
43+
const FilteredMultiSelect = require('react-filtered-multiselect')
4544
```
4645

4746
**Browser**
4847

4948
Browser bundles export a global ``FilteredMultiSelect`` variable and expect to find a global ``React`` variable to work with.
5049

51-
* [react-filtered-multiselect.js](https://npmcdn.com/react-filtered-multiselect/umd/react-filtered-multiselect.js) (development version)
52-
* [react-filtered-multiselect.min.js](https://npmcdn.com/react-filtered-multiselect/umd/react-filtered-multiselect.min.js) (compressed production version)
50+
* [react-filtered-multiselect.js](https://unpkg.com/react-filtered-multiselect/umd/react-filtered-multiselect.js) (development version)
51+
* [react-filtered-multiselect.min.js](https://unpkg.com/react-filtered-multiselect/umd/react-filtered-multiselect.min.js) (compressed production version)
5352

5453
## API
5554

5655
### Required props
5756

5857
Minimal usage:
5958

60-
```javascript
61-
var options = [
59+
```js
60+
let options = [
6261
{value: 1, text: 'Item One'},
6362
{value: 2, text: 'Item Two'}
6463
]
@@ -71,7 +70,7 @@ var options = [
7170

7271
`options` - list of objects providing `<option>` data for the multi-select. By default, these should have ``text`` and ``value`` properties, but this is configurable via props.
7372

74-
The component will update its display if its `options` list changes length or is replaced with a different list, but it will *not* be able to detect changes which don't affect length or object equality, such as replacement of one option with another. Consider using `react-addons-update` or other immutability helpers if you need to do this.
73+
The component will update its display if its `options` list changes length or is replaced with a different list, but it will *not* be able to detect changes which don't affect length or object equality, such as replacement of one option with another. Consider using [immutability-helper](https://github.com/kolodny/immutability-helper) or other immutability libraries if you need to do this.
7574

7675
`onChange(selectedOptions)` - callback which will be called with selected option objects each time the selection is added to.
7776

@@ -102,7 +101,7 @@ the `value` for its `<option>`.
102101

103102
### Default props
104103

105-
```javascript
104+
```js
106105
{
107106
buttonText: 'Select',
108107
className: 'FilteredMultiSelect',
@@ -127,28 +126,27 @@ the `value` for its `<option>`.
127126

128127
Example which implements display of selected items and de-selection.
129128

130-
```javascript
131-
var CULTURE_SHIPS = [
129+
```js
130+
const CULTURE_SHIPS = [
132131
{id: 1, name: '5*Gelish-Oplule'},
133132
{id: 2, name: '7*Uagren'},
134133
// ...
135134
{id: 249, name: 'Zero Gravitas'},
136135
{id: 250, name: 'Zoologist'}
137136
]
138137

139-
var Example = React.createClass({
140-
getInitialState() {
141-
return {selectedShips: []}
142-
},
138+
class Example extends React.Component {
139+
state = {selectedShips: []}
143140

144141
handleDeselect(index) {
145142
var selectedShips = this.state.selectedShips.slice()
146143
selectedShips.splice(index, 1)
147144
this.setState({selectedShips})
148-
},
149-
handleSelectionChange(selectedShips) {
145+
}
146+
147+
handleSelectionChange = (selectedShips) => {
150148
this.setState({selectedShips})
151-
},
149+
}
152150

153151
render() {
154152
var {selectedShips} = this.state
@@ -164,22 +162,19 @@ var Example = React.createClass({
164162
{selectedShips.length > 0 && <ul>
165163
{selectedShips.map((ship, i) => <li key={ship.id}>
166164
{`${ship.name} `}
167-
<button type="button" onClick={this.handleDeselect.bind(null, i)}>
165+
<button type="button" onClick={() => this.handleDeselect(i)}>
168166
&times;
169167
</button>
170168
</li>)}
171169
</ul>}
172170
</div>
173171
}
174-
})
172+
}
175173
```
176174
## MIT Licensed
177175

178-
[build-badge]: https://img.shields.io/travis/insin/react-filtered-multiselect/master.svg
176+
[build-badge]: https://img.shields.io/travis/insin/react-filtered-multiselect/master.png?style=flat-square
179177
[build]: https://travis-ci.org/insin/react-filtered-multiselect
180178

181-
[coverage-badge]: https://img.shields.io/codecov/c/github/insin/react-filtered-multiselect.svg
182-
[coverage]: https://codecov.io/github/insin/react-filtered-multiselect
183-
184-
[npm-badge]: https://img.shields.io/npm/v/react-filtered-multiselect.svg
179+
[npm-badge]: https://img.shields.io/npm/v/react-filtered-multiselect.png?style=flat-square
185180
[npm]: https://www.npmjs.org/package/react-filtered-multiselect

demo/src/index.js

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,27 @@ const BOOTSTRAP_CLASSES = {
1111
filter: 'form-control',
1212
select: 'form-control',
1313
button: 'btn btn btn-block btn-default',
14-
buttonActive: 'btn btn btn-block btn-primary'
14+
buttonActive: 'btn btn btn-block btn-primary',
1515
}
1616

17-
var BasicSelection = React.createClass({
18-
getInitialState() {
19-
return {
20-
selectedOptions: []
21-
}
22-
},
17+
class BasicSelection extends React.Component {
18+
state = {
19+
selectedOptions: []
20+
}
2321

24-
handleClearSelection() {
25-
this.setState({selectedOptions: []})
26-
},
2722
handleDeselect(index) {
2823
var selectedOptions = this.state.selectedOptions.slice()
2924
selectedOptions.splice(index, 1)
3025
this.setState({selectedOptions})
31-
},
32-
handleSelectionChange(selectedOptions) {
26+
}
27+
28+
handleClearSelection = (e) => {
29+
this.setState({selectedOptions: []})
30+
}
31+
handleSelectionChange = (selectedOptions) => {
3332
selectedOptions.sort((a, b) => a.id - b.id)
3433
this.setState({selectedOptions})
35-
},
34+
}
3635

3736
render() {
3837
var {selectedOptions} = this.state
@@ -53,7 +52,7 @@ var BasicSelection = React.createClass({
5352
{selectedOptions.length > 0 && <ol>
5453
{selectedOptions.map((ship, i) => <li key={ship.id}>
5554
{`${ship.name} `}
56-
<span style={{cursor: 'pointer'}} onClick={this.handleDeselect.bind(null, i)}>
55+
<span style={{cursor: 'pointer'}} onClick={() => this.handleDeselect(i)}>
5756
&times;
5857
</span>
5958
</li>)}
@@ -64,26 +63,24 @@ var BasicSelection = React.createClass({
6463
</div>
6564
</div>
6665
}
67-
})
66+
}
6867

69-
var AddRemoveSelection = React.createClass({
70-
getInitialState() {
71-
return {
72-
selectedOptions: []
73-
}
74-
},
68+
class AddRemoveSelection extends React.Component {
69+
state = {
70+
selectedOptions: []
71+
}
7572

76-
handleDeselect(deselectedOptions) {
73+
handleDeselect = (deselectedOptions) => {
7774
var selectedOptions = this.state.selectedOptions.slice()
7875
deselectedOptions.forEach(option => {
7976
selectedOptions.splice(selectedOptions.indexOf(option), 1)
8077
})
8178
this.setState({selectedOptions})
82-
},
83-
handleSelect(selectedOptions) {
79+
}
80+
handleSelect = (selectedOptions) => {
8481
selectedOptions.sort((a, b) => a.id - b.id)
8582
this.setState({selectedOptions})
86-
},
83+
}
8784

8885
render() {
8986
var {selectedOptions} = this.state
@@ -116,9 +113,9 @@ var AddRemoveSelection = React.createClass({
116113
</div>
117114
</div>
118115
}
119-
})
116+
}
120117

121-
var App = React.createClass({
118+
class App extends React.Component {
122119
render() {
123120
return <div className="container">
124121
<div className="row header">
@@ -137,12 +134,6 @@ var App = React.createClass({
137134
<AddRemoveSelection/>
138135
</div>
139136
}
140-
})
141-
142-
var app = document.querySelector('#app')
143-
if (!app) {
144-
app = document.createElement('div')
145-
app.id = 'app'
146-
document.body.appendChild(app)
147137
}
148-
render(<App/>, app)
138+
139+
render(<App/>, document.querySelector('#demo'))

nwb.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
type: 'react-component',
3+
npm: {
4+
umd: {
5+
global: 'FilteredMultiSelect',
6+
externals: {
7+
react: 'React'
8+
}
9+
}
10+
}
11+
}

package.json

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
11
{
22
"name": "react-filtered-multiselect",
3-
"description": "Filtered multi-select React component",
43
"version": "0.4.2",
4+
"description": "Filtered multi-select React component",
55
"main": "lib/index.js",
6-
"jsnext:main": "src/index.js",
7-
"global": "FilteredMultiSelect",
8-
"externals": {
9-
"react": "React"
10-
},
11-
"homepage": "https://github.com/insin/react-filtered-multiselect",
12-
"license": "MIT",
13-
"author": "Jonny Buchanan <[email protected]>",
14-
"scripts": {
15-
"test": "nwb lint"
16-
},
6+
"module": "es/index.js",
177
"files": [
8+
"es",
189
"lib",
19-
"src",
2010
"umd"
2111
],
12+
"scripts": {
13+
"build": "nwb build-react-component",
14+
"clean": "nwb clean-module && nwb clean-demo",
15+
"lint": "eslint src demo",
16+
"start": "nwb serve-react-demo",
17+
"test": "npm run lint"
18+
},
2219
"dependencies": {
2320
"prop-types": "^15.5.7"
2421
},
2522
"peerDependencies": {
26-
"react": ">=0.14.0"
23+
"react": ">=0.14.9"
2724
},
2825
"devDependencies": {
29-
"bootstrap": "3.3.5",
30-
"nwb": "*",
31-
"react": "0.14.2",
32-
"react-dom": "0.14.2"
26+
"bootstrap": "3.3.x",
27+
"eslint-config-jonnybuchanan": "5.0.x",
28+
"nwb": "0.16.x",
29+
"react": "15.x",
30+
"react-dom": "15.x"
3331
},
32+
"author": "Jonny Buchanan <[email protected]>",
33+
"homepage": "https://github.com/insin/react-filtered-multiselect",
34+
"license": "MIT",
3435
"repository": {
3536
"type": "git",
3637
"url": "https://github.com/insin/react-filtered-multiselect.git"

0 commit comments

Comments
 (0)