blob: da5fa2b00d18ce7b622adf38726108a7e14de237 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import * as React from 'react';
import { useEffect } from "react"
import "./ProgressBar.scss"
interface ProgressBarProps {
progress: number,
marks: number[],
playSegment: (idx: number) => void
}
export function ProgressBar(props: ProgressBarProps) {
const handleClick = (e: React.MouseEvent) => {
let progressbar = document.getElementById('progressbar')!
let bounds = progressbar!.getBoundingClientRect();
let x = e.clientX - bounds.left;
let percent = x / progressbar.clientWidth * 100
for (let i = 0; i < props.marks.length; i++) {
let start = i == 0 ? 0 : props.marks[i-1];
if (percent > start && percent < props.marks[i]) {
props.playSegment(i)
// console.log(i)
// console.log(percent)
// console.log(props.marks[i])
break
}
}
}
return(
<div className="progressbar" id="progressbar">
<div
className="progressbar done"
style={{ width: `${props.progress}%` }}
onClick={handleClick}
></div>
{props.marks.map((mark) => {
return <div
className="progressbar mark"
style={{ width: `${mark}%` }}
></div>
})}
</div>
)
}
|