Skip to content

Commit 5bcc6c3

Browse files
committed
Add new prop: 'wrapperClassName'
1 parent 87c4a28 commit 5bcc6c3

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export default MyImage;
6363
| placeholderSrc | `String` | | Image src to display while the image is not visible or loaded. |
6464
| threshold | `Number` | 100 | Threshold in pixels. So the image starts loading before it appears in the viewport. |
6565
| visibleByDefault | `Boolean` | false | Whether the image must be visible from the beginning. |
66+
| wrapperClassName | `string` | | In some occasions (for example, when using a placeholderSrc) a wrapper span tag is rendered. This prop allows setting a class to that element. |
6667
| ... | | | Any other image attribute |
6768

6869

src/components/LazyLoadImage.jsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LazyLoadImage extends React.Component {
2929
getImg() {
3030
const { afterLoad, beforeLoad, delayMethod, delayTime, effect,
3131
placeholder, placeholderSrc, scrollPosition, threshold,
32-
visibleByDefault, ...imgProps } = this.props;
32+
visibleByDefault, wrapperClassName, ...imgProps } = this.props;
3333

3434
return <img onLoad={this.onImageLoad()} {...imgProps} />;
3535
}
@@ -58,7 +58,8 @@ class LazyLoadImage extends React.Component {
5858
}
5959

6060
getWrappedLazyLoadImage(lazyLoadImage) {
61-
const { effect, height, placeholderSrc, width } = this.props;
61+
const { effect, height, placeholderSrc,
62+
width, wrapperClassName } = this.props;
6263
const { loaded } = this.state;
6364

6465
const loadedClassName = loaded ?
@@ -67,7 +68,8 @@ class LazyLoadImage extends React.Component {
6768

6869
return (
6970
<span
70-
className={'lazy-load-image-background ' + effect + loadedClassName}
71+
className={wrapperClassName + ' lazy-load-image-background ' +
72+
effect + loadedClassName}
7173
style={{
7274
backgroundImage: 'url( ' + placeholderSrc + ')',
7375
backgroundSize: '100% 100%',

0 commit comments

Comments
 (0)