Skip to content

Commit fca4d8a

Browse files
committed
Use className as property
1 parent e786052 commit fca4d8a

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

components/input/index.cjsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,31 @@ module.exports = React.createClass
88

99
# -- States & Properties
1010
propTypes:
11-
type : React.PropTypes.string
12-
label : React.PropTypes.string
13-
value : React.PropTypes.string
14-
error : React.PropTypes.string
15-
required : React.PropTypes.bool
11+
className : React.PropTypes.string
1612
disabled : React.PropTypes.bool
13+
error : React.PropTypes.string
14+
label : React.PropTypes.string
1715
multiline : React.PropTypes.bool
1816
onChange : React.PropTypes.func
1917
onKeyPress : React.PropTypes.func
2018
onFocus : React.PropTypes.func
2119
onBlur : React.PropTypes.func
20+
required : React.PropTypes.bool
21+
type : React.PropTypes.string
22+
value : React.PropTypes.string
2223

2324
getDefaultProps: ->
24-
type : "text"
25-
required : false
25+
className : ''
2626
disabled : false
2727
multiline : false
28+
required : false
29+
type : 'text'
2830

2931
getInitialState: ->
30-
value : @props.value
3132
checked : @props.value
3233
error : @props.error
33-
touch : @props.type in ["checkbox", "radio"]
34+
touch : @props.type in ['checkbox', 'radio']
35+
value : @props.value
3436

3537
# -- Events
3638
onChange: (event) ->
@@ -42,39 +44,39 @@ module.exports = React.createClass
4244

4345
# -- Render
4446
render: ->
45-
className = ""
46-
className += " disabled" if @props.disabled
47-
className += " error" if @state.error
48-
className += " touch" if @state.touch
49-
className += " radio" if @props.type is "radio"
50-
className += " checked" if @state.checked
47+
className = @props.className
48+
className += ' disabled' if @props.disabled
49+
className += ' error' if @state.error
50+
className += ' touch' if @state.touch
51+
className += ' radio' if @props.type is 'radio'
52+
className += ' checked' if @state.checked
5153

5254
<div data-component-input={@props.type} className={className}>
5355
{
5456
if @props.multiline
55-
<textarea ref="input" {...@props} value={@state.value}
57+
<textarea ref='input' {...@props} value={@state.value}
5658
onChange={@onChange}
5759
onKeyPress={@props.onKeyPress}
5860
onFocus={@props.onFocus}
5961
onBlur={@props.onBlur}>{@state.value}</textarea>
6062
else
61-
<input ref="input" {...@props} value={@state.value} checked={@state.checked
63+
<input ref='input' {...@props} value={@state.value} checked={@state.checked
6264
onChange={@onChange}
6365
onKeyPress={@props.onKeyPress}
6466
onFocus={@props.onFocus}
6567
onBlur={@props.onBlur}/>
6668
}
67-
<span className="bar"></span>
69+
<span className='bar'></span>
6870
{ <label>{@props.label}</label> if @props.label }
69-
{ <span className="error">{@state.error}</span> if @state.error }
71+
{ <span className='error'>{@state.error}</span> if @state.error }
7072
</div>
7173

7274
# -- Extends
7375
getValue: ->
74-
@refs.input?.getDOMNode()[if @state.touch then "checked" else "value"]
76+
@refs.input?.getDOMNode()[if @state.touch then 'checked' else 'value']
7577

7678
setValue: (data) ->
7779
@setState value: data
7880

79-
setError: (data = "Unknown error") ->
81+
setError: (data = 'Unknown error') ->
8082
@setState error: @props.error or data

0 commit comments

Comments
 (0)