1
+ // NOTE: https://github.com/react-bootstrap/react-bootstrap/issues/1850 seesm to require string
2
+ // refs and not the callback kind.
3
+ /* eslint-disable react/no-find-dom-node, react/no-string-refs */
1
4
import React , { PropTypes } from 'react' ;
2
-
3
- import Row from 'react-bootstrap/lib/Row' ;
5
+ import ReactDOM from 'react-dom' ;
4
6
import Col from 'react-bootstrap/lib/Col' ;
7
+ import FormControl from 'react-bootstrap/lib/FormControl' ;
8
+ import ControlLabel from 'react-bootstrap/lib/ControlLabel' ;
9
+ import Form from 'react-bootstrap/lib/Form' ;
10
+ import FormGroup from 'react-bootstrap/lib/FormGroup' ;
11
+ import Button from 'react-bootstrap/lib/Button' ;
5
12
import Nav from 'react-bootstrap/lib/Nav' ;
6
13
import NavItem from 'react-bootstrap/lib/NavItem' ;
7
14
import Alert from 'react-bootstrap/lib/Alert' ;
@@ -10,7 +17,7 @@ import _ from 'lodash';
10
17
11
18
import BaseComponent from 'libs/components/BaseComponent' ;
12
19
13
- import Input from '../../Input ' ;
20
+ import css from './CommentForm.scss ' ;
14
21
15
22
const emptyComment = { author : '' , text : '' } ;
16
23
const textPlaceholder = 'Say something using markdown...' ;
@@ -57,22 +64,22 @@ export default class CommentForm extends BaseComponent {
57
64
switch ( this . state . formMode ) {
58
65
case 0 :
59
66
comment = {
60
- author : this . horizontalAuthorNode . getValue ( ) ,
61
- text : this . horizontalTextNode . getValue ( ) ,
67
+ author : ReactDOM . findDOMNode ( this . refs . horizontalAuthorNode ) . value ,
68
+ text : ReactDOM . findDOMNode ( this . refs . horizontalTextNode ) . value ,
62
69
} ;
63
70
break ;
64
71
case 1 :
65
72
comment = {
66
- author : this . stackedAuthorNode . getValue ( ) ,
67
- text : this . stackedTextNode . getValue ( ) ,
73
+ author : ReactDOM . findDOMNode ( this . refs . stackedAuthorNode ) . value ,
74
+ text : ReactDOM . findDOMNode ( this . refs . stackedTextNode ) . value ,
68
75
} ;
69
76
break ;
70
77
case 2 :
71
78
comment = {
72
79
// This is different because the input is a native HTML element
73
80
// rather than a React element.
74
- author : this . inlineAuthorNode . value ,
75
- text : this . inlineTextNode . value ,
81
+ author : ReactDOM . findDOMNode ( this . refs . inlineAuthorNode ) . value ,
82
+ text : ReactDOM . findDOMNode ( this . refs . inlineTextNode ) . value ,
76
83
} ;
77
84
break ;
78
85
default :
@@ -100,13 +107,13 @@ export default class CommentForm extends BaseComponent {
100
107
let ref ;
101
108
switch ( this . state . formMode ) {
102
109
case 0 :
103
- ref = this . horizontalTextNode . getInputDOMNode ( ) ;
110
+ ref = ReactDOM . findDOMNode ( this . refs . horizontalTextNode ) ;
104
111
break ;
105
112
case 1 :
106
- ref = this . stackedTextNode . getInputDOMNode ( ) ;
113
+ ref = ReactDOM . findDOMNode ( this . refs . stackedTextNode ) ;
107
114
break ;
108
115
case 2 :
109
- ref = this . inlineTextNode ;
116
+ ref = ReactDOM . findDOMNode ( this . refs . inlineTextNode ) ;
110
117
break ;
111
118
default :
112
119
throw new Error ( `Unexpected state.formMode ${ this . state . formMode } ` ) ;
@@ -119,44 +126,52 @@ export default class CommentForm extends BaseComponent {
119
126
return (
120
127
< div >
121
128
< hr />
122
- < form className = "commentForm form-horizontal" onSubmit = { this . handleSubmit } >
123
- < Input
124
- type = "text"
125
- label = "Name"
126
- placeholder = "Your Name"
127
- labelClassName = "col-sm-2"
128
- wrapperClassName = "col-sm-10"
129
- ref = { ( node ) => { this . horizontalAuthorNode = node ; } }
130
- value = { this . state . comment . author }
131
- onChange = { this . handleChange }
132
- disabled = { this . props . isSaving }
133
- hasFeedback
134
- bsStyle = { bsStyleFor ( 'author' , this . props . error ) }
135
- />
136
- < Input
137
- type = "textarea"
138
- label = "Text"
139
- placeholder = { textPlaceholder }
140
- labelClassName = "col-sm-2"
141
- wrapperClassName = "col-sm-10"
142
- ref = { ( node ) => { this . horizontalTextNode = node ; } }
143
- value = { this . state . comment . text }
144
- onChange = { this . handleChange }
145
- disabled = { this . props . isSaving }
146
- hasFeedback
147
- bsStyle = { bsStyleFor ( 'text' , this . props . error ) }
148
- />
149
- < div className = "form-group" >
150
- < div className = "col-sm-offset-2 col-sm-10" >
151
- < input
129
+ < Form horizontal className = "commentForm form-horizontal" onSubmit = { this . handleSubmit } >
130
+ < FormGroup controlId = "formHorizontalName" >
131
+ < Col componentClass = { ControlLabel } sm = { 2 } >
132
+ Name
133
+ </ Col >
134
+ < Col sm = { 10 } >
135
+ < FormControl
136
+ type = "text"
137
+ placeholder = "Your Name"
138
+ ref = "horizontalAuthorNode"
139
+ value = { this . state . comment . author }
140
+ onChange = { this . handleChange }
141
+ disabled = { this . props . isSaving }
142
+ bsStyle = { bsStyleFor ( 'author' , this . props . error ) }
143
+ />
144
+ </ Col >
145
+ </ FormGroup >
146
+ < FormGroup controlId = "formHorizontalName" >
147
+ < Col componentClass = { ControlLabel } sm = { 2 } >
148
+ Text
149
+ </ Col >
150
+ < Col sm = { 10 } >
151
+ < FormControl
152
+ type = "textarea"
153
+ label = "Text"
154
+ placeholder = { textPlaceholder }
155
+ ref = "horizontalTextNode"
156
+ value = { this . state . comment . text }
157
+ onChange = { this . handleChange }
158
+ disabled = { this . props . isSaving }
159
+ bsStyle = { bsStyleFor ( 'text' , this . props . error ) }
160
+ />
161
+ </ Col >
162
+ </ FormGroup >
163
+ < FormGroup controlId = "formHorizontalSubmit" >
164
+ < Col smOffset = { 2 } sm = { 10 } >
165
+ < Button
152
166
type = "submit"
153
167
className = "btn btn-primary"
154
- value = { this . props . isSaving ? 'Saving...' : 'Post' }
155
168
disabled = { this . props . isSaving }
156
- />
157
- </ div >
158
- </ div >
159
- </ form >
169
+ >
170
+ { this . props . isSaving ? 'Saving...' : 'Post' }
171
+ </ Button >
172
+ </ Col >
173
+ </ FormGroup >
174
+ </ Form >
160
175
</ div >
161
176
) ;
162
177
}
@@ -166,79 +181,92 @@ export default class CommentForm extends BaseComponent {
166
181
< div >
167
182
< hr />
168
183
< form className = "commentForm form" onSubmit = { this . handleSubmit } >
169
- < Input
170
- type = "text"
171
- label = "Name"
172
- placeholder = "Your Name"
173
- ref = { ( node ) => { this . stackedAuthorNode = node ; } }
174
- value = { this . state . comment . author }
175
- onChange = { this . handleChange }
176
- disabled = { this . props . isSaving }
177
- hasFeedback
178
- bsStyle = { bsStyleFor ( 'author' , this . props . error ) }
179
- />
180
- < Input
181
- type = "textarea"
182
- label = "Text"
183
- placeholder = { textPlaceholder }
184
- ref = { ( node ) => { this . stackedTextNode = node ; } }
185
- value = { this . state . comment . text }
186
- onChange = { this . handleChange }
187
- disabled = { this . props . isSaving }
188
- hasFeedback
189
- bsStyle = { bsStyleFor ( 'text' , this . props . error ) }
190
- />
191
- < input
192
- type = "submit"
193
- className = "btn btn-primary"
194
- value = { this . props . isSaving ? 'Saving...' : 'Post' }
195
- disabled = { this . props . isSaving }
196
- />
184
+ < FormGroup controlId = "formBasicName" >
185
+ < ControlLabel > Name</ ControlLabel >
186
+ < FormControl
187
+ type = "text"
188
+ placeholder = "Your Name"
189
+ ref = "stackedAuthorNode"
190
+ value = { this . state . comment . author }
191
+ onChange = { this . handleChange }
192
+ disabled = { this . props . isSaving }
193
+ bsStyle = { bsStyleFor ( 'author' , this . props . error ) }
194
+ />
195
+ </ FormGroup >
196
+ < FormGroup
197
+ controlId = "formBasicText"
198
+ >
199
+ < ControlLabel > Text</ ControlLabel >
200
+ < FormControl
201
+ type = "textarea"
202
+ label = "Text"
203
+ placeholder = { textPlaceholder }
204
+ ref = "stackedTextNode"
205
+ value = { this . state . comment . text }
206
+ onChange = { this . handleChange }
207
+ disabled = { this . props . isSaving }
208
+ bsStyle = { bsStyleFor ( 'text' , this . props . error ) }
209
+ />
210
+ </ FormGroup >
211
+ < FormGroup controlId = "formBasicSubmit" >
212
+ < Button
213
+ type = "submit"
214
+ className = "btn btn-primary"
215
+ disabled = { this . props . isSaving }
216
+ >
217
+ { this . props . isSaving ? 'Saving...' : 'Post' }
218
+ </ Button >
219
+ </ FormGroup >
197
220
</ form >
198
221
</ div >
199
222
) ;
200
223
}
201
224
225
+ // Head up! We have some CSS modules going on here with the className props below.
202
226
formInline ( ) {
203
227
return (
204
228
< div >
205
229
< hr />
206
- < form className = "commentForm form" onSubmit = { this . handleSubmit } >
207
- < Input label = "Inline Form" wrapperClassName = "wrapper" >
208
- < Row >
209
- < Col xs = { 3 } >
210
- < input
211
- type = "text"
212
- className = "form-control"
213
- placeholder = "Your Name"
214
- ref = { ( node ) => { this . inlineAuthorNode = node ; } }
215
- value = { this . state . comment . author }
216
- onChange = { this . handleChange }
217
- disabled = { this . props . isSaving }
218
- />
219
- </ Col >
220
- < Col xs = { 8 } >
221
- < input
222
- type = "text"
223
- className = "form-control"
224
- placeholder = { textPlaceholder }
225
- ref = { ( node ) => { this . inlineTextNode = node ; } }
226
- value = { this . state . comment . text }
227
- onChange = { this . handleChange }
228
- disabled = { this . props . isSaving }
229
- />
230
- </ Col >
231
- < Col xs = { 1 } >
232
- < input
233
- type = "submit"
234
- className = "btn btn-primary"
235
- value = { this . props . isSaving ? 'Saving...' : 'Post' }
236
- disabled = { this . props . isSaving }
237
- />
238
- </ Col >
239
- </ Row >
240
- </ Input >
241
- </ form >
230
+ < Form inline className = "commentForm form-inline" onSubmit = { this . handleSubmit } >
231
+ < FormGroup controlId = "formInlineName" >
232
+ < ControlLabel >
233
+ Name
234
+ </ ControlLabel >
235
+ < FormControl
236
+ type = "text"
237
+ placeholder = "Your Name"
238
+ ref = "inlineAuthorNode"
239
+ value = { this . state . comment . author }
240
+ onChange = { this . handleChange }
241
+ disabled = { this . props . isSaving }
242
+ bsStyle = { bsStyleFor ( 'author' , this . props . error ) }
243
+ className = { css . nameFormControl }
244
+ />
245
+ </ FormGroup >
246
+ < FormGroup controlId = "formInlineName" >
247
+ < ControlLabel >
248
+ Text
249
+ </ ControlLabel >
250
+ < FormControl
251
+ type = "textarea"
252
+ label = "Text"
253
+ placeholder = { textPlaceholder }
254
+ ref = "inlineTextNode"
255
+ value = { this . state . comment . text }
256
+ onChange = { this . handleChange }
257
+ disabled = { this . props . isSaving }
258
+ bsStyle = { bsStyleFor ( 'text' , this . props . error ) }
259
+ className = { css . textFormControl }
260
+ />
261
+ </ FormGroup >
262
+ < Button
263
+ type = "submit"
264
+ className = "btn btn-primary"
265
+ disabled = { this . props . isSaving }
266
+ >
267
+ { this . props . isSaving ? 'Saving...' : 'Post' }
268
+ </ Button >
269
+ </ Form >
242
270
</ div >
243
271
) ;
244
272
}
0 commit comments