anvil/striker-ui/components/Bars/AllocationBar.tsx

66 lines
1.4 KiB
TypeScript
Raw Normal View History

import { LinearProgress } from '@mui/material';
import { styled } from '@mui/material/styles';
import {
PURPLE,
RED,
BLUE,
BORDER_RADIUS,
} from '../../lib/consts/DEFAULT_THEME';
import BorderLinearProgress from './BorderLinearProgress';
const PREFIX = 'AllocationBar';
2021-03-10 17:06:52 +00:00
const classes = {
barOk: `${PREFIX}-barOk`,
barWarning: `${PREFIX}-barWarning`,
barAlert: `${PREFIX}-barAlert`,
underline: `${PREFIX}-underline`,
};
2021-03-10 17:06:52 +00:00
const StyledDiv = styled('div')(() => ({
[`& .${classes.barOk}`]: {
backgroundColor: BLUE,
},
[`& .${classes.barWarning}`]: {
backgroundColor: PURPLE,
},
[`& .${classes.barAlert}`]: {
backgroundColor: RED,
},
[`& .${classes.underline}`]: {
borderRadius: BORDER_RADIUS,
},
}));
const breakpointWarning = 70;
const breakpointAlert = 90;
const AllocationBar = ({ allocated }: { allocated: number }): JSX.Element => (
<StyledDiv>
<BorderLinearProgress
classes={{
bar:
/* eslint-disable no-nested-ternary */
allocated > breakpointWarning
? allocated > breakpointAlert
? classes.barAlert
: classes.barWarning
: classes.barOk,
}}
variant="determinate"
value={allocated}
/>
<LinearProgress
className={classes.underline}
variant="determinate"
value={0}
/>
</StyledDiv>
);
2021-03-10 17:06:52 +00:00
export default AllocationBar;