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

Added spinnerPosition prop to allow modifying the position of the spinner. #88

Open
wants to merge 2 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
3 changes: 3 additions & 0 deletions JSR.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ If no props are passed to `<NextTopLoader />`, below is the default configuratio
height={3}
crawl={true}
showSpinner={true}
spinnerPosition="top-right"
easing="ease"
speed={200}
shadow="0 0 10px #2299DD,0 0 5px #2299DD"
Expand All @@ -162,6 +163,7 @@ If no props are passed to `<NextTopLoader />`, below is the default configuratio
- `height`: height of TopLoader in `px`.
- `crawl`: auto incrementing behavior for the TopLoader.
- `showSpinner`: to show spinner or not.
- `spinnerPosition`: to change the corner position of the spinner (top-right, top-left, bottom-right, bottom-left).
- `shadow`: a smooth shadow for the TopLoader. (set to `false` to disable it)
- `template`: to include custom HTML attributes for the TopLoader.
- `zIndex`: defines zIndex for the TopLoader.
Expand All @@ -177,6 +179,7 @@ If no props are passed to `<NextTopLoader />`, below is the default configuratio
| `height` | `number` | `3` |
| `crawl` | `boolean` | `true` |
| `showSpinner` | `boolean` | `true` |
| `spinnerPosition` | `string` | `"top-right"` |
| `easing` | `string` | `"ease"` |
| `speed` | `number` | `200` |
| `shadow` | `string \| false` | `"0 0 10px ${color}, 0 0 5px ${color}"` |
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ If no props are passed to `<NextTopLoader />`, below is the default configuratio
height={3}
crawl={true}
showSpinner={true}
spinnerPosition="top-right"
easing="ease"
speed={200}
shadow="0 0 10px #2299DD,0 0 5px #2299DD"
Expand All @@ -153,6 +154,7 @@ If no props are passed to `<NextTopLoader />`, below is the default configuratio
- `height`: height of TopLoader in `px`.
- `crawl`: auto incrementing behavior for the TopLoader.
- `showSpinner`: to show spinner or not.
- `spinnerPosition`: to change the corner position of the spinner (top-right, top-left, bottom-right, bottom-left).
- `shadow`: a smooth shadow for the TopLoader. (set to `false` to disable it)
- `template`: to include custom HTML attributes for the TopLoader.
- `zIndex`: defines zIndex for the TopLoader.
Expand All @@ -168,6 +170,7 @@ If no props are passed to `<NextTopLoader />`, below is the default configuratio
| `height` | `number` | `3` |
| `crawl` | `boolean` | `true` |
| `showSpinner` | `boolean` | `true` |
| `spinnerPosition` | `string` | `"top-right"` |
| `easing` | `string` | `"ease"` |
| `speed` | `number` | `200` |
| `shadow` | `string \| false` | `"0 0 10px #2299DD,0 0 5px #2299DD"` |
Expand Down
42 changes: 34 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export type NextTopLoaderProps = {
* @default true
*/
showSpinner?: boolean;
/**
* To change the corner position of the spinner. (top-left, top-right, bottom-left, bottom-right)
* @default "top-right"
*/
spinnerPosition?: string;
/**
* Animation settings using easing (a CSS easing string).
* @default "ease"
Expand Down Expand Up @@ -95,6 +100,7 @@ const NextTopLoader = ({
color: propColor,
height: propHeight,
showSpinner,
spinnerPosition,
crawl,
crawlSpeed,
initialPosition,
Expand All @@ -116,19 +122,38 @@ const NextTopLoader = ({
!shadow && shadow !== undefined
? ''
: shadow
? `box-shadow:${shadow}`
: `box-shadow:0 0 10px ${color},0 0 5px ${color}`;
? `box-shadow:${shadow}`
: `box-shadow:0 0 10px ${color},0 0 5px ${color}`;

// Check if to show at bottom
const positionStyle = showAtBottom ? 'bottom: 0;' : 'top: 0;';
const spinnerPositionStyle = showAtBottom ? 'bottom: 15px;' : 'top: 15px;';

// Setting the corner position of the spinner
let spinnerPositionStyle;
switch (spinnerPosition) {
case 'top-right':
spinnerPositionStyle = 'top: 15px; right: 15px;';
break;
case 'top-left':
spinnerPositionStyle = 'top: 15px; left: 15px;';
break;
case 'bottom-right':
spinnerPositionStyle = 'bottom: 15px; right: 15px;';
break;
case 'bottom-left':
spinnerPositionStyle = 'bottom: 15px; left: 15px;';
break;
default:
spinnerPositionStyle = 'top: 15px; right: 15px;';
break;
}

/**
* CSS Styles for the NextTopLoader
*/
const styles = (
<style>
{`#nprogress{pointer-events:none}#nprogress .bar{background:${color};position:fixed;z-index:${zIndex};${positionStyle}left:0;width:100%;height:${height}px}#nprogress .peg{display:block;position:absolute;right:0;width:100px;height:100%;${boxShadow};opacity:1;-webkit-transform:rotate(3deg) translate(0px,-4px);-ms-transform:rotate(3deg) translate(0px,-4px);transform:rotate(3deg) translate(0px,-4px)}#nprogress .spinner{display:block;position:fixed;z-index:${zIndex};${spinnerPositionStyle}right:15px}#nprogress .spinner-icon{width:18px;height:18px;box-sizing:border-box;border:2px solid transparent;border-top-color:${color};border-left-color:${color};border-radius:50%;-webkit-animation:nprogress-spinner 400ms linear infinite;animation:nprogress-spinner 400ms linear infinite}.nprogress-custom-parent{overflow:hidden;position:relative}.nprogress-custom-parent #nprogress .bar,.nprogress-custom-parent #nprogress .spinner{position:absolute}@-webkit-keyframes nprogress-spinner{0%{-webkit-transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg)}}@keyframes nprogress-spinner{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}`}
{`#nprogress{pointer-events:none}#nprogress .bar{background:${color};position:fixed;z-index:${zIndex};${positionStyle}left:0;width:100%;height:${height}px}#nprogress .peg{display:block;position:absolute;right:0;width:100px;height:100%;${boxShadow};opacity:1;-webkit-transform:rotate(3deg) translate(0px,-4px);-ms-transform:rotate(3deg) translate(0px,-4px);transform:rotate(3deg) translate(0px,-4px)}#nprogress .spinner{display:block;position:fixed;z-index:${zIndex};${spinnerPositionStyle}}#nprogress .spinner-icon{width:18px;height:18px;box-sizing:border-box;border:2px solid transparent;border-top-color:${color};border-left-color:${color};border-radius:50%;-webkit-animation:nprogress-spinner 400ms linear infinite;animation:nprogress-spinner 400ms linear infinite}.nprogress-custom-parent{overflow:hidden;position:relative}.nprogress-custom-parent #nprogress .bar,.nprogress-custom-parent #nprogress .spinner{position:absolute}@-webkit-keyframes nprogress-spinner{0%{-webkit-transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg)}}@keyframes nprogress-spinner{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}`}
</style>
);

Expand Down Expand Up @@ -288,10 +313,10 @@ const NextTopLoader = ({
})((window as Window).history);

/**
* Complete TopLoader Progress on replacing current entry of history stack
* @param {History}
* @returns {void}
*/
* Complete TopLoader Progress on replacing current entry of history stack
* @param {History}
* @returns {void}
*/
((history: History): void => {
const replaceState = history.replaceState;
history.replaceState = (...args) => {
Expand Down Expand Up @@ -335,6 +360,7 @@ NextTopLoader.propTypes = {
color: PropTypes.string,
height: PropTypes.number,
showSpinner: PropTypes.bool,
spinnerPosition: PropTypes.string,
crawl: PropTypes.bool,
crawlSpeed: PropTypes.number,
initialPosition: PropTypes.number,
Expand Down
23 changes: 22 additions & 1 deletion src/pages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const PagesTopLoader = ({
color: propColor,
height: propHeight,
showSpinner,
spinnerPosition,
crawl,
crawlSpeed,
initialPosition,
Expand All @@ -39,7 +40,26 @@ export const PagesTopLoader = ({

// Check if to show at bottom
const positionStyle = showAtBottom ? 'bottom: 0;' : 'top: 0;';
const spinnerPositionStyle = showAtBottom ? 'bottom: 15px;' : 'top: 15px;';

// Setting the corner position of the spinner
let spinnerPositionStyle;
switch (spinnerPosition) {
case 'top-right':
spinnerPositionStyle = 'top: 15px; right: 15px;';
break;
case 'top-left':
spinnerPositionStyle = 'top: 15px; left: 15px;';
break;
case 'bottom-right':
spinnerPositionStyle = 'bottom: 15px; right: 15px;';
break;
case 'bottom-left':
spinnerPositionStyle = 'bottom: 15px; left: 15px;';
break;
default:
spinnerPositionStyle = 'top: 15px; right: 15px;';
break;
}

/**
* CSS Styles for the NextTopLoader
Expand Down Expand Up @@ -85,6 +105,7 @@ PagesTopLoader.propTypes = {
color: PropTypes.string,
height: PropTypes.number,
showSpinner: PropTypes.bool,
spinnerPosition: PropTypes.string,
crawl: PropTypes.bool,
crawlSpeed: PropTypes.number,
initialPosition: PropTypes.number,
Expand Down