Skip to content

Commit 0a90831

Browse files
Pedro DuarteKyleAMathews
authored andcommitted
Fix gatsby-plugin-nprogress default options param (#3533)
* Fix default `pluginOptions` parameter This PR fixes #3484 Correctly merge `defaultOptions` with `pluginOptions` * Indent `styles` template string correctly * Change default
1 parent bdb5a00 commit 0a90831

File tree

1 file changed

+68
-62
lines changed

1 file changed

+68
-62
lines changed

packages/gatsby-plugin-nprogress/src/gatsby-browser.js

Lines changed: 68 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,87 @@
11
import NProgress from "nprogress"
22

3-
exports.onClientEntry = (a, pluginOptions = { color: `#29d` }) => {
3+
const defaultOptions = { color: `#29d` }
4+
5+
exports.onClientEntry = (a, pluginOptions = {}) => {
6+
// Merge default options with user defined options in `gatsby-config.js`
7+
const options = { ...defaultOptions, ...pluginOptions }
8+
49
window.___emitter.on(`onDelayedLoadPageResources`, () => {
5-
NProgress.configure(pluginOptions)
10+
NProgress.configure(options)
611
NProgress.start()
712
})
813
window.___emitter.on(`onPostLoadPageResources`, () => {
914
NProgress.done()
1015
})
1116

1217
// Inject styles.
13-
const styles = `#nprogress {
14-
pointer-events: none;
15-
}
16-
#nprogress .bar {
17-
background: ${pluginOptions.color};
18-
position: fixed;
19-
z-index: 1031;
20-
top: 0;
21-
left: 0;
22-
width: 100%;
23-
height: 2px;
24-
}
25-
#nprogress .peg {
26-
display: block;
27-
position: absolute;
28-
right: 0px;
29-
width: 100px;
30-
height: 100%;
31-
box-shadow: 0 0 10px ${pluginOptions.color}, 0 0 5px ${pluginOptions.color};
32-
opacity: 1.0;
33-
-webkit-transform: rotate(3deg) translate(0px, -4px);
34-
-ms-transform: rotate(3deg) translate(0px, -4px);
35-
transform: rotate(3deg) translate(0px, -4px);
36-
}
37-
#nprogress .spinner {
38-
display: block;
39-
position: fixed;
40-
z-index: 1031;
41-
top: 15px;
42-
right: 15px;
43-
}
44-
#nprogress .spinner-icon {
45-
width: 18px;
46-
height: 18px;
47-
box-sizing: border-box;
48-
border: solid 2px transparent;
49-
border-top-color: ${pluginOptions.color};
50-
border-left-color: ${pluginOptions.color};
51-
border-radius: 50%;
52-
-webkit-animation: nprogress-spinner 400ms linear infinite;
53-
animation: nprogress-spinner 400ms linear infinite;
54-
}
55-
.nprogress-custom-parent {
56-
overflow: hidden;
57-
position: relative;
58-
}
59-
.nprogress-custom-parent #nprogress .spinner,
60-
.nprogress-custom-parent #nprogress .bar {
61-
position: absolute;
62-
}
63-
@-webkit-keyframes nprogress-spinner {
64-
0% {
65-
-webkit-transform: rotate(0deg);
18+
const styles = `
19+
#nprogress {
20+
pointer-events: none;
6621
}
67-
100% {
22+
#nprogress .bar {
23+
background: ${options.color};
24+
position: fixed;
25+
z-index: 1031;
26+
top: 0;
27+
left: 0;
28+
width: 100%;
29+
height: 2px;
30+
}
31+
#nprogress .peg {
32+
display: block;
33+
position: absolute;
34+
right: 0px;
35+
width: 100px;
36+
height: 100%;
37+
box-shadow: 0 0 10px ${options.color}, 0 0 5px ${options.color};
38+
opacity: 1.0;
39+
-webkit-transform: rotate(3deg) translate(0px, -4px);
40+
-ms-transform: rotate(3deg) translate(0px, -4px);
41+
transform: rotate(3deg) translate(0px, -4px);
42+
}
43+
#nprogress .spinner {
44+
display: block;
45+
position: fixed;
46+
z-index: 1031;
47+
top: 15px;
48+
right: 15px;
49+
}
50+
#nprogress .spinner-icon {
51+
width: 18px;
52+
height: 18px;
53+
box-sizing: border-box;
54+
border: solid 2px transparent;
55+
border-top-color: ${options.color};
56+
border-left-color: ${options.color};
57+
border-radius: 50%;
58+
-webkit-animation: nprogress-spinner 400ms linear infinite;
59+
animation: nprogress-spinner 400ms linear infinite;
60+
}
61+
.nprogress-custom-parent {
62+
overflow: hidden;
63+
position: relative;
64+
}
65+
.nprogress-custom-parent #nprogress .spinner,
66+
.nprogress-custom-parent #nprogress .bar {
67+
position: absolute;
68+
}
69+
@-webkit-keyframes nprogress-spinner {
70+
0% {
71+
-webkit-transform: rotate(0deg);
72+
}
73+
100% {
6874
-webkit-transform: rotate(360deg);
75+
}
6976
}
70-
}
71-
@keyframes nprogress-spinner {
72-
0% {
77+
@keyframes nprogress-spinner {
78+
0% {
7379
transform: rotate(0deg);
74-
}
75-
100% {
80+
}
81+
100% {
7682
transform: rotate(360deg);
83+
}
7784
}
78-
}
7985
`
8086

8187
const node = document.createElement(`style`)

0 commit comments

Comments
 (0)