Skip to content

Commit

Permalink
fix(react-image): add prop validations
Browse files Browse the repository at this point in the history
[#86938454]
  • Loading branch information
gpleiss authored and Geoff Pleiss committed Jan 30, 2015
1 parent bcca161 commit d1ef2a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/pivotal-ui/components/images.scss
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ categories:
Images in react can be responsive and/or wrapped in a link.
```react_example
<UI.Image src="http://placehold.it/1000x100" responsive="true" href="http://google.com" />
<UI.Image src="http://placehold.it/1000x100" responsive={true} href="http://google.com" />
```
Expand Down
36 changes: 16 additions & 20 deletions src/pivotal-ui/javascripts/images.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,26 @@ var React = require('react/addons');
var setClass = React.addons.classSet;

var UIImage = React.createClass({
propTypes: {
responsive: React.PropTypes.bool,
href: React.PropTypes.string,
src: React.PropTypes.string.isRequired
},

render: function () {
var {responsive, href, src, children, ...other} = this.props;

var classes = setClass({
'img-responsive': this.props.responsive
'img-responsive': responsive
});

var href = this.props.href;
delete this.props.href;

if (href){
return(
<a href={href}>
<img {...this.props} className={classes}>
{this.props.children}
</img>
</a>
);
}
else {
return (
<img {...this.props} className={classes}>
{this.props.children}
</img>
);
}
var image = (
<img {...other} src={src} className={classes}>
{children}
</img>
);

return (href) ? <a href={href}>{image}</a> : image;
}
});

Expand Down
2 changes: 1 addition & 1 deletion test/javascripts/image_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Image', 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" />,
<Image src="http://placehold.it/20x20" href="http://google.com" responsive={true} />,
this.node
);
});
Expand Down

0 comments on commit d1ef2a0

Please sign in to comment.