fix(striker-ui): simplify bar underline, add stack bar

main
Tsu-ba-me 1 year ago
parent 8eda5b1849
commit 66a1e6c111
  1. 23
      striker-ui/components/Bars/AllocationBar.tsx
  2. 15
      striker-ui/components/Bars/BorderLinearProgress.tsx
  3. 18
      striker-ui/components/Bars/ProgressBar.tsx
  4. 72
      striker-ui/components/Bars/StackBar.tsx
  5. 13
      striker-ui/components/Bars/Underline.tsx
  6. 3
      striker-ui/components/Bars/index.tsx
  7. 8
      striker-ui/types/StackBar.d.ts

@ -1,13 +1,9 @@
import { LinearProgress } from '@mui/material'; import { styled } from '@mui/material';
import { styled } from '@mui/material/styles';
import { PURPLE, RED, BLUE } from '../../lib/consts/DEFAULT_THEME';
import {
PURPLE,
RED,
BLUE,
BORDER_RADIUS,
} from '../../lib/consts/DEFAULT_THEME';
import BorderLinearProgress from './BorderLinearProgress'; import BorderLinearProgress from './BorderLinearProgress';
import Underline from './Underline';
const PREFIX = 'AllocationBar'; const PREFIX = 'AllocationBar';
@ -15,7 +11,6 @@ const classes = {
barOk: `${PREFIX}-barOk`, barOk: `${PREFIX}-barOk`,
barWarning: `${PREFIX}-barWarning`, barWarning: `${PREFIX}-barWarning`,
barAlert: `${PREFIX}-barAlert`, barAlert: `${PREFIX}-barAlert`,
underline: `${PREFIX}-underline`,
}; };
const StyledDiv = styled('div')(() => ({ const StyledDiv = styled('div')(() => ({
@ -30,10 +25,6 @@ const StyledDiv = styled('div')(() => ({
[`& .${classes.barAlert}`]: { [`& .${classes.barAlert}`]: {
backgroundColor: RED, backgroundColor: RED,
}, },
[`& .${classes.underline}`]: {
borderRadius: BORDER_RADIUS,
},
})); }));
const breakpointWarning = 70; const breakpointWarning = 70;
@ -54,11 +45,7 @@ const AllocationBar = ({ allocated }: { allocated: number }): JSX.Element => (
variant="determinate" variant="determinate"
value={allocated} value={allocated}
/> />
<LinearProgress <Underline />
className={classes.underline}
variant="determinate"
value={0}
/>
</StyledDiv> </StyledDiv>
); );

@ -1,14 +1,15 @@
import { LinearProgress } from '@mui/material'; import { LinearProgress, linearProgressClasses, styled } from '@mui/material';
import { styled } from '@mui/material/styles';
import { import { BORDER_RADIUS } from '../../lib/consts/DEFAULT_THEME';
PANEL_BACKGROUND,
BORDER_RADIUS,
} from '../../lib/consts/DEFAULT_THEME';
const BorderLinearProgress = styled(LinearProgress)({ const BorderLinearProgress = styled(LinearProgress)({
backgroundColor: 'transparent',
borderRadius: BORDER_RADIUS,
height: '1em', height: '1em',
[`& .${linearProgressClasses.bar}`]: {
borderRadius: BORDER_RADIUS, borderRadius: BORDER_RADIUS,
backgroundColor: PANEL_BACKGROUND, },
}); });
export default BorderLinearProgress; export default BorderLinearProgress;

@ -1,15 +1,15 @@
import { LinearProgress } from '@mui/material'; import { styled } from '@mui/material';
import { styled } from '@mui/material/styles';
import { PURPLE, BLUE } from '../../lib/consts/DEFAULT_THEME';
import { PURPLE, BLUE, BORDER_RADIUS } from '../../lib/consts/DEFAULT_THEME';
import BorderLinearProgress from './BorderLinearProgress'; import BorderLinearProgress from './BorderLinearProgress';
import Underline from './Underline';
const PREFIX = 'ProgressBar'; const PREFIX = 'ProgressBar';
const classes = { const classes = {
barOk: `${PREFIX}-barOk`, barOk: `${PREFIX}-barOk`,
barInProgress: `${PREFIX}-barInProgress`, barInProgress: `${PREFIX}-barInProgress`,
underline: `${PREFIX}-underline`,
}; };
const StyledDiv = styled('div')(() => ({ const StyledDiv = styled('div')(() => ({
@ -20,10 +20,6 @@ const StyledDiv = styled('div')(() => ({
[`& .${classes.barInProgress}`]: { [`& .${classes.barInProgress}`]: {
backgroundColor: PURPLE, backgroundColor: PURPLE,
}, },
[`& .${classes.underline}`]: {
borderRadius: BORDER_RADIUS,
},
})); }));
const completed = 100; const completed = 100;
@ -44,11 +40,7 @@ const ProgressBar = ({
variant="determinate" variant="determinate"
value={progressPercentage} value={progressPercentage}
/> />
<LinearProgress <Underline />
className={classes.underline}
variant="determinate"
value={0}
/>
</StyledDiv> </StyledDiv>
); );

@ -0,0 +1,72 @@
import { Box, linearProgressClasses } from '@mui/material';
import { FC, ReactElement, useMemo } from 'react';
import { GREY } from '../../lib/consts/DEFAULT_THEME';
import BorderLinearProgress from './BorderLinearProgress';
import Underline from './Underline';
const StackBar: FC<StackBarProps> = (props) => {
const { value } = props;
const values = useMemo<Record<string, StackBarValue>>(
() => ('value' in value ? { default: value as StackBarValue } : value),
[value],
);
const entries = useMemo<[string, StackBarValue][]>(
() => Object.entries(values).reverse(),
[values],
);
const bars = useMemo<ReactElement[]>(
() =>
entries.map<ReactElement>(
([id, { colour = GREY, value: val }], index) => {
const backgroundColor =
typeof colour === 'string'
? colour
: Object.entries(colour).findLast(
([mark]) => val >= Number(mark),
)?.[1] ?? GREY;
let position: 'absolute' | 'relative' = 'relative';
let top: 0 | undefined;
let width: string | undefined;
if (index) {
position = 'absolute';
top = 0;
width = '100%';
}
return (
<BorderLinearProgress
key={`stack-bar-${id}`}
sx={{
position,
top,
width,
[`& .${linearProgressClasses.bar}`]: {
backgroundColor,
},
}}
variant="determinate"
value={val}
/>
);
},
),
[entries],
);
return (
<Box position="relative">
{bars}
<Underline />
</Box>
);
};
export default StackBar;

@ -0,0 +1,13 @@
import { Box, styled } from '@mui/material';
import { BORDER_RADIUS, DISABLED } from '../../lib/consts/DEFAULT_THEME';
const Underline = styled(Box)({
backgroundColor: DISABLED,
borderRadius: BORDER_RADIUS,
display: 'block',
height: '4px',
position: 'relative',
});
export default Underline;

@ -1,4 +1,5 @@
import AllocationBar from './AllocationBar'; import AllocationBar from './AllocationBar';
import ProgressBar from './ProgressBar'; import ProgressBar from './ProgressBar';
import StackBar from './StackBar';
export { AllocationBar, ProgressBar }; export { AllocationBar, ProgressBar, StackBar };

@ -0,0 +1,8 @@
type StackBarValue = {
colour?: string | Record<number, string>;
value: number;
};
type StackBarProps = {
value: StackBarValue | Record<string, StackBarValue>;
};
Loading…
Cancel
Save