Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specifying bar color and spinner color #238

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,25 @@ specify this to change the parent container. (default: `body`)
NProgress.configure({ parent: '#container' });
~~~

#### `barColor`
Specify this to change the bar color. (default: `#29d`)

~~~ js
NProgress.configure({ barColor: '#343A40' });
~~~

#### `spinnerColor`
Specify this to change the spinner color. (default: `#29d`)

~~~ js
NProgress.configure({ spinnerColor: '#343A40' });
~~~


Customization
-------------

Just edit `nprogress.css` to your liking. Tip: you probably only want to find
and replace occurrences of `#29d`.
Just edit `nprogress.css` to your liking.

The included CSS file is pretty minimal... in fact, feel free to scrap it and
make your own!
Expand Down
21 changes: 19 additions & 2 deletions nprogress.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
speed: 200,
trickle: true,
trickleSpeed: 200,
barColor: '#29d',
showSpinner: true,
barSelector: '[role="bar"]',
spinnerSelector: '[role="spinner"]',
spinnerColor: '#29d',
parent: 'body',
template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>'
};
Expand Down Expand Up @@ -237,16 +239,31 @@
parent = isDOM(Settings.parent)
? Settings.parent
: document.querySelector(Settings.parent),
spinner
spinner,
spinnerIconSelector

css(bar, {
transition: 'all 0 linear',
transform: 'translate3d(' + perc + '%,0,0)'
transform: 'translate3d(' + perc + '%,0,0)',
backgroundColor: Settings.barColor, // set bar color
});

// set fancy blur effect color
css(progress.querySelector('.peg'), {
boxShadow: `0 0 10px ${Settings.barColor}, 0 0 5px ${Settings.barColor}`
});

if (!Settings.showSpinner) {
spinner = progress.querySelector(Settings.spinnerSelector);
spinner && removeElement(spinner);
} else {
// set spinner color
spinner = progress.querySelector(Settings.spinnerSelector);
spinnerIconSelector = spinner.querySelector('.spinner-icon');
css(spinnerIconSelector, {
borderTopColor: Settings.spinnerColor,
borderLeftColor: Settings.spinnerColor
})
}

if (parent != document.body) {
Expand Down