-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-images): add image components
- images can be responsive or wrapped in a link [#84877438] Signed-off-by: Nicole Sullivan <nsullivan@pivotal.io>
- Loading branch information
Showing
4 changed files
with
103 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
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 @@ | ||
'use strict'; | ||
|
||
var React = require('react/addons'); | ||
var _ = require('lodash'); | ||
|
||
var setClass = React.addons.classSet; | ||
|
||
var Image = React.createClass({ | ||
|
||
|
||
render: function () { | ||
var classes = setClass({ | ||
'img-responsive': this.props.responsive | ||
}); | ||
|
||
if (this.props.href){ | ||
return( | ||
<a href={this.props.href}> | ||
<img {...this.props} className={classes}> | ||
{this.props.children} | ||
</img> | ||
</a> | ||
); | ||
} | ||
else { | ||
return ( | ||
<img {...this.props} className={classes}> | ||
{this.props.children} | ||
</img> | ||
); | ||
} | ||
} | ||
}); | ||
|
||
module.exports = { | ||
Image: 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
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,39 @@ | ||
'use strict'; | ||
|
||
var $ = require('jquery'); | ||
var React = require('react/addons'); | ||
var TestUtils = React.addons.TestUtils; | ||
|
||
var Image = require('../../../src/pivotal-ui/javascripts/images.jsx').Image; | ||
|
||
describe('Image', function() { | ||
beforeEach(function() { | ||
this.node = $('<div id="container"></div>').appendTo('body').get(0); | ||
|
||
React.render( | ||
<Image src="http://placehold.it/20x20" href="http://google.com" responsive="true" />, | ||
this.node | ||
); | ||
}); | ||
|
||
afterEach(function() { | ||
React.unmountComponentAtNode(this.node); | ||
document.body.removeChild(this.node); | ||
}); | ||
|
||
describe('when the href is set', function() { | ||
it("wraps the image in an link", function() { | ||
expect($('#container a')).toContainElement('img'); | ||
}); | ||
}); | ||
|
||
describe('when image responsive is set to true', function() { | ||
it("adds the image-responsive class to the image", function() { | ||
expect($('#container img')).toHaveClass('img-responsive'); | ||
}); | ||
}); | ||
|
||
it("adds the gutter class to the row", function() { | ||
expect($('#container img').attr('src')).toEqual('http://placehold.it/20x20'); | ||
}); | ||
}); |