Skip to content

Commit

Permalink
feat: added primaryColor into configure (#3)
Browse files Browse the repository at this point in the history
* feat: added `primaryColor` into configure

* chore: demo update
  • Loading branch information
wangyewei authored Feb 4, 2024
1 parent 7058e54 commit acf8b6c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
8 changes: 5 additions & 3 deletions packages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class NProgress {
NProgress.set(100)
}

static render(from: Minimum) {
private static render(from: Minimum) {
if (NProgress.isRendered) return document.getElementById(ELEMENT_ID)

addClass(document.documentElement, 'nprogress-busy')
Expand All @@ -104,6 +104,8 @@ class NProgress {
progress.id = ELEMENT_ID
progress.innerHTML = NProgress.settings.template

document.documentElement.style.setProperty('--progress-primary-color', NProgress.settings.primaryColor)

const bar = progress.querySelector<HTMLElement>(
NProgress.settings.barSelector
)!
Expand Down Expand Up @@ -170,7 +172,7 @@ class NProgress {
progress && removeElement(progress)
}

static getPositionCss(): 'translate3d' | 'translate' | 'margin' {
private static getPositionCss(): 'translate3d' | 'translate' | 'margin' {
const bodyStyle = document.body.style

const vendorPrefix =
Expand All @@ -193,7 +195,7 @@ class NProgress {
}
}

static barPositionCSS(n: Minimum, speed: number, ease: string) {
private static barPositionCSS(n: Minimum, speed: number, ease: string) {
let barCSS: Record<string, any>

if (NProgress.settings.positionUsing === 'translate3d') {
Expand Down
2 changes: 2 additions & 0 deletions packages/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { DightEnum } from './utils/typed'

export type Minimum = DightEnum<101>
export type NProgressSetting = {
primaryColor: string
minimum: Minimum
easing: 'linear' | string
positionUsing: string
Expand All @@ -16,6 +17,7 @@ export type NProgressSetting = {
}

export const DEFAULT_SETTINGS: NProgressSetting = {
primaryColor: '#29d',
minimum: 1,
easing: 'linear',
positionUsing: '',
Expand Down
12 changes: 8 additions & 4 deletions packages/style.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* Make clicks pass-through */
:root {
--progress-primary-color: #29d;
}
#nprogress {
pointer-events: none;
}

#nprogress .bar {
background: #29d;
background: var(--progress-primary-color);

position: fixed;
z-index: 1031;
Expand All @@ -22,7 +25,8 @@
right: 0px;
width: 100px;
height: 100%;
box-shadow: 0 0 10px #29d, 0 0 5px #29d;
box-shadow: 0 0 10px var(--progress-primary-color),
0 0 5px var(--progress-primary-color);
opacity: 1;

-webkit-transform: rotate(3deg) translate(0px, -4px);
Expand All @@ -45,8 +49,8 @@
box-sizing: border-box;

border: solid 2px transparent;
border-top-color: #29d;
border-left-color: #29d;
border-top-color: var(--progress-primary-color);
border-left-color: var(--progress-primary-color);
border-radius: 50%;

-webkit-animation: nprogress-spinner 400ms linear infinite;
Expand Down
5 changes: 3 additions & 2 deletions playground/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Progress from "./dist/index.js"
import Progress from './dist/index.js'

window.addEventListener('DOMContentLoaded', () => {
const start = document.getElementById('start')
const set = document.getElementById('set')
const done = document.getElementById('done')

start.onclick = () => {
Progress.start()
}
Expand All @@ -15,4 +16,4 @@ window.addEventListener('DOMContentLoaded', () => {
done.onclick = () => {
Progress.done()
}
})
})
1 change: 0 additions & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type { NProgressSetting } from '../packages/settings'

const getProgress = () => document.getElementById('nprogress')
const rawSettings: NProgressSetting = deepClone(NProgress.settings)

describe('n-progress-esm', () => {


Expand Down

0 comments on commit acf8b6c

Please sign in to comment.