Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-multiselect

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-multiselect - npm Package Compare versions

Comparing version 0.2.0 to 0.3.1

.npmignore

24

package.json
{
"name": "react-multiselect",
"version": "0.2.0",
"version": "0.3.1",
"author": "James Barton <james@neodon.com>",

@@ -23,13 +23,17 @@ "license": "MIT",

},
"files": [
"src/"
],
"main": "main.js",
"main": "react-multiselect.js",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.5.0",
"grunt-react": "^0.9.0"
"browserify": "3.44.x",
"envify": "1.2.x",
"grunt": "0.4.x",
"grunt-browserify": "3.1.x",
"grunt-contrib-clean": "0.6.x",
"grunt-contrib-copy": "0.6.x",
"grunt-contrib-jshint": "0.10.x",
"grunt-contrib-nodeunit": "0.4.x",
"grunt-contrib-uglify": "0.5.x",
"grunt-react": "0.9.x",
"react": "0.11.x",
"react-tools": "0.11.x"
}
}

@@ -22,4 +22,4 @@ Please get in touch with me if you have any issues or suggestions for this project. It's under active development

Supports loading item lists dynamically with AJAX requests. Selections will remain across requests as long as the item
ids stay the same. This can be helpful where you need the items in one list to depend on the selections in another list
and want them to update dynamically.
ids stay the same. This can be helpful where you need the items in one multiselect to depend on the selections in another
multiselect and want them to update dynamically.

@@ -26,0 +26,0 @@ ## Examples

/** @jsx React.DOM */
var MultiSelectItem = React.createClass({
getDefaultProps: function() {
return {
visible: true,
selected: false,
text: '',
onClick: function() {}
(function (root, factory) {
if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(
require('react/addons')
);
}
else {
// Browser globals (root is window)
root.MultiSelect = factory(root.React);
}
}(this, function(React) {
var MultiSelectItem = React.createClass({
getDefaultProps: function() {
return {
visible: true,
selected: false,
text: '',
onClick: function() {}
}
},
render: function() {
return this.props.visible && <li
className={this.props.selected ? 'selected' : 'deselected'}
onClick={this.props.onClick}
>{this.props.text}</li>
}
},
render: function() {
return <li
className={this.props.selected ? 'selected' : 'deselected'}
onClick={this.props.onClick}
style={this.props.visible ? {} : {display: 'none'}}
>{this.props.text}</li>
}
})
})
var MultiSelect = React.createClass({
getDefaultProps: function() {
return {
items: [],
placeholder: 'Enter some filter text',
onChange: function() {},
onItemSelected: function() {},
onItemDeselected: function() {}
}
},
getInitialState: function() {
return {
selections: {},
filter: ''
}
},
handleItemClick: function(item) {
this.setSelected(item, !this.state.selections[item.id])
},
handleFilterChange: function(event) {
// Keep track of every change to the filter input
this.setState({ filter: event.target.value })
},
escapeRegExp: function(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
},
createItem: function(item) {
// Filter item visibility based on the filter input
var regex = new RegExp('.*'+this.escapeRegExp(this.state.filter)+'.*', 'i')
var text = 'text' in item ? item.text
: 'name' in item ? item.name
: item.id
return <MultiSelectItem
key={item.id}
text={text}
onClick={this.handleItemClick.bind(this, item)}
visible={regex.test(text)}
selected={this.state.selections[item.id] ? true : false}
/>
},
selectAll: function(event) {
this.setSelected(this.props.items, true)
},
selectNone: function(event) {
this.setSelected(this.props.items, false)
},
setSelected: function(items, selected) {
// Accept an array or a single item
if (!(items instanceof Array)) items = [items]
var selections = this.state.selections
for (var i in items) {
selections[items[i].id] = selected
var MultiSelect = React.createClass({
getDefaultProps: function() {
return {
items: [],
placeholder: 'Enter some filter text',
onChange: function() {},
onItemSelected: function() {},
onItemDeselected: function() {}
}
},
getInitialState: function() {
return {
selections: {},
filter: ''
}
},
handleItemClick: function(item) {
this.setSelected(item, !this.state.selections[item.id])
},
handleFilterChange: function(event) {
// Keep track of every change to the filter input
this.setState({ filter: event.target.value })
},
escapeRegExp: function(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
},
createItem: function(item) {
// Filter item visibility based on the filter input
var regex = new RegExp('.*'+this.escapeRegExp(this.state.filter)+'.*', 'i')
var text = 'text' in item ? item.text
: 'name' in item ? item.name
: item.id
return <MultiSelectItem
key={item.id}
text={text}
onClick={this.handleItemClick.bind(this, item)}
visible={regex.test(text)}
selected={this.state.selections[item.id] ? true : false}
/>
},
selectAll: function(event) {
this.setSelected(this.props.items, true)
},
selectNone: function(event) {
this.setSelected(this.props.items, false)
},
setSelected: function(items, selected) {
// Accept an array or a single item
if (!(items instanceof Array)) items = [items]
if (selected)
this.props.onItemSelected(items[i])
else
this.props.onItemDeselected(items[i])
var selections = this.state.selections
for (var i in items) {
selections[items[i].id] = selected
if (selected)
this.props.onItemSelected(items[i])
else
this.props.onItemDeselected(items[i])
}
this.setState({ selections: selections })
this.props.onChange(selections)
},
render: function() {
return (
<div className="multiselect">
<input onChange={this.handleFilterChange} value={this.state.filter} placeholder={this.props.placeholder} />
<ul>{this.props.items.map(this.createItem)}</ul>
<button onClick={this.selectAll}>Select all</button>&nbsp;
<button onClick={this.selectNone}>Select none</button>
</div>
)
}
this.setState({ selections: selections })
this.props.onChange(selections)
},
render: function() {
return (
<div className="multiselect">
<input onChange={this.handleFilterChange} value={this.state.filter} placeholder={this.props.placeholder} />
<ul>{this.props.items.map(this.createItem)}</ul>
<button onClick={this.selectAll}>Select all</button>&nbsp;
<button onClick={this.selectNone}>Select none</button>
</div>
)
}
})
})
return MultiSelect
}))
if (typeof module === 'undefined') {
window.MultiSelect = MultiSelect
} else {
module.exports = MultiSelect
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc