Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from vadymshymko/develop
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
vadymshymko authored Oct 12, 2019
2 parents 39a85c6 + 1657d50 commit ac7ab6c
Show file tree
Hide file tree
Showing 30 changed files with 2,624 additions and 17,287 deletions.
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
>0.25%, not ie 11
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
dist/*
example/*
11 changes: 7 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"plugins": [
"react",
"jsx-a11y",
"import",
"jest"
"import"
],
"rules": {
"import/no-extraneous-dependencies": [
Expand All @@ -21,6 +20,10 @@
]
},
"settings": {
"import/resolver": "webpack"
"import/resolver": {
"webpack": {
"config": "webpack.config.js"
}
}
}
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ typings/

# next.js build output
.next

dist/
example/
66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,66 @@
# react-lazilyload-img
React.js component for lazy load your images

[![npm version](https://img.shields.io/npm/v/react-lazilyload-img.svg?style=flat)](https://www.npmjs.com/package/react-lazilyload-img)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-lazilyload-img?label=size)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/vadymshymko/react-lazilyload-img/blob/master/LICENSE)

Simple && small React.js component for lazy load images

## Table of contents
- [Installation](#installation)
- [Usage](#usage)
- [Props](#props)
- [Demo](#demo)

## Installation

**npm**

```bash
npm install react-lazilyload-img --save
```

**yarn**

```bash
yarn add react-lazilyload-img
```

## Usage

#### Basic Example:

```js
import React, { Component } from 'react';
import Img from 'react-lazilyload-img';

const App = () => {
return(
<Img
src="//images.unsplash.com/photo-1539250632877-c12b7d5d6fcb"
placeholderSrc="//images.unsplash.com/photo-1539250632877-c12b7d5d6fcb?w=27&q=8"
>
);
};
```

## Props

Name | Type | Default Value | Description
---- | ---- | ------------- | --------------
className | string | `''` | image className
loadingClassName | string | `''` | className for main image in loading state (applied when main image start loading and delete after loading end)
mainImgClassName | string | `''` | className for main image (applied when main image start loading)
mainImgOnLoad | func | `null` | function that will be called after main image load end
onLoad | func | `null` | function that will be called after placeholder image or main image load end
placeholderClassName | string | `''` | placeholder image className (deleted before main image start loading)
placeholderOnLoad | func | `null` | function that will be called after placeholder image load end
placeholderSrc | string | `''` | placeholder image src attr value
placeholderSrcSet | string | `''` | placeholder image srcset attr value
src | string | `''` | main image src attr value
srcSet | string | `''` | main image srcset attr value
... | | | any other image attributes

## Demo

[![](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/react-lazilyload-img-69wd6)
41 changes: 20 additions & 21 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@ module.exports = {
'@babel/preset-env',
],
plugins: [
// Stage 0
'@babel/plugin-proposal-function-bind',

// Stage 1
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-logical-assignment-operators',
['@babel/plugin-proposal-optional-chaining', { loose: false }],
['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],
['@babel/plugin-proposal-nullish-coalescing-operator', { loose: false }],
'@babel/plugin-proposal-do-expressions',
['@babel/plugin-proposal-class-properties', { loose: true }],

// Stage 2
['@babel/plugin-proposal-decorators', { legacy: true }],
'@babel/plugin-proposal-function-sent',
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-numeric-separator',
'@babel/plugin-proposal-throw-expressions',
'transform-inline-consecutive-adds',
'minify-constant-folding',
'minify-dead-code-elimination',
'minify-guarded-expressions',
'minify-numeric-literals',
'minify-type-constructors',

// Stage 3
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-import-meta',
['@babel/plugin-proposal-class-properties', { loose: false }],
'@babel/plugin-proposal-json-strings',
[
'transform-react-remove-prop-types',
{
removeImport: true,
classNameMatchers: ['Component', 'PureComponent'],
additionalLibraries: ['prop-types'],
},
],

'@babel/plugin-transform-runtime',
['@babel/plugin-transform-react-constant-elements'],
['@babel/plugin-transform-react-inline-elements'],
['transform-remove-console', { exclude: ['error', 'warn'] }],
['babel-plugin-loop-optimizer'],
],
};
2 changes: 1 addition & 1 deletion dist/index.js

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

21 changes: 0 additions & 21 deletions example/.gitignore

This file was deleted.

Loading

0 comments on commit ac7ab6c

Please sign in to comment.