-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[added] Images Component with Sample and Docs #1293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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; | ||
|
5269
tr>
||
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/); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought our prop tables were generated off prop types, not default props.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @taion for the review. Does it mean the getDefaultProps() method is not needed here?