Skip to content

Commit

Permalink
v0.4.0 - Updated to React 0.14 and re-configured development setup
Browse files Browse the repository at this point in the history
Removed .getDOMNode() as DOM node refs are now the node itself

New development setup:

- ES6 modules with jsnext:main configured in package.json
- ESLint (+ standard config with tweaks) instead of JSHint
- Webpack instead of Browserify
- npm scripts instead of Gulp, since Webpack handles build pipeline
- The demo is now built instead of using global modules from CDNs
  • Loading branch information
insin committed Oct 28, 2015
1 parent bfa1ee2 commit 55d2974
Show file tree
Hide file tree
Showing 22 changed files with 979 additions and 891 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"stage": 2,
"loose": "all"
}
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
demo/dist/
dist/
lib/
13 changes: 13 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": ["standard", "standard-react"],
"rules": {
"brace-style": [2, "stroustrup", {"allowSingleLine": true}],
"eqeqeq": [2, "smart"],
"jsx-quotes": [2, "prefer-double"],
"react/prop-types": 0,
"react/self-closing-comp": 0,
"react/wrap-multilines": 0,
"space-before-function-paren": [2, "never"]
},
"parser": "babel-eslint"
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
demo/dist
lib
node_modules
node_modules
24 changes: 0 additions & 24 deletions .jshintrc

This file was deleted.

11 changes: 6 additions & 5 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
demo
dist
src
.babelrc
.eslintignore
.eslintrc
.gitignore
.jshintrc
.npmignore
bootstrap-example.png
gulpfile.js
webpack.config.js
webpack.demo.config.js
webpack.prod.config.js
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- 0.12
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.0 - 2015-10-28

**Breaking:** Now requires React 0.14.

## 0.3.2 - 2015-03-11

Re-bundled with latest Browserify (9.x) and React (0.13.x), but still
Expand Down Expand Up @@ -34,4 +38,4 @@ No code changes - version bump to get correct package.json metadata into npm.

## 0.1.0 - 2014-11-13

Initial version.
Initial version.
4 changes: 1 addition & 3 deletions LICENSE.md → LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## react-filtered-multiselect

Copyright (c) 2015 Jonny Buchanan

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -18,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
115 changes: 47 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,102 +1,83 @@
## react-filtered-multiselect
# react-filtered-multiselect

A `<FilteredMultiSelect/>` React component, for making and adding to selections
using a filtered multi-select.
A `<FilteredMultiSelect/>` React component, for making and adding to selections using a filtered multi-select.

[Live example with Bootstrap styles applied](http://insin.github.io/react-filtered-multiselect/)

![FilteredMultiSelect with Bootstrap styles screenshot](https://github.com/insin/react-filtered-multiselect/raw/master/bootstrap-example.png "A FilteredMultiSelect with Bootstrap styles applied")

### Features
## Features

This component manages an `<input>`, a `<select multiple>` and a `<button>`.

You provide a list of objects to be used to populate the select and an `onChange`
callback function.
You provide a list of objects to be used to populate the select and an `onChange` callback function.

Typing in the the input will filter the select to items with matching option text.

When some of the select's options are selected, the button will become enabled.
Clicking it will select the objects backing the currently selected options.
When some of the select's options are selected, the button will become enabled. Clicking it will select the objects backing the currently selected options.

If only one option is displayed after filtering against the input, pressing Enter
in the input will select the object backing it.
If only one option is displayed after filtering against the input, pressing Enter in the input will select the object backing it.

When backing objects are selected, the `onChange` callback is executed, passing
a list of all backing objects selected so far.
When backing objects are selected, the `onChange` callback is executed, passing a list of all backing objects selected so far.

To hide already-selected items, pass them back to `FilteredMultiSelect` as its
`selectedOptions` prop. This can be more convenient than manually removing the
selected items from the list passed as `options`.
To hide already-selected items, pass them back to `FilteredMultiSelect` as its `selectedOptions` prop. This can be more convenient than manually removing the selected items from the list passed as `options`.

To deselect items, remove them from the list passed back via the `onChange`
callback and re-render the `FilteredMultiSelect` with the new list passed as its
`selectedOptions` prop.
To deselect items, remove them from the list passed back via the `onChange` callback and re-render the `FilteredMultiSelect` with the new list passed as its `selectedOptions` prop.

Double-clicking will add the selected option to the selection.

### Install
## Install

**Node**

react-filtered-multiselect can be used on the server, or bundled for the client
using an npm-compatible packaging system such as [Browserify](http://browserify.org/)
or [webpack](http://webpack.github.io/).

````
npm install react-filtered-multiselect
```
```javascript
var FilteredMultiSelect = require('react-filtered-multiselect')
// or
import FilteredMultiSelect from 'react-filtered-multiselect'
```
**Browser**
Browser bundles export a global ``FilteredMultiSelect`` variable and expect to
find a global ``React`` variable to work with.
Browser bundles export a global ``FilteredMultiSelect`` variable and expect to find a global ``React`` variable to work with.
* [react-filtered-multiselect.js](https://github.com/insin/react-filtered-multiselect/raw/master/dist/react-filtered-multiselect.js) (development version)
* [react-filtered-multiselect.min.js](https://github.com/insin/react-filtered-multiselect/raw/master/dist/react-filtered-multiselect.min.js) (compressed production version)
## API
### Required props
Minimal usage:
```javascript
var options = [
{value: 1, text: 'Item One'}
, {value: 2, text: 'Item Two'}
{value: 1, text: 'Item One'},
{value: 2, text: 'Item Two'}
]
<FilteredMultiSelect
onChange={this.onChange}
onChange={this.handleChange}
options={options}
/>
```
`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.
`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.
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.
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.
`onChange(selectedOptions)` - callback which will be called with selected option
objects each time the selection is added to.
`onChange(selectedOptions)` - callback which will be called with selected option objects each time the selection is added to.
### Optional props
`buttonText` - text to be displayed in the `<button>` for adding selected `<option>`s.
`className` - class name for the component's `<div>` container.
`classNames` - class names for each of the component's child elements. See the
default props below for properties. Defaults will be used for any properties not
specified via this prop.
`classNames` - class names for each of the component's child elements. See the default props below for properties. Defaults will be used for any properties not specified via this prop.
`defaultFilter` - default filter text to be applied to the `<select>`
Expand All @@ -115,7 +96,7 @@ the displayed text for its `<option>`.
`valueProp` - name of the property in each object in `options` which provides
the `value` for its `<option>`.
#### Default props
### Default props
```javascript
{
Expand All @@ -138,56 +119,54 @@ the `value` for its `<option>`.
}
```
### Example
## Example
Example which implements display of selected items and de-selection.
```javascript
var CULTURE_SHIPS = [
{id: 1, name: "5*Gelish-Oplule"}
, {id: 2, name: "7*Uagren"}
{id: 1, name: '5*Gelish-Oplule'},
{id: 2, name: '7*Uagren'},
// ...
, {id: 249, name: "Zero Gravitas"}
, {id: 250, name: "Zoologist"}
{id: 249, name: 'Zero Gravitas'},
{id: 250, name: 'Zoologist'}
]
var Example = React.createClass({
getInitialState: function() {
getInitialState() {
return {selectedShips: []}
},
_onSelectionChange: function(selectedShips) {
this.setState({selectedShips: selectedShips})
},
_onDeselect: function(index) {
handleDeselect(index) {
var selectedShips = this.state.selectedShips.slice()
selectedShips.splice(index, 1)
this.setState({selectedShips: selectedShips})
this.setState({selectedShips})
},
handleSelectionChange(selectedShips) {
this.setState({selectedShips})
},
render: function() {
render() {
var {selectedShips} = this.state
return <div>
<FilteredMultiSelect
onChange={this._onSelectionChange}
onChange={this.handleSelectionChange}
options={CULTURE_SHIPS}
selectedOptions={this.state.selectedShips}
selectedOptions={selectedShips}
textProp="name"
valueProp="id"
/>
{this.state.selectedShips.length === 0 && <p>(nothing selected yet)</p>}
{this.state.selectedShips.length > 0 && <ul>
{this.state.selectedShips.map(function(ship, i) {
return <li key={ship.id}>{ship.name}{' '}
<button type="button" onClick={this._onDeselect.bind(null, i)}>
&times;
</button>
</li>
}.bind(this))}
{selectedShips.length === 0 && <p>(nothing selected yet)</p>}
{selectedShips.length > 0 && <ul>
{selectedShips.map((ship, i) => <li key={ship.id}>
{`${ship.name} `}
<button type="button" onClick={this.handleDeselect.bind(null, i)}>
&times;
</button>
</li>)}
</ul>}
</div>
}
})
```
### MIT Licensed
## MIT Licensed
Loading

0 comments on commit 55d2974

Please sign in to comment.