Skip to content
Open
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
22 changes: 8 additions & 14 deletions lib/ImageWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ type ImageWorkerProps = {
src: string,
placeholder?: string | Function,
style?: Object,
imageClass?: string,
containerClass?: string,
placeholderAlt?: string
}

type ImageWorkerState = {
Expand Down Expand Up @@ -64,12 +63,12 @@ class ImageWorker extends Component<ImageWorkerProps, ImageWorkerState> {
}

renderPlaceholder() {
const { placeholder, style } = this.props;
const { placeholder, style, placeholderAlt } = this.props;
if (typeof placeholder === 'function') {
const PlaceholderComponent = wrappedComponent(placeholder);
return <PlaceholderComponent />;
} else if (typeof placeholder === 'string') {
return <img src={placeholder} style={{ ...style }} alt='placeholder' />;
return <img src={placeholder} style={{ ...style }} alt={placeholderAlt} />;
} else {
return null;
}
Expand All @@ -90,16 +89,11 @@ class ImageWorker extends Component<ImageWorkerProps, ImageWorkerState> {
}

render() {
const { style, imageClass, containerClass } = this.props;
return (
<div className={containerClass}>
{
this.state.isLoading ? this.renderPlaceholder() :
<img src={this.state.imgSrc}
style={{ ...style }} className={imageClass} alt='worker' />
}
</div>
);
const { style, src, placeholderAlt, placeholder, ...props } = this.props; // eslint-disable-line no-unused-vars
const { isLoading, imgSrc } = this.state;
return isLoading ? this.renderPlaceholder() :
<img src={imgSrc}
style={{ ...style }} {...props} />;
}
}

Expand Down