Skip to content

Commit

Permalink
Added support for Image caption.
Browse files Browse the repository at this point in the history
Adding feedbacks
  • Loading branch information
alansouzati committed Mar 17, 2016
1 parent fa77076 commit 5f115f7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/js/components/Image.js
Expand Up @@ -3,27 +3,45 @@
import React, { Component, PropTypes } from 'react';
import classnames from 'classnames';

import Label from './Label';

const CLASS_ROOT = 'image';

export default class Image extends Component {
render () {
let { size, full } = this.props;
let { caption, className, full, id, size, src } = this.props;
let classes = classnames(
CLASS_ROOT,
this.props.className,
{
[`${CLASS_ROOT}--${size}`]: size,
[`${CLASS_ROOT}--full`]: typeof full === 'boolean' && full,
[`${CLASS_ROOT}--full-${full}`]: typeof full === 'string'
}
},
className
);

return <img id={this.props.id} className={classes} src={this.props.src} />;
return caption ? (
<figure className={classes}>
<img id={id} src={src} className={`${CLASS_ROOT}__image`} />
<figcaption className={`${CLASS_ROOT}__caption`}>
<Label>{caption}</Label>
</figcaption>
</figure>
) : (
<img id={id} src={src} className={classes} />
);
}
};

Image.propTypes = {
caption: PropTypes.string,
className: PropTypes.string,
full: PropTypes.oneOf([true, 'horizontal', 'vertical', false]),
src: PropTypes.string,
size: PropTypes.oneOf(['small', 'medium', 'large', 'thumb'])
id: PropTypes.string,
size: PropTypes.oneOf(['small', 'medium', 'large', 'thumb']),
src: PropTypes.string
};

Image.defaultProps = {
size: 'medium'
};
11 changes: 11 additions & 0 deletions src/scss/grommet-core/_objects.image.scss
Expand Up @@ -2,6 +2,8 @@

.image {

max-width: 100%;

&--medium {
width: $image-width;
}
Expand Down Expand Up @@ -33,4 +35,13 @@
&--full-vertical {
height: 100%;
}

&__image {
width: 100%;
}

&__caption {
text-align: center;
padding: halve($inuit-base-spacing-unit);
}
}

0 comments on commit 5f115f7

Please sign in to comment.