Expand file tree Collapse file tree 6 files changed +77
-4
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import classNames from 'classnames' ;
3
+ import InputBase from '../InputBase' ;
4
+ import childrenValueValidation from '../utils/childrenValueInputValidation' ;
5
+
6
+ class Static extends InputBase {
7
+ getValue ( ) {
8
+ const { children, value} = this . props ;
9
+ return children ? children : value ;
10
+ }
11
+
12
+ renderInput ( ) {
13
+ return (
14
+ < p { ...this . props } className = { classNames ( this . props . className , 'form-control-static' ) } ref = "input" key = "input" >
15
+ { this . getValue ( ) }
16
+ </ p >
17
+ ) ;
18
+ }
19
+ }
20
+
21
+ Static . propTypes = {
22
+ value : childrenValueValidation ,
23
+ children : childrenValueValidation
24
+ } ;
25
+
26
+ export default Static ;
Original file line number Diff line number Diff line change
1
+ import Static from './Static' ;
2
+
3
+ export default {
4
+ Static
5
+ } ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import InputBase from './InputBase' ;
3
3
import ButtonInput from './ButtonInput' ;
4
+ import FormControls from './FormControls' ;
4
5
import deprecationWarning from './utils/deprecationWarning' ;
5
6
6
7
class Input extends InputBase {
7
8
render ( ) {
8
9
if ( ButtonInput . types . indexOf ( this . props . type ) > - 1 ) {
9
10
deprecationWarning ( `Input type=${ this . props . type } ` , 'ButtonInput' ) ;
10
11
return < ButtonInput { ...this . props } /> ;
12
+ } else if ( this . props . type === 'static' ) {
13
+ deprecationWarning ( 'Input type=static' , 'StaticText' ) ;
14
+ return < FormControls . Static { ...this . props } /> ;
11
15
}
12
16
13
17
return super . render ( ) ;
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import DropdownButton from './DropdownButton';
19
19
import DropdownMenu from './DropdownMenu' ;
20
20
import DropdownStateMixin from './DropdownStateMixin' ;
21
21
import FadeMixin from './FadeMixin' ;
22
+ import FormControls from './FormControls' ;
22
23
import Glyphicon from './Glyphicon' ;
23
24
import Grid from './Grid' ;
24
25
import Input from './Input' ;
@@ -75,6 +76,7 @@ export default {
75
76
DropdownMenu,
76
77
DropdownStateMixin,
77
78
FadeMixin,
79
+ FormControls,
78
80
Glyphicon,
79
81
Grid,
80
82
Input,
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import ReactTestUtils from 'react/lib/ReactTestUtils' ;
3
+ import FormControls from '../src/FormControls' ;
4
+
5
+ describe ( 'Form Controls' , function ( ) {
6
+ describe ( 'Static' , function ( ) {
7
+ it ( 'renders a p element wrapped around the given value' , function ( ) {
8
+ const instance = ReactTestUtils . renderIntoDocument (
9
+ < FormControls . Static value = 'v' />
10
+ ) ;
11
+
12
+ const result = ReactTestUtils . findRenderedDOMComponentWithTag ( instance , 'p' ) ;
13
+ result . props . children . should . equal ( 'v' ) ;
14
+ } ) ;
15
+
16
+ it ( 'getValue() pulls from either value or children' , function ( ) {
17
+ let instance = ReactTestUtils . renderIntoDocument (
18
+ < FormControls . Static value = 'v' />
19
+ ) ;
20
+
21
+ instance . getValue ( ) . should . equal ( 'v' ) ;
22
+
23
+ instance = ReactTestUtils . renderIntoDocument (
24
+ < FormControls . Static > 5</ FormControls . Static >
25
+ ) ;
26
+
27
+ instance . getValue ( ) . should . equal ( '5' ) ;
28
+ } ) ;
29
+
30
+ it ( 'throws an error if both value and children are provided' , function ( ) {
31
+ const testData = { value : 'blah' , children : 'meh' } ;
32
+ const result = FormControls . Static . propTypes . children ( testData , 'children' , 'Static' ) ;
33
+
34
+ result . should . be . instanceOf ( Error ) ;
35
+ } ) ;
36
+ } ) ;
37
+ } ) ;
Original file line number Diff line number Diff line change @@ -65,13 +65,12 @@ describe('Input', function () {
65
65
shouldWarn ( 'deprecated' ) ;
66
66
} ) ;
67
67
68
- it ( 'renders a p element when type=static' , function ( ) {
69
- let instance = ReactTestUtils . renderIntoDocument (
68
+ it ( 'throws a warning when type=static' , function ( ) {
69
+ ReactTestUtils . renderIntoDocument (
70
70
< Input type = "static" value = "v" />
71
71
) ;
72
72
73
- assert . ok ( ReactTestUtils . findRenderedDOMComponentWithTag ( instance , 'p' ) ) ;
74
- assert . equal ( instance . getValue ( ) , 'v' ) ;
73
+ shouldWarn ( 'deprecated' ) ;
75
74
} ) ;
76
75
77
76
it ( 'renders an input element of given type when type is anything else' , function ( ) {
0 commit comments