5.0.0 • Published 7 years ago
react-responsive-image v5.0.0
react-responsive-image
A React responsive image component.
Displays different image sizes based on the user's window width. Can support an unlimited number of image sizes.
To install
npm i react-responsive-imageTo run demo
npm installthen
npm startThen navigate to http://localhost:3000/demo.html
To run tests
npm testTo build
npm run buildUsage
import React from 'react';
import ReactDOM from 'react-dom';
import { ResponsiveImage, ResponsiveImageSize } from 'react-responsive-image';
<ResponsiveImage>
<ResponsiveImageSize
default
minWidth={0}
path={'path-to-small-image.jpg'}
/>
<ResponsiveImageSize
minWidth={768}
path={'path-to-medium-image.jpg'}
/>
<ResponsiveImageSize
minWidth={1100}
path={'path-to-large-image.jpg'}
/>
</ResponsiveImage>props for ResponsiveImage component
alt {String} // The value for the image alt attributebackground {Boolean} // If set to true, the component will render a background imageclassName {String} // An additional className to add to the componentlazy {Boolean} // If the component should lazy-load the imageloadImage {Boolean} // Set to `true` to load an image, if the `lazy` prop is set to `true`onLoad {Function} // A callback to fire when the image is loadedstyle {Object} // A style object to add to the componentprops for ResponsiveImageSize component
default {Boolean} // If this is the default size to be loaded, before the window width is available. Mainly used for rendering from the server.minWidth {Number} // The minimum width the window should be to load this imagepath {Object} // The image path