-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
120 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { adoptedStyle, customElement } from '@mantou/gem/lib/decorators'; | ||
import { GemElement, html } from '@mantou/gem/lib/element'; | ||
import { createCSSSheet, css } from '@mantou/gem/lib/utils'; | ||
|
||
import { theme } from '../helper/theme'; | ||
|
||
const style = createCSSSheet(css` | ||
:host { | ||
z-index: 22222222; | ||
position: fixed; | ||
display: flex; | ||
justify-content: flex-end; | ||
align-items: flex-end; | ||
top: 0; | ||
left: 0; | ||
height: 2px; | ||
transition: width 0.3s; | ||
background-color: ${theme.primaryColor}; | ||
} | ||
.head { | ||
width: 300px; | ||
height: 400%; | ||
background-color: inherit; | ||
border-start-start-radius: 50%; | ||
border-end-start-radius: 50%; | ||
filter: drop-shadow(0 0 4px ${theme.primaryColor}); | ||
} | ||
`); | ||
|
||
/** | ||
* @customElement gem-book-loadbar | ||
*/ | ||
@customElement('gem-book-loadbar') | ||
@adoptedStyle(style) | ||
export class GemBookLoadbarElement extends GemElement { | ||
static instance?: GemBookLoadbarElement; | ||
static timer = 0; | ||
|
||
static async start({ delay = 100 }: { delay?: number } = {}) { | ||
clearInterval(Loadbar.timer); | ||
Loadbar.timer = window.setTimeout(() => { | ||
const instance = Loadbar.instance || new Loadbar(); | ||
instance.setState({ progress: 0 }); | ||
Loadbar.timer = window.setInterval(() => { | ||
instance.setState({ progress: instance.state.progress + (95 - instance.state.progress) * 0.1 }); | ||
}, 100); | ||
}, delay); | ||
} | ||
|
||
static async end() { | ||
clearInterval(Loadbar.timer); | ||
const instance = Loadbar.instance; | ||
if (instance) { | ||
instance.setState({ progress: 100 }); | ||
await new Promise((res) => setTimeout(res, 300)); | ||
instance.remove(); | ||
} | ||
} | ||
|
||
constructor() { | ||
super(); | ||
document.body.append(this); | ||
this.internals.role = 'progressbar'; | ||
} | ||
|
||
state = { | ||
progress: 0, | ||
}; | ||
|
||
mounted = () => { | ||
Loadbar.instance = this; | ||
return () => (Loadbar.instance = undefined); | ||
}; | ||
|
||
render = () => { | ||
return html` | ||
<style> | ||
:host { | ||
width: ${this.state.progress}%; | ||
} | ||
</style> | ||
<div class="head"></div> | ||
`; | ||
}; | ||
} | ||
|
||
export const Loadbar = GemBookLoadbarElement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters