Created
July 13, 2018 17:56
-
-
Save jasonferrier/3659b2753da314614d1d932e4b2f0198 to your computer and use it in GitHub Desktop.
Reproduce syntax highlighting bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copied from JedWatson/react-select/master/examples/src/components/Multiselect.js on 2018-July-13 11:55:55 MDT */ | |
import React from 'react'; | |
import createClass from 'create-react-class'; | |
import PropTypes from 'prop-types'; | |
import Select from 'react-select'; | |
const FLAVOURS = [ | |
{ label: 'Chocolate', value: 'chocolate' }, | |
{ label: 'Vanilla', value: 'vanilla' }, | |
{ label: 'Strawberry', value: 'strawberry' }, | |
{ label: 'Caramel', value: 'caramel' }, | |
{ label: 'Cookies and Cream', value: 'cookiescream' }, | |
{ label: 'Peppermint', value: 'peppermint' }, | |
]; | |
const WHY_WOULD_YOU = [ | |
{ label: 'Chocolate (are you crazy?)', value: 'chocolate', disabled: true }, | |
].concat(FLAVOURS.slice(1)); | |
var MultiSelectField = createClass({ | |
displayName: 'MultiSelectField', | |
propTypes: { | |
label: PropTypes.string, | |
}, | |
getInitialState () { | |
return { | |
removeSelected: true, | |
disabled: false, | |
crazy: false, | |
stayOpen: false, | |
value: [], | |
rtl: false, | |
}; | |
}, | |
handleSelectChange (value) { | |
console.log('You\'ve selected:', value); | |
this.setState({ value }); | |
}, | |
toggleCheckbox (e) { | |
this.setState({ | |
[e.target.name]: e.target.checked, | |
}); | |
}, | |
toggleRtl (e) { | |
let rtl = e.target.checked; | |
this.setState({ rtl }); | |
}, | |
render () { | |
const { crazy, disabled, stayOpen, value } = this.state; | |
const options = crazy ? WHY_WOULD_YOU : FLAVOURS; | |
return ( | |
<div className="section"> | |
<h3 className="section-heading">{this.props.label} <a href="https://github.com/JedWatson/react-select/tree/master/examples/src/components/Multiselect.js">(Source)</a></h3> | |
<Select | |
closeOnSelect={!stayOpen} | |
disabled={disabled} | |
multi | |
onChange={this.handleSelectChange} | |
options={options} | |
placeholder="Select your favourite(s)" | |
removeSelected={this.state.removeSelected} | |
rtl={this.state.rtl} | |
simpleValue | |
value={value} | |
/> | |
<div className="checkbox-list"> | |
<label className="checkbox"> | |
<input type="checkbox" className="checkbox-control" name="removeSelected" checked={this.state.removeSelected} onChange={this.toggleCheckbox} /> | |
<span className="checkbox-label">Remove selected options</span> | |
</label> | |
<label className="checkbox"> | |
<input type="checkbox" className="checkbox-control" name="disabled" checked={this.state.disabled} onChange={this.toggleCheckbox} /> | |
<span className="checkbox-label">Disable the control</span> | |
</label> | |
<label className="checkbox"> | |
<input type="checkbox" className="checkbox-control" name="crazy" checked={crazy} onChange={this.toggleCheckbox} /> | |
<span className="checkbox-label">I don't like Chocolate (disabled the option)</span> | |
</label> | |
<label className="checkbox"> | |
<input type="checkbox" className="checkbox-control" name="stayOpen" checked={stayOpen} onChange={this.toggleCheckbox}/> | |
<span className="checkbox-label">Stay open when an Option is selected</span> | |
</label> | |
<label className="checkbox"> | |
<input type="checkbox" className="checkbox-control" name="rtl" checked={this.state.rtl} onChange={this.toggleCheckbox} /> | |
<span className="checkbox-label">rtl</span> | |
</label> | |
</div> | |
</div> | |
); | |
} | |
}); | |
module.exports = MultiSelectField; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment