-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
line-progress.tsx
39 lines (34 loc) · 1.03 KB
/
line-progress.tsx
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
import "./line-progress.scss";
import React from "react";
import { cssNames } from "../../utils";
import { TooltipDecoratorProps, withTooltip } from "../tooltip";
export interface LineProgressProps extends React.HTMLProps<any>, TooltipDecoratorProps {
value: number;
min?: number;
max?: number;
className?: any;
precise?: number;
}
@withTooltip
export class LineProgress extends React.PureComponent<LineProgressProps> {
static defaultProps: LineProgressProps = {
value: 0,
min: 0,
max: 100,
precise: 2,
};
render() {
const { className, min, max, value, precise, children, ...props } = this.props;
let valuePercents = Math.min(100, value / (max - min) * 100);
const valuePercentsRounded = +valuePercents.toFixed(precise);
if (valuePercentsRounded) {
valuePercents = valuePercentsRounded;
}
return (
<div className={cssNames("LineProgress", className)} {...props}>
<div className="line" style={{ width: `${valuePercents}%` }}></div>
{children}
</div>
);
}
}