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.
image testing done add docs add comment for props * Merge previous three samples (ImageCircle, ImageRounded, ImageThumbnail) to one sample file (ImageShape) * Add ImageResponsive and ImageShape in ReactPlayground.js * Add Image source include in Samples.js fix the comment * Fix eslint issue on Image.js * Fix eslint issue on ImageSpec.js * remove src and alt * refactor test code to test attribute not props fix eslint
- Loading branch information
Showing
7 changed files
with
155 additions
and
0 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,5 @@ | ||
const imageResponsiveInstance = ( | ||
<Image src="/assets/thumbnail.png" responsive /> | ||
); | ||
|
||
React.render(imageResponsiveInstance, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const imageShapeInstance = ( | ||
<Grid> | ||
<Row> | ||
<Col xs={6} md={4}> | ||
<Image src="/assets/thumbnail.png" rounded /> | ||
</Col> | ||
<Col xs={6} md={4}> | ||
<Image src="/assets/thumbnail.png" circle /> | ||
</Col> | ||
<Col xs={6} md={4}> | ||
<Image src="/assets/thumbnail.png" thumbnail /> | ||
</Col> | ||
</Row> | ||
</Grid> | ||
); | ||
|
||
React.render(imageShapeInstance, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
const Image = React.createClass({ | ||
|
||
propTypes: { | ||
|
||
/** | ||
* Sets image as responsive image | ||
*/ | ||
responsive: React.PropTypes.bool, | ||
|
||
/** | ||
* Sets image shape as rounded | ||
*/ | ||
rounded: React.PropTypes.bool, | ||
|
||
/** | ||
* Sets image shape as circle | ||
*/ | ||
circle: React.PropTypes.bool, | ||
|
||
/** | ||
* Sets image shape as thumbnail | ||
*/ | ||
thumbnail: React.PropTypes.bool | ||
}, | ||
|
||
getDefaultProps() { | ||
return { | ||
responsive: false, | ||
rounded: false, | ||
circle: false, | ||
thumbnail: false | ||
}; | ||
}, | ||
|
||
render() { | ||
const classes = { | ||
'img-responsive': this.props.responsive, | ||
'img-rounded': this.props.rounded, | ||
'img-circle': this.props.circle, | ||
'img-thumbnail': this.props.thumbnail | ||
}; | ||
|
||
return ( | ||
<img {...this.props} className={classNames(this.props.className, classes)} /> | ||
); | ||
} | ||
}); | ||
|
||
export default Image; |
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,61 @@ | ||
import React from 'react'; | ||
import ReactTestUtils from 'react/lib/ReactTestUtils'; | ||
import Image from '../src/Image'; | ||
|
||
describe('Image', function() { | ||
|
||
it('should be an image', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<Image /> | ||
); | ||
let image = React.findDOMNode(instance); | ||
|
||
image.nodeName.should.equal('IMG'); | ||
}); | ||
|
||
it('should provide src and alt prop', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<Image src="image.jpg" alt="this is alt" /> | ||
); | ||
let image = React.findDOMNode(instance); | ||
|
||
assert.equal(image.getAttribute('src'), 'image.jpg'); | ||
assert.equal(image.getAttribute('alt'), 'this is alt'); | ||
}); | ||
|
||
it('should have correct class when responsive prop is set', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<Image responsive /> | ||
); | ||
let imageClassName = React.findDOMNode(instance).className; | ||
|
||
imageClassName.should.match(/\bimg-responsive\b/); | ||
}); | ||
|
||
it('should have correct class when rounded prop is set', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<Image rounded /> | ||
); | ||
let imageClassName = React.findDOMNode(instance).className; | ||
|
||
imageClassName.should.match(/\bimg-rounded\b/); | ||
}); | ||
|
||
it('should have correct class when circle prop is set', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<Image circle /> | ||
); | ||
let imageClassName = React.findDOMNode(instance).className; | ||
|
||
imageClassName.should.match(/\bimg-circle\b/); | ||
}); | ||
|
||
it('should have correct class when thumbnail prop is set', function() { | ||
let instance = ReactTestUtils.renderIntoDocument( | ||
<Image thumbnail /> | ||
); | ||
let imageClassName = React.findDOMNode(instance).className; | ||
|
||
imageClassName.should.match(/\bimg-thumbnail\b/); | ||
}); | ||
}); |