fix(striker-ui): add thin option to stack bar

main
Tsu-ba-me 1 year ago
parent 66a1e6c111
commit 78cbdeb123
  1. 65
      striker-ui/components/Bars/StackBar.tsx
  2. 8
      striker-ui/types/StackBar.d.ts

@ -1,13 +1,23 @@
import { Box, linearProgressClasses } from '@mui/material'; import { Box, linearProgressClasses, styled } from '@mui/material';
import { FC, ReactElement, useMemo } from 'react'; import { FC, ReactElement, createElement, useMemo } from 'react';
import { GREY } from '../../lib/consts/DEFAULT_THEME'; import { GREY } from '../../lib/consts/DEFAULT_THEME';
import BorderLinearProgress from './BorderLinearProgress'; import RoundedLinearProgress from './BorderLinearProgress';
import Underline from './Underline'; import Underline from './Underline';
const ThinRoundedLinearProgress = styled(RoundedLinearProgress)({
height: '.4em',
});
const ThinUnderline = styled(Underline)({
height: '.2em',
});
const StackBar: FC<StackBarProps> = (props) => { const StackBar: FC<StackBarProps> = (props) => {
const { value } = props; const { barProps = {}, thin, underlineProps, value } = props;
const { sx: barSx, ...restBarProps } = barProps;
const values = useMemo<Record<string, StackBarValue>>( const values = useMemo<Record<string, StackBarValue>>(
() => ('value' in value ? { default: value as StackBarValue } : value), () => ('value' in value ? { default: value as StackBarValue } : value),
@ -19,6 +29,16 @@ const StackBar: FC<StackBarProps> = (props) => {
[values], [values],
); );
const creatableBar = useMemo(
() => (thin ? ThinRoundedLinearProgress : RoundedLinearProgress),
[thin],
);
const creatableUnderline = useMemo(
() => (thin ? ThinUnderline : Underline),
[thin],
);
const bars = useMemo<ReactElement[]>( const bars = useMemo<ReactElement[]>(
() => () =>
entries.map<ReactElement>( entries.map<ReactElement>(
@ -40,31 +60,32 @@ const StackBar: FC<StackBarProps> = (props) => {
width = '100%'; width = '100%';
} }
return ( return createElement(creatableBar, {
<BorderLinearProgress key: `stack-bar-${id}`,
key={`stack-bar-${id}`} sx: {
sx={{ position,
position, top,
top, width,
width,
[`& .${linearProgressClasses.bar}`]: {
[`& .${linearProgressClasses.bar}`]: { backgroundColor,
backgroundColor, },
},
}} ...barSx,
variant="determinate" },
value={val} variant: 'determinate',
/> value: val,
); ...restBarProps,
});
}, },
), ),
[entries], [barSx, entries, creatableBar, restBarProps],
); );
return ( return (
<Box position="relative"> <Box position="relative">
{bars} {bars}
<Underline /> {createElement(creatableUnderline, underlineProps)}
</Box> </Box>
); );
}; };

@ -3,6 +3,12 @@ type StackBarValue = {
value: number; value: number;
}; };
type StackBarProps = { type StackBarOptionalProps = {
barProps?: import('@mui/material').LinearProgressProps;
thin?: boolean;
underlineProps?: import('@mui/material').BoxProps;
};
type StackBarProps = StackBarOptionalProps & {
value: StackBarValue | Record<string, StackBarValue>; value: StackBarValue | Record<string, StackBarValue>;
}; };

Loading…
Cancel
Save