-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from NeurodataWithoutBorders/basic-progress-bar
Add basic progress bar for multi-session conversions
- Loading branch information
Showing
7 changed files
with
184 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ProgressBar } from "./ProgressBar"; | ||
|
||
export default { | ||
title: "Components/Progress Bar", | ||
}; | ||
|
||
const Template = (args) => new ProgressBar(args); | ||
|
||
const b = 0; | ||
const tsize = 50; | ||
const bsize = 1; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
value: { | ||
b, | ||
bsize, | ||
tsize, | ||
}, | ||
}; | ||
|
||
function sleep(ms) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
Default.play = async ({ canvasElement }) => { | ||
const progressBar = canvasElement.querySelector("nwb-progress"); | ||
for (let i = 1; i <= tsize; i++) { | ||
await sleep(1000); | ||
progressBar.value = { b: i, tsize }; | ||
} | ||
}; |
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,69 @@ | ||
|
||
|
||
import { LitElement, html, css } from 'lit'; | ||
|
||
export type ProgressProps = { | ||
value?: { | ||
b: number, | ||
bsize?: number, | ||
tsize: number | ||
}, | ||
} | ||
|
||
export class ProgressBar extends LitElement { | ||
|
||
static get styles() { | ||
return css` | ||
:host { | ||
display: flex; | ||
align-items: center; | ||
} | ||
:host > div { | ||
width: 100%; | ||
height: 10px; | ||
border: 1px solid lightgray; | ||
overflow: hidden; | ||
} | ||
:host > div > div { | ||
width: 0%; | ||
height: 100%; | ||
background-color: #029CFD; | ||
transition: width 0.5s; | ||
} | ||
small { | ||
white-space: nowrap; | ||
margin-left: 10px; | ||
} | ||
`; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
value: { | ||
type: Object, | ||
reflect: true, | ||
} | ||
}; | ||
} | ||
|
||
declare value: any | ||
|
||
constructor(props: ProgressProps = {}) { | ||
super(); | ||
|
||
this.value = props.value ?? {} | ||
} | ||
|
||
render() { | ||
|
||
const value = this.value.b / this.value.tsize * 100 | ||
return html`<div><div style="width: ${value}%"></div></div><small>${this.value.b}/${this.value.tsize} (${value.toFixed(0)}%)</small>` | ||
} | ||
} | ||
|
||
customElements.get('nwb-progress') || customElements.define('nwb-progress', ProgressBar); |
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