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.
Merge pull request react-bootstrap#674 from aabenoja/static-split
Static FormControl Component
- Loading branch information
Showing
17 changed files
with
167 additions
and
24 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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
"CarouselItem", | ||
"Col", | ||
"DropdownButton", | ||
"FormControls", | ||
"Glyphicon", | ||
"Grid", | ||
"Input", | ||
|
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,9 @@ | ||
const staticTextExample = ( | ||
<form className="form-horizontal"> | ||
<FormControls.Static className="col-xs-10 col-xs-offset-2" value="I'm in a form" /> | ||
<FormControls.Static label="First Name" labelClassName="col-xs-2" wrapperClassName="col-xs-10" value="Billy" /> | ||
<FormControls.Static label="Last Name" labelClassName="col-xs-2" wrapperClassName="col-xs-10">Bob</FormControls.Static> | ||
</form> | ||
); | ||
|
||
React.render(staticTextExample, mountNode); |
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
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,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
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,14 @@ | ||
import React from 'react'; | ||
import { singlePropFrom } from './CustomPropTypes'; | ||
|
||
const propList = ['children', 'value']; | ||
const typeList = [React.PropTypes.number, React.PropTypes.string]; | ||
|
||
export default function valueValidation(props, propName, componentName) { | ||
let error = singlePropFrom(propList)(props, propName, componentName); | ||
if (!error) { | ||
const oneOfType = React.PropTypes.oneOfType(typeList); | ||
error = oneOfType(props, propName, componentName); | ||
} | ||
return 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
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