Skip to content
This repository was archived by the owner on Aug 19, 2022. It is now read-only.

Commit 40f3d8c

Browse files
committed
Update readme
1 parent 2dc86a8 commit 40f3d8c

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

README.md

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55

66
[`react-progressive-image`](https://www.npmjs.com/package/react-progressive-image) React component for progressive image loading
77

8-
## Installation
9-
10-
Using [npm](https://www.npmjs.com/):
11-
12-
$ npm install --save react-progressive-image
8+
### Install
139

10+
```bash
11+
$ yarn add react-progressive-image
12+
```
1413

1514
The UMD build is also available on [unpkg](https://unpkg.com):
1615

@@ -20,50 +19,67 @@ The UMD build is also available on [unpkg](https://unpkg.com):
2019

2120
If you use the UMD build you can find the library on `window.ReactProgressiveImage`.
2221

23-
## Usage
22+
### Examples
2423

25-
`react-progressive-image` exports a single React component, `ProgressiveImage`, which takes a `src` and `placeholder` prop, as well as optional props `srcSetData`, and `onError` function.
24+
#### Simple
2625

27-
`src` should be the final image you want to load, and `placeholder` is the image you want to display until `src` is loaded. `placeholder` can be anything you want. A typical use case might involve using a smaller version of the image, an inlined version (data URI), or a loading graphic.
28-
29-
If you would like to supply a srcSet for the image, you can use the `srcSetData` prop. The prop should be and object containing two properties, `srcSet`, and `sizes`.
26+
```jsx
27+
<ProgressiveImage src="large-image.jpg" placeholder="tiny-image.jpg">
28+
{src => <img src={src} alt="an image" />}
29+
</ProgressiveImage>
30+
```
3031

31-
`ProgressiveImage` accepts a render callback as a child, which will be called with the `placeholder` first, and then `src` once the image has been loaded.
32+
#### With Delay
3233

3334
```jsx
34-
<ProgressiveImage src='large-image.jpg' placeholder='tiny-image.jpg'>
35-
{(src) => <img src={src} alt='an image'/>}
35+
<ProgressiveImage
36+
delay={3000}
37+
src="large-image.jpg"
38+
placeholder="tiny-image.jpg"
39+
>
40+
{src => <img src={src} alt="an image" />}
3641
</ProgressiveImage>
3742
```
3843

39-
It will also call the render callback with a second argument, `loading`, which you can use to quickly determine what image is being rendered. `loading` will be `true` when the placeholder is rendered, and `false` when the full image is rendered.
44+
#### With loading argment
4045

4146
```jsx
42-
<ProgressiveImage src='large-image.jpg' placeholder='tiny-image.jpg'>
47+
<ProgressiveImage src="large-image.jpg" placeholder="tiny-image.jpg">
4348
{(src, loading) => (
44-
<img style={{ opacity: loading ? 0.5 : 1 }} src={src} alt='an image'/>
49+
<img style={{ opacity: loading ? 0.5 : 1 }} src={src} alt="an image" />
4550
)}
4651
</ProgressiveImage>
4752
```
4853

49-
If the `srcSetData` prop is supplied, it will be returned as the third argument to the render callback. This is helpful if you are sharing a render function between multiple different `ProgressiveImage` components.
54+
#### With srcSet
5055

5156
```jsx
52-
<ProgressiveImage
53-
src='medium.jpg'
57+
<ProgressiveImage
58+
src="medium.jpg"
5459
srcSetData={{
5560
srcSet: 'small.jpg 320w, medium.jpg 700w, large.jpg 2000w',
56-
sizes: "(max-width: 2000px) 100vw, 2000px"
61+
sizes: '(max-width: 2000px) 100vw, 2000px'
5762
}}
58-
placeholder='tiny-image.jpg'
63+
placeholder="tiny-image.jpg"
5964
>
6065
{(src, _loading, srcSetData) => (
61-
<img
62-
src={src}
63-
srcSet={srcSetData.srcSet}
64-
sizes={srcSetData.sizes}
65-
alt='an image'
66+
<img
67+
src={src}
68+
srcSet={srcSetData.srcSet}
69+
sizes={srcSetData.sizes}
70+
alt="an image"
6671
/>
6772
)}
6873
</ProgressiveImage>
69-
```
74+
```
75+
76+
### Props
77+
78+
| Name | Type | Required | Description |
79+
| ----------- | -------------------------------------- | -------- | ----------------------------------------------- |
80+
| children | `function` | `true` | returns `src`, `loading`, and `srcSetData` |
81+
| delay | `number` | `false` | time in milliseconds before src image is loaded |
82+
| onError | `function` | `false` | returns error event |
83+
| placeholder | `string` | `true` | the src of the placeholder image |
84+
| src | `string` | `true` | the src of the main image |
85+
| srcSetData | `{srcSet: "string", sizes: "string" }` | `false` | srcset and sizes to be applied to the image |

0 commit comments

Comments
 (0)