Skip to content
This repository was archived by the owner on Dec 23, 2022. It is now read-only.

Commit a63a14d

Browse files
committed
Lint the code with standard style.
1 parent 6e1ca55 commit a63a14d

File tree

5 files changed

+86
-79
lines changed

5 files changed

+86
-79
lines changed

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"main": "lib/ChipInput.js",
66
"scripts": {
77
"build": "babel src -d lib",
8+
"test": "standard",
9+
"lint": "standard",
810
"prepublish": "babel src -d lib",
911
"storybook": "start-storybook -p 6006",
1012
"deploy-storybook": "storybook-to-ghpages"
@@ -31,14 +33,16 @@
3133
"@kadira/storybook-deployer": "^1.2.0",
3234
"babel-cli": "^6.14.0",
3335
"babel-core": "^6.8.0",
36+
"babel-eslint": "^7.2.3",
3437
"babel-plugin-transform-object-assign": "^6.8.0",
3538
"babel-preset-es2015": "^6.14.0",
3639
"babel-preset-react": "^6.11.1",
3740
"babel-preset-stage-0": "^6.5.0",
3841
"material-ui": "^0.17.0",
3942
"react": "^15.4.0",
4043
"react-dom": "^15.4.0",
41-
"react-tap-event-plugin": "^2.0.0"
44+
"react-tap-event-plugin": "^2.0.0",
45+
"standard": "^10.0.2"
4246
},
4347
"peerDependencies": {
4448
"material-ui": ">= 0.15.0 <= 0.17.x",
@@ -48,5 +52,8 @@
4852
},
4953
"dependencies": {
5054
"prop-types": "^15.5.7"
55+
},
56+
"standard": {
57+
"parser": "babel-eslint"
5158
}
5259
}

src/ChipInput.js

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import AutoComplete from 'material-ui/AutoComplete/AutoComplete'
1111
import transitions from 'material-ui/styles/transitions'
1212
import Chip from 'material-ui/Chip'
1313
import {blue300} from 'material-ui/styles/colors'
14-
import {fade} from 'material-ui/utils/colorManipulator'
1514

1615
const getStyles = (props, context, state) => {
1716
const {
@@ -22,9 +21,9 @@ const getStyles = (props, context, state) => {
2221
textColor,
2322
disabledTextColor,
2423
backgroundColor,
25-
errorColor,
26-
},
27-
} = context.muiTheme;
24+
errorColor
25+
}
26+
} = context.muiTheme
2827

2928
const styles = {
3029
root: {
@@ -54,15 +53,15 @@ const getStyles = (props, context, state) => {
5453
font: 'inherit',
5554
appearance: 'none', // Remove border in Safari, doesn't seem to break anything in other browsers
5655
WebkitTapHighlightColor: 'rgba(0,0,0,0)', // Remove mobile color flashing (deprecated style).
57-
float: 'left',
56+
float: 'left'
5857
},
5958
error: {
6059
position: 'absolute',
6160
bottom: -10,
6261
fontSize: 12,
6362
lineHeight: '12px',
6463
color: errorColor,
65-
transition: transitions.easeOut(),
64+
transition: transitions.easeOut()
6665
},
6766
floatingLabel: {
6867
color: props.disabled ? disabledTextColor : floatingLabelColor,
@@ -76,24 +75,24 @@ const getStyles = (props, context, state) => {
7675
margin: '8px 8px 0 0',
7776
float: 'left'
7877
}
79-
};
78+
}
8079

8180
if (state.isFocused) {
82-
styles.floatingLabel.color = focusColor;
81+
styles.floatingLabel.color = focusColor
8382
}
8483

8584
if (props.floatingLabelText) {
86-
styles.input.boxSizing = 'border-box';
85+
styles.input.boxSizing = 'border-box'
8786
}
8887

8988
if (state.errorText) {
9089
if (state.isFocused) {
91-
styles.floatingLabel.color = styles.error.color;
90+
styles.floatingLabel.color = styles.error.color
9291
}
9392
}
9493

95-
return styles;
96-
};
94+
return styles
95+
}
9796

9897
const defaultChipRenderer = ({ value, text, isFocused, isDisabled, handleClick, handleRequestDelete, defaultStyle }, key) => (
9998
<Chip
@@ -109,7 +108,7 @@ const defaultChipRenderer = ({ value, text, isFocused, isDisabled, handleClick,
109108

110109
class ChipInput extends React.Component {
111110
static contextTypes = {
112-
muiTheme: PropTypes.object.isRequired,
111+
muiTheme: PropTypes.object.isRequired
113112
};
114113

115114
state = {
@@ -128,22 +127,22 @@ class ChipInput extends React.Component {
128127
}
129128
}
130129

131-
componentWillMount() {
130+
componentWillMount () {
132131
const {
133132
name,
134133
hintText,
135134
floatingLabelText
136-
} = this.props;
135+
} = this.props
137136

138137
this.setState({
139138
errorText: this.props.errorText
140139
})
141140

142-
const uniqueId = `${name}-${hintText}-${floatingLabelText}-${Math.floor(Math.random() * 0xFFFF)}`;
143-
this.uniqueId = uniqueId.replace(/[^A-Za-z0-9-]/gi, '');
141+
const uniqueId = `${name}-${hintText}-${floatingLabelText}-${Math.floor(Math.random() * 0xFFFF)}`
142+
this.uniqueId = uniqueId.replace(/[^A-Za-z0-9-]/gi, '')
144143
}
145144

146-
componentDidMount() {
145+
componentDidMount () {
147146
const handleKeyDown = this.autoComplete.handleKeyDown
148147
this.autoComplete.handleKeyDown = (event) => {
149148
if (this.props.newChipKeyCodes.indexOf(event.keyCode) >= 0) {
@@ -157,15 +156,15 @@ class ChipInput extends React.Component {
157156
}
158157

159158
this.autoComplete.handleItemTouchTap = (event, child) => {
160-
const dataSource = this.autoComplete.props.dataSource;
159+
const dataSource = this.autoComplete.props.dataSource
161160

162-
const index = parseInt(child.key, 10);
163-
const chosenRequest = dataSource[index];
161+
const index = parseInt(child.key, 10)
162+
const chosenRequest = dataSource[index]
164163
this.handleAddChip(chosenRequest)
165164

166165
this.autoComplete.setState({
167-
searchText: '',
168-
});
166+
searchText: ''
167+
})
169168
this.autoComplete.forceUpdate()
170169
this.autoComplete.close()
171170

@@ -187,17 +186,17 @@ class ChipInput extends React.Component {
187186
}
188187
}
189188

190-
blur() {
191-
if (this.input) this.getInputNode().blur();
189+
blur () {
190+
if (this.input) this.getInputNode().blur()
192191
}
193192

194-
focus() {
193+
focus () {
195194
if (this.autoComplete) {
196-
this.getInputNode().focus();
195+
this.getInputNode().focus()
197196
if (this.props.openOnFocus) {
198197
this.autoComplete.setState({
199198
open: true,
200-
anchorEl: this.getInputNode(),
199+
anchorEl: this.getInputNode()
201200
})
202201

203202
this.autoComplete.forceUpdate()
@@ -208,15 +207,15 @@ class ChipInput extends React.Component {
208207
}
209208
}
210209

211-
select() {
212-
if (this.input) this.getInputNode().select();
210+
select () {
211+
if (this.input) this.getInputNode().select()
213212
}
214213

215-
getValue() {
216-
return this.input ? this.getInputNode().value : undefined;
214+
getValue () {
215+
return this.input ? this.getInputNode().value : undefined
217216
}
218217

219-
getInputNode() {
218+
getInputNode () {
220219
return this.autoComplete.refs.searchTextField.getInputNode()
221220
}
222221

@@ -236,16 +235,16 @@ class ChipInput extends React.Component {
236235
}
237236
this.setState({ isFocused: false })
238237
}
239-
}, 0);
238+
}, 0)
240239
}
241240

242241
handleInputFocus = (event) => {
243242
if (this.props.disabled) {
244-
return;
243+
return
245244
}
246-
this.setState({isFocused: true});
245+
this.setState({isFocused: true})
247246
if (this.props.onFocus) {
248-
this.props.onFocus(event);
247+
this.props.onFocus(event)
249248
}
250249
}
251250

@@ -303,7 +302,7 @@ class ChipInput extends React.Component {
303302
if (typeof chip === 'string') {
304303
chip = {
305304
[this.props.dataSourceConfig.text]: chip,
306-
[this.props.dataSourceConfig.value]: chip,
305+
[this.props.dataSourceConfig.value]: chip
307306
}
308307
}
309308

@@ -410,7 +409,7 @@ class ChipInput extends React.Component {
410409
underlineFocusStyle,
411410
underlineShow,
412411
underlineStyle,
413-
defaultValue = [],
412+
defaultValue = [], // eslint-disable-line no-unused-vars
414413
filter,
415414
value,
416415
dataSource,
@@ -422,24 +421,24 @@ class ChipInput extends React.Component {
422421
onRequestDelete, // eslint-disable-line no-unused-vars
423422
chipRenderer = defaultChipRenderer,
424423
newChipKeyCodes, // eslint-disable-line no-unused-vars
425-
...other,
426-
} = this.props;
424+
...other
425+
} = this.props
427426

428-
const {prepareStyles} = this.context.muiTheme;
429-
const styles = getStyles(this.props, this.context, this.state);
430-
const inputId = id || this.uniqueId;
427+
const {prepareStyles} = this.context.muiTheme
428+
const styles = getStyles(this.props, this.context, this.state)
429+
const inputId = id || this.uniqueId
431430

432431
const inputProps = {
433432
id: inputId,
434-
ref: (elem) => this.input = elem,
433+
ref: (elem) => { this.input = elem },
435434
disabled: !!this.props.disabled,
436435
onBlur: this.handleInputBlur,
437436
onFocus: this.handleInputFocus,
438437
onKeyDown: this.handleKeyDown,
439438
fullWidth: !!fullWidthInput
440439
}
441440

442-
const inputStyleMerged = Object.assign(styles.input, inputStyle);
441+
const inputStyleMerged = Object.assign(styles.input, inputStyle)
443442

444443
const hasInput = (this.props.value || this.state.chips).length > 0 || this.state.inputValue.length > 0
445444
const showHintText = hintText && !hasInput
@@ -482,7 +481,7 @@ class ChipInput extends React.Component {
482481

483482
return (
484483
<div
485-
className={ className }
484+
className={className}
486485
style={prepareStyles(Object.assign(styles.root, style, overrideRootStyles))}
487486
onTouchTap={() => this.focus()}
488487
>
@@ -503,14 +502,14 @@ class ChipInput extends React.Component {
503502
})}
504503
</div>
505504
</div>
506-
{hintText ?
507-
<TextFieldHint
505+
{hintText
506+
? <TextFieldHint
508507
muiTheme={this.context.muiTheme}
509508
show={showHintText && !(floatingLabelText && !floatingLabelFixed && !this.state.isFocused)}
510509
style={Object.assign({ bottom: 20, pointerEvents: 'none' }, hintStyle)}
511510
text={hintText}
512-
/> :
513-
null
511+
/>
512+
: null
514513
}
515514
<AutoComplete
516515
{...other}
@@ -524,8 +523,8 @@ class ChipInput extends React.Component {
524523
onKeyUp={this.handleKeyUp}
525524
ref={this.setAutoComplete}
526525
/>
527-
{underlineShow ?
528-
<TextFieldUnderline
526+
{underlineShow
527+
? <TextFieldUnderline
529528
disabled={disabled}
530529
disabledStyle={underlineDisabledStyle}
531530
error={!!this.state.errorText}
@@ -534,8 +533,8 @@ class ChipInput extends React.Component {
534533
focusStyle={underlineFocusStyle}
535534
muiTheme={this.context.muiTheme}
536535
style={underlineStyle}
537-
/> :
538-
null
536+
/>
537+
: null
539538
}
540539
{errorTextElement}
541540
</div>

stories/ClipboardExample.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ import React from 'react'
22
import ChipInput from '../src/ChipInput'
33

44
class ClipboardExample extends React.Component {
5-
constructor(props) {
5+
constructor (props) {
66
super(props)
77
this.state = {
88
chips: []
99
}
1010
}
1111

12-
handleRequestAdd(...chips) {
12+
handleRequestAdd (...chips) {
1313
this.setState({
1414
chips: [...this.state.chips, ...chips]
1515
})
1616
}
1717

18-
handleRequestDelete(deletedChip) {
18+
handleRequestDelete (deletedChip) {
1919
this.setState({
2020
chips: this.state.chips.filter((c) => c !== deletedChip)
2121
})
2222
}
2323

24-
render() {
24+
render () {
2525
return (
2626
<ChipInput
2727
{...this.props}
28-
hintText="Paste anything here (try with line breaks)"
28+
hintText='Paste anything here (try with line breaks)'
2929

3030
value={this.state.chips}
3131
onPaste={(event) => {

0 commit comments

Comments
 (0)