forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[changed] Moving type=static out of Input
Introducing the Static component. Usage of type=static is now deprecated. Please use Static instead.
- Loading branch information
Showing
6 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import InputBase from '../InputBase'; | ||
import childrenValueValidation from '../utils/childrenValueInputValidation'; | ||
|
||
class Static extends InputBase { | ||
getValue() { | ||
const {children, value} = this.props; | ||
return children ? children : value; | ||
} | ||
|
||
renderInput() { | ||
return ( | ||
<p {...this.props} className={classNames(this.props.className, 'form-control-static')} ref="input" key="input"> | ||
{this.getValue()} | ||
</p> | ||
); | ||
} | ||
} | ||
|
||
Static.propTypes = { | ||
value: childrenValueValidation, | ||
children: childrenValueValidation | ||
}; | ||
|
||
export default Static; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Static from './Static'; | ||
|
||
export default { | ||
Static | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import ReactTestUtils from 'react/lib/ReactTestUtils'; | ||
import FormControls from '../src/FormControls'; | ||
|
||
describe('Form Controls', function () { | ||
describe('Static', function () { | ||
it('renders a p element wrapped around the given value', function () { | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<FormControls.Static value='v' /> | ||
); | ||
|
||
const result = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'p'); | ||
result.props.children.should.equal('v'); | ||
}); | ||
|
||
it('getValue() pulls from either value or children', function () { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<FormControls.Static value='v' /> | ||
); | ||
|
||
instance.getValue().should.equal('v'); | ||
|
||
instance = ReactTestUtils.renderIntoDocument( | ||
<FormControls.Static>5</FormControls.Static> | ||
); | ||
|
||
instance.getValue().should.equal('5'); | ||
}); | ||
|
||
it('throws an error if both value and children are provided', function () { | ||
const testData = { value: 'blah', children: 'meh' }; | ||
const result = FormControls.Static.propTypes.children(testData, 'children', 'Static'); | ||
|
||
result.should.be.instanceOf(Error); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters