Image component for React.
- Declarative
- Functional component
- Responsive
- Lazy-loaded media
- Module syntax
- ES6
- React
npm i enteocode/react-revelations
import React from 'react';
import Image, { RATIO_WIDE } from 'react-revelations';
const MyComponent = () => (
<article>
<h2>Lorem ipsum</h2>
<Image
source="//lorempixel.com/g/640/360/"
width={640}
ratio={RATIO_WIDE}
caption="Random image"
/>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</article>
);
- source : {string} - The URL of the image
Two of these properties must be set properly to calculate aspect ratio for the placeholder. This is a must to prevent repaints on DOM.
- width : (number) - Image size in pixels
- height : (number) - Image size of pixels
- ratio : (number[]) - Two elements Array with the width/height ratio
Optional properties:
- caption (string) - The title of the Image (this will be read by screen-readers)
- containerClass (string) - Stylesheet class to append
- errorColor (string) - Color of the error icon (if can't load the resource)
- loaderColor (string) - Color of the loader spinner
You can see the component in action at the GitHub Page of the repository.
The MIT License (MIT). Please see the License File for more information.