Demo
++ The source code to this demo can be found in the repo's + docs folder. + + Below, the component infinite scrolls React's Github issues. +
+diff --git a/.babelrc b/.babelrc
new file mode 100644
index 0000000..c7a0b0c
--- /dev/null
+++ b/.babelrc
@@ -0,0 +1,14 @@
+{
+ "presets": ["es2015", "react", "stage-2"],
+ "plugins": [
+ ["transform-object-rest-spread", { "useBuiltIns": true }],
+ ["add-module-exports"]
+ ],
+ "env": {
+ "test": {
+ "plugins": [
+ "istanbul"
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..c3b073c
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+# EditorConfig - http://EditorConfig.org
+
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+
+[**.html]
+indent_style = space
+indent_size = 4
+
+[**.js]
+indent_style = space
+indent_size = 2
diff --git a/.eslintrc.js b/.eslintrc.js
new file mode 100644
index 0000000..16f01ec
--- /dev/null
+++ b/.eslintrc.js
@@ -0,0 +1,29 @@
+const fs = require('fs');
+
+const prettierOptions = JSON.parse(fs.readFileSync('./.prettierrc', 'utf8'));
+
+module.exports = {
+ extends: ['last', 'prettier', 'prettier/react', 'plugin:react/recommended'],
+ plugins: ['react', 'prettier'],
+ env: {
+ browser: true,
+ },
+ globals: {
+ describe: true,
+ it: true,
+ module: true,
+ exports: true,
+ require: true
+ },
+ rules: {
+ 'prettier/prettier': ['error', prettierOptions],
+ 'no-unused-vars': [
+ 'off',
+ {
+ vars: 'all',
+ args: 'after-used',
+ ignoreRestSiblings: false
+ }
+ ]
+ }
+};
diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index e0094c4..0000000
--- a/.gitattributes
+++ /dev/null
@@ -1 +0,0 @@
-dist/** -diff merge=binary
diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md
new file mode 100644
index 0000000..fdba6d3
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/Bug_report.md
@@ -0,0 +1,22 @@
+---
+name: Bug report
+about: Submit a bug you found using the package
+
+---
+
+**Describe the bug**
+A clear and concise description of what the bug is.
+
+**To Reproduce**
+Please clone your layout and use of react-infinite-scroller by forking [this Code Sandbox](https://codesandbox.io/s/my6vo3yo78) and linking it here. Doing so will massively expedite getting the bug fixed! 👊
+
+**Expected behavior**
+A clear and concise description of what you expected to happen.
+
+**Screenshots**
+If applicable, add screenshots to help explain your problem.
+
+**Device (please complete the following information):**
+ - OS: [e.g. Mac]
+ - Browser [e.g. chrome, safari]
+ - Version [e.g. 22]
diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md
new file mode 100644
index 0000000..5384295
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/Feature_request.md
@@ -0,0 +1,17 @@
+---
+name: Feature request
+about: Suggest an idea for this project
+
+---
+
+**Is your feature request related to a problem? Please describe.**
+A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+
+**Describe the solution you'd like**
+A clear and concise description of what you want to happen.
+
+**Describe alternatives you've considered**
+A clear and concise description of any alternative solutions or features you've considered.
+
+**Additional context**
+Add any other context or screenshots about the feature request here.
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..60c6074
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,23 @@
+name: Test
+
+on:
+ pull_request:
+ branches: [master]
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - name: Cache node modules
+ id: cache
+ uses: actions/cache@v2
+ with:
+ path: node_modules
+ key: cache-node-modules-${{ hashFiles('package-lock.json') }}
+ - name: npm install
+ if: steps.cache.outputs.cache-hit != 'true'
+ run: npm ci
+ - run: npm run lint
+ - run: npm run test
+ - run: npm run build
diff --git a/.gitignore b/.gitignore
index 299aea9..19880bb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
-npm-debug.log
node_modules
+npm-debug.log
.DS_Store
+.idea
+.nyc_output
+coverage
diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..c75bb0e
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1,5 @@
+coverage
+test
+.nyc_output
+docs
+.eslintrc.js
diff --git a/.prettierrc b/.prettierrc
new file mode 100644
index 0000000..1b0cca8
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1,7 @@
+{
+ "printWidth": 80,
+ "tabWidth": 2,
+ "useTabs": false,
+ "semi": true,
+ "singleQuote": true
+}
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..e57b3bd
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,4 @@
+{
+ "prettier.eslintIntegration": true,
+ "editor.formatOnSave": true
+}
diff --git a/Gruntfile.js b/Gruntfile.js
deleted file mode 100644
index d3f827e..0000000
--- a/Gruntfile.js
+++ /dev/null
@@ -1,97 +0,0 @@
-module.exports = function (grunt) {
- grunt.initConfig({
- pkg: grunt.file.readJSON('package.json'),
- browserify: {
- dist: {
- files: {
- 'dist/react-infinite-scroll.js': ['src/umd.js']
- },
- }
- },
- uglify: {
- options: {
- banner: '/*! <%= pkg.name %> - v <%= pkg.version %> - <%= pkg.author %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
- },
- dist: {
- files: {
- 'dist/react-infinite-scroll.min.js': ['dist/react-infinite-scroll.js']
- }
- }
- },
- clean: ['dist/react-infinite-scroll.js'],
- mochaTest: {
- all: {
- options: {
- reporter: 'spec'
- },
- src: ['test/**/*.js', '!test/mock/**']
- }
- },
- jshint: {
- options: {
- indent: 2,
- camelcase: true,
- nonew: true,
- plusplus: true,
- quotmark: true,
- bitwise: true,
- forin: true,
- curly: true,
- eqeqeq: true,
- immed: true,
- latedef: true,
- newcap: true,
- noarg: true,
- undef: true,
- unused: true,
- regexp: true,
- trailing: true,
- node: true,
- browser: true
- },
- gruntfile: {
- files: {
- src: ['Gruntfile.js']
- }
- },
- dev: {
- files: {
- src: ['src/**/*.js']
- },
- options: {
- debug: true,
- devel: true
- }
- },
- dist: {
- files: {
- src: ['src/**/*.js']
- }
- },
- test: {
- files: {
- src: ['test/**/*.js']
- },
- options: {
- globals: {
- describe: true,
- it: true,
- before: true,
- after: true,
- beforeEach: true,
- afterEach: true
- }
- }
- }
- }
- });
-
- grunt.loadNpmTasks('grunt-contrib-jshint');
- grunt.loadNpmTasks('grunt-browserify');
- grunt.loadNpmTasks('grunt-contrib-uglify');
- grunt.loadNpmTasks('grunt-contrib-clean');
-
- grunt.registerTask('lint', ['jshint']);
- grunt.registerTask('dist', ['browserify', 'uglify', 'clean']);
- grunt.registerTask('default', ['jshint', 'dist']);
-};
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index cd2cd3d..2014a14 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,5 +1,6 @@
The MIT License (MIT)
+Copyright (c) 2016 Dan Bovey
Copyright (c) 2013 guillaumervls
Permission is hereby granted, free of charge, to any person obtaining a copy of
diff --git a/README.md b/README.md
index bb4dfdf..8fee7f3 100644
--- a/README.md
+++ b/README.md
@@ -1,103 +1,134 @@
-React Infinite Scroll
-=====================
+# React Infinite Scroller
-*React infinite scroll component*
+[](https://www.npmjs.com/package/react-infinite-scroller)
+[](https://www.npmjs.com/package/react-infinite-scroller)
+[](https://github.com/danbovey/react-infinite-scroller/blob/master/LICENSE)
-Demo: http://jsfiddle.net/mb9vJ/2
+Infinitely load a grid or list of items in React. This component allows you to create a simple, lightweight infinite scrolling page or element by supporting both window and scrollable elements.
-# Getting started
+- ⏬ Ability to use window or a scrollable element
+- 📏 No need to specify item heights
+- 💬 Support for "chat history" (reverse) mode
+- ✅ Fully unit tested and used in hundreds of production sites around the
+ world!
+- 📦 Lightweight alternative to other available React scroll libs ~ 2.2KB
+ minified & gzipped
-### Classic :
+---
-The "ready to use" [script file](https://raw.github.com/guillaumervls/react-infinite-scroll/master/dist/react-infinite-scroll.min.js)
-is in the `dist` folder.
+- [Demo](https://danbovey.uk/react-infinite-scroller/demo/)
+- [Demo Source](https://github.com/danbovey/react-infinite-scroller/blob/master/docs/src/index.js)
-Then :
-```html
-
-
-```
-
-### [Browserify](https://github.com/substack/node-browserify) :
-̀
-Install : `npm install react-infinite-scroll`
+## Installation
-Then :
-```javascript
-InfiniteScroll = require('react-infinite-scroll')(React);
+```
+npm install react-infinite-scroller --save
+```
+```
+yarn add react-infinite-scroller
```
-### Also works with AMD (e.g [RequireJS](http://requirejs.org))
-
-In this case, it will depend on `react`.
+## How to use
+```js
+import InfiniteScroll from 'react-infinite-scroller';
+```
-# Use in JSX
+### Window scroll events
-```html
+```js
+ The source code to this demo can be found in the repo's + docs folder. + + Below, the component infinite scrolls React's Github issues. +
+Infinitely load content using a React Component. This fork maintains a simple, lightweight infinite scroll
+ package that supports both window
and scrollable elements.
npm i react-infinite-scroller
+
+ import InfiniteScroll from 'react-infinite-scroller'
+
+ <InfiniteScroll
+ pageStart={0}
+ loadMore={loadFunc}
+ hasMore={true || false}
+ loader={<div className="loader">Loading ...</div>}>
+ {items} // <-- This is the content you want to load
+</InfiniteScroll>
+ <div style="height:700px;overflow:auto;">
+ <InfiniteScroll
+ pageStart={0}
+ loadMore={loadFunc}
+ hasMore={true || false}
+ loader={<div className="loader">Loading ...</div>}
+ useWindow={false}>
+ {items}
+ </InfiniteScroll>
+</div>
+ Name | +Type | +Default | +Description | +
---|---|---|---|
element |
+ String |
+ 'div' |
+ Name of the element that the component should render as. | +
hasMore |
+ Boolean |
+ false |
+ Whether there are more items to be loaded. Event listeners are removed if false .
+ |
+
initialLoad |
+ Boolean |
+ true |
+ Whether the component should load the first set of items. | +
loadMore |
+ Function |
+ + | A callback when more items are requested by the user. | +
pageStart |
+ Object |
+ 0 |
+ The number of the first page to load, With the default of 0 , the first page is
+ 1 .
+ |
+
threshold |
+ Number |
+ 250 |
+ The distance in pixels before the end of the items that will trigger a call to
+ loadMore .
+ |
+
useWindow |
+ Boolean |
+ true |
+ Add scroll listeners to the window, or else, the component's parentNode . |
+