Skip to content

Commit

Permalink
Fix js style
Browse files Browse the repository at this point in the history
  • Loading branch information
rkit committed Jan 29, 2016
1 parent a3df6d9 commit a324cda
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 40 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": "airbnb",
"parser": "babel-eslint",
"rules": {
// max length
"max-len": [2, 120, 2],
Expand Down
46 changes: 27 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import Select2 from 'react-select2-wrapper';

<Select2
multiple={true}
data={['bug', 'feature', 'documents', 'discussion']}
options={{
placeholder: 'search by tags',
}} />
multiple
data={['bug', 'feature', 'documents', 'discussion']}
options={
{
placeholder: 'search by tags',
}
}
/>
```

### With data as an object
Expand All @@ -37,23 +40,26 @@ import Select2 from 'react-select2-wrapper';
]}
options={{
placeholder: 'search by tags',
}} />
}}
/>
```

### With callbacks

```js
<Select2
multiple={true}
data={['bug', 'feature', 'documents', 'discussion']}
onOpen={() => { console.log('onOpen'); } }
onClose={() => { console.log('onClose'); } }
onSelect={() => { console.log('onSelect'); } }
onChange={() => { console.log('onChange'); } }
onUnselect={() => { console.log('onUnselect'); } }
options={{
placeholder: 'search by tags',
}} />
multiple
data={['bug', 'feature', 'documents', 'discussion']}
onOpen={this.cbOpen}
onClose={this.cbClose}
onSelect={this.cbSelect}
onChange={this.cbChange}
onUnselect={this.cbUnselect}
options={{
placeholder: 'search by tags',
}
}
/>
```

### With default value
Expand All @@ -70,14 +76,15 @@ import Select2 from 'react-select2-wrapper';
]}
options={{
placeholder: 'search by tags',
}} />
}}
/>
```

### With default multiple value

```js
<Select2
multiple={true}
multiple
defaultValue={[1, 4]}
data={[
{ text: 'bug', id: 1 },
Expand All @@ -87,7 +94,8 @@ import Select2 from 'react-select2-wrapper';
]}
options={{
placeholder: 'search by tags',
}} />
}}
/>
```

### Properties
Expand Down
54 changes: 35 additions & 19 deletions examples/src/components/Tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ export default class Tags extends Component {
<div>
Basic usage<br/>
<Select2
multiple={true}
data={['bug', 'feature', 'documents', 'discussion']}
options={{
placeholder: 'search by tags',
}} />
multiple
data={['bug', 'feature', 'documents', 'discussion']}
options={
{
placeholder: 'search by tags',
}
}
/>

<br/><br/>

With data as an object<br/>
<Select2
multiple={false}
Expand All @@ -25,21 +30,28 @@ export default class Tags extends Component {
]}
options={{
placeholder: 'search by tags',
}} />
}}
/>

<br/><br/>

With callbacks<br/>
<Select2
multiple={true}
data={['bug', 'feature', 'documents', 'discussion']}
onOpen={() => { console.log('onOpen'); } }
onClose={() => { console.log('onClose'); } }
onSelect={() => { console.log('onSelect'); } }
onChange={() => { console.log('onChange'); } }
onUnselect={() => { console.log('onUnselect'); } }
options={{
placeholder: 'search by tags',
}} />
multiple
data={['bug', 'feature', 'documents', 'discussion']}
onOpen={this.cbOpen}
onClose={this.cbClose}
onSelect={this.cbSelect}
onChange={this.cbChange}
onUnselect={this.cbUnselect}
options={{
placeholder: 'search by tags',
}
}
/>

<br/><br/>

With default value<br/>
<Select2
multiple={false}
Expand All @@ -52,11 +64,14 @@ export default class Tags extends Component {
]}
options={{
placeholder: 'search by tags',
}} />
}}
/>

<br/><br/>

With default multiple value<br/>
<Select2
multiple={true}
multiple
defaultValue={[1, 4]}
data={[
{ text: 'bug', id: 1 },
Expand All @@ -66,7 +81,8 @@ export default class Tags extends Component {
]}
options={{
placeholder: 'search by tags',
}} />
}}
/>
</div>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export default class Select2 extends Component {
{data.map((item, k) => {
if (typeof item === 'string' ||
((!!item && typeof item === 'object') && Object.prototype.toString.call(item) === '[object String]')) {
return (<option key={'option-' + k} value={item}>{item}</option>);
return (<option key={`option-${k}`} value={item}>{item}</option>);
}

const { id, text, ...itemParams } = item;
return (<option key={'option-' + k} value={id} {...itemParams}>{text}</option>);
return (<option key={`option-${k}`} value={id} {...itemParams}>{text}</option>);
})}
</select>
);
Expand Down

0 comments on commit a324cda

Please sign in to comment.