8000 [added] Images Component with Sample and Docs by deerawan · Pull Request #1293 · react-bootstrap/react-bootstrap · GitHub
[go: up one dir, main page]

Skip to content

[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 1 commit into from
Sep 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/examples/ImageResponsive.js
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);
17 changes: 17 additions & 0 deletions docs/examples/ImageShape.js
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);
17 changes: 17 additions & 0 deletions docs/src/ComponentsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,22 @@ const ComponentsPage = React.createClass({
<h4><Anchor id="utilities-fade-props">Props</Anchor></h4>
<PropTable component="Fade"/>
</div>

{/* Images */}
<div className="bs-docs-section">
<h1 className="page-header"><Anchor id="images">Images</Anchor></h1>

<h3><Anchor id="image-shape">Shape</Anchor></h3>
<p>Use the <code>rounded</code>, <code>circle</code> and <code>thumbnail</code> props to customise the image.</p>
<ReactPlayground codeText={Samples.ImageShape} />

<h3><Anchor id="image-responsive">Responsive</Anchor></h3>
<p>Use the <code>responsive</code> to scale image nicely to the parent element.</p>
<ReactPlayground codeText={Samples.ImageResponsive} />

<h3><Anchor id="image-props">Props</Anchor></h3>
<PropTable component="Image"/>
</div>
</div>


Expand Down Expand Up @@ -948,6 +964,7 @@ const ComponentsPage = React.createClass({
<NavItem href="#tables" key={25}>Tables</NavItem>
<NavItem href="#input" key={26}>Input</NavItem>
<NavItem href="#utilities" key={28}>Utilities</NavItem>
<NavItem href="#images" key={29}>Images</NavItem>
</Nav>
<a className="back-to-top" href="#top">
Back to top
Expand Down
1 change: 1 addition & 0 deletions docs/src/ReactPlayground.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const FormControls = require('../../src/FormControls');
const Glyphicon = require('../../src/Glyphicon');
const Grid = require('../../src/Grid');
const Input = require('../../src/Input');
const Image = require('../../src/Image');
const Jumbotron = require('../../src/Jumbotron');
const Label = require('../../src/Label');
const ListGroup = require('../../src/ListGroup');
Expand Down
2 changes: 2 additions & 0 deletions docs/src/Samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export default {
InputHorizontal: require('fs').readFileSync(__dirname + '/../examples/InputHorizontal.js', 'utf8'),
InputWrapper: require('fs').readFileSync(__dirname + '/../examples/InputWrapper.js', 'utf8'),
MenuItem: require('fs').readFileSync(__dirname + '/../examples/MenuItem.js', 'utf8'),
ImageResponsive: require('fs').readFileSync(__dirname + '/../examples/ImageResponsive.js', 'utf8'),
ImageShape: require('fs').readFileSync(__dirname + '/../examples/ImageShape.js', 'utf8'),

Overlay: require('fs').readFileSync(__dirname + '/../examples/Overlay.js', 'utf8'),
OverlayCustom: require('fs').readFileSync(__dirname + '/../examples/OverlayCustom.js', 'utf8')
Expand Down
52 changes: 52 additions & 0 deletions src/Image.js
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() {
Copy link
Member

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.

Copy link
Contributor Author

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?

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;
61 changes: 61 additions & 0 deletions test/ImageSpec.js
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/);
});
});
0