Skip to content

Commit 3e49687

Browse files
committed
Initial commit
0 parents  commit 3e49687

File tree

6 files changed

+124
-0
lines changed

6 files changed

+124
-0
lines changed

.eslintrc.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es6: true,
5+
},
6+
extends: ['eslint:recommended'],
7+
parserOptions: {
8+
ecmaVersion: 2018,
9+
sourceType: 'module',
10+
},
11+
rules: {
12+
indent: ['error', 2],
13+
quotes: ['warn', 'single'],
14+
semi: ['warn', 'never'],
15+
'comma-dangle': ['warn', 'always-multiline'],
16+
},
17+
}

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
node_modules
3+
package-lock.json
4+
yarn.lock

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Jonathan Reinink <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@inertiajs/progress",
3+
"version": "0.0.1",
4+
"license": "MIT",
5+
"description": "This package adds an NProgress page loading indicator to your Inertia.js app.",
6+
"contributors": [
7+
"Jonathan Reinink <[email protected]>"
8+
],
9+
"source": "src/index.js",
10+
"main": "dist/index.js",
11+
"unpkg": "dist/index.umd.js",
12+
"scripts": {
13+
"build": "npm run build:cjs && npm run build:umd",
14+
"build:cjs": "microbundle --format cjs",
15+
"build:umd": "microbundle --format umd --name Inertia --external none",
16+
"prepublishOnly": "npm run build",
17+
"watch": "microbundle watch --format cjs"
18+
},
19+
"devDependencies": {
20+
"eslint": "^6.1.0",
21+
"microbundle": "^0.12.0"
22+
},
23+
"dependencies": {
24+
"nprogress": "^0.2.0"
25+
}
26+
}

readme.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Inertia.js Progress
2+
3+
This package adds an NProgress page loading indicator to your Inertia.js app.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @inertiajs/progress
9+
yarn add @inertiajs/progress
10+
```
11+
12+
Once it's been installed, initialize it in your app:
13+
14+
```js
15+
import Progress from '@inertiajs/progress'
16+
17+
Progress.init({
18+
delay: 250,
19+
showSpinner: false,
20+
})
21+
```

src/index.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Nprogress from 'nprogress'
2+
3+
export default {
4+
delay: null,
5+
timeout: null,
6+
7+
init({ delay = 250, showSpinner = false } = {}) {
8+
this.delay = delay
9+
10+
Nprogress.configure({ showSpinner: showSpinner })
11+
12+
document.addEventListener('inertia:start', this.start.bind(this))
13+
document.addEventListener('inertia:progress', this.progress.bind(this))
14+
document.addEventListener('inertia:finish', this.finish.bind(this))
15+
},
16+
17+
start() {
18+
clearTimeout(this.timeout)
19+
this.timeout = setTimeout(() => {
20+
Nprogress.set(0)
21+
Nprogress.start()
22+
}, this.delay)
23+
},
24+
25+
progress(event) {
26+
if (event.detail.progress.completed) {
27+
Nprogress.set(event.detail.progress.completed / 100 * .9)
28+
}
29+
},
30+
31+
finish() {
32+
clearTimeout(this.timeout)
33+
Nprogress.done()
34+
},
35+
}

0 commit comments

Comments
 (0)