1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/dashboard/client/components/line-progress/line-progress.tsx
Jari Kolehmainen db4dca3005 lens app source code
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
2020-03-15 09:46:21 +02:00

38 lines
1016 B
TypeScript

import "./line-progress.scss";
import * as React from "react";
import { cssNames } from "../../utils";
import { TooltipDecoratorProps, withTooltip } from "../tooltip";
interface Props extends React.HTMLProps<any>, TooltipDecoratorProps {
value: number;
min?: number;
max?: number;
className?: any;
precise?: number;
}
@withTooltip
export class LineProgress extends React.PureComponent<Props> {
static defaultProps: Props = {
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>
);
}
}