Skip to content

Commit

Permalink
Merge pull request #1 from vivid-planet/allow-srcSet
Browse files Browse the repository at this point in the history
Allow src set
  • Loading branch information
kaufmo authored Sep 5, 2018
2 parents b058f64 + ab11875 commit 05e33f0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from "react";

export interface ImageProps {
src: string;
srcSet?: string;
width: number;
height: number;
className?: string;
Expand Down
18 changes: 17 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@vivid-planet/react-image",
"version": "1.2.0",
"version": "1.3.0",
"description": "Image component with loading animation for react",
"main": "./lib/index.js",
"typings": "./index.d.ts",
"scripts": {
"scss": "node-sass --output-style expanded --recursive scss/default.scss dist/react-image.css",
"build": "babel src --presets=es2015,react --out-dir lib",
"build": "babel src --presets=es2015,react --plugins transform-object-rest-spread --out-dir lib",
"clean": "rm -rf lib && rm -rf dist",
"prepublish": "npm run clean && npm run build && npm run scss"
},
Expand All @@ -20,6 +20,7 @@
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"node-sass": "^4.9.2"
Expand Down
7 changes: 4 additions & 3 deletions src/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Image extends Component {

render() {
const { loading } = this.state;
const { className, src, width, height, alt, title, onClick } = this.props;
const { className, ...imgProps } = this.props;

const classNames = ['kwfUp-reactImage'];
if (loading) classNames.push('kwfUp-reactImage--loading');
Expand All @@ -37,11 +37,11 @@ class Image extends Component {
<div
className={classNames.join(' ')}
style={{
paddingBottom: `${100 * (height / width)}%`
paddingBottom: `${100 * (imgProps.height / imgProps.width)}%`
}}
>
<img
{...{src, width, height, alt, title, onClick}}
{...imgProps}
onLoad={this._handleImageLoaded}
/>
</div>
Expand All @@ -51,6 +51,7 @@ class Image extends Component {

Image.propTypes = {
src: PropTypes.string.isRequired,
srcSet: PropTypes.string,
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
className: PropTypes.string,
Expand Down

0 comments on commit 05e33f0

Please sign in to comment.