From 3f68c241c7ef283d673f551f6d8c5a0641fb79c9 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Wed, 28 Sep 2022 20:20:16 -0400 Subject: [PATCH] feat(striker-ui): add IconWithIndicator --- striker-ui/components/IconWithIndicator.tsx | 92 +++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 striker-ui/components/IconWithIndicator.tsx diff --git a/striker-ui/components/IconWithIndicator.tsx b/striker-ui/components/IconWithIndicator.tsx new file mode 100644 index 00000000..bf1f9123 --- /dev/null +++ b/striker-ui/components/IconWithIndicator.tsx @@ -0,0 +1,92 @@ +import { SvgIconComponent } from '@mui/icons-material'; +import { + Box as MUIBox, + BoxProps as MUIBoxProps, + SvgIconProps, +} from '@mui/material'; +import { createElement, FC } from 'react'; + +import { BLACK, BLUE } from '../lib/consts/DEFAULT_THEME'; + +import FlexBox, { FlexBoxProps } from './FlexBox'; + +type IconWithIndicatorOptionalPropsWithDefault = { + iconProps?: SvgIconProps; + indicatorProps?: FlexBoxProps; +}; + +type IconWithIndicatorOptionalProps = IconWithIndicatorOptionalPropsWithDefault; + +type IconWithIndicatorProps = MUIBoxProps & + IconWithIndicatorOptionalProps & { + icon: SvgIconComponent; + }; + +const ICON_WITH_INDICATOR_DEFAULT_PROPS: Required = + { + iconProps: {}, + indicatorProps: {}, + }; + +const IconWithIndicator: FC = ({ + icon, + iconProps: { + sx: iconSx, + + ...restIconProps + } = ICON_WITH_INDICATOR_DEFAULT_PROPS.iconProps, + indicatorProps: { + sx: indicatorSx, + + ...restIndicatorProps + } = ICON_WITH_INDICATOR_DEFAULT_PROPS.indicatorProps, + sx, +}) => { + const containerLength = '1.7em'; + const indicatorLength = '24%'; + const indicatorOffset = '.1rem'; + + return ( + + {createElement(icon, { + ...restIconProps, + + sx: { height: '100%', width: '100%', ...iconSx }, + })} + {createElement(FlexBox, { + row: true, + + ...restIndicatorProps, + + sx: { + backgroundColor: BLUE, + borderColor: BLACK, + borderRadius: '50%', + borderStyle: 'solid', + borderWidth: '.2rem', + bottom: indicatorOffset, + boxSizing: 'content-box', + height: 0, + justifyContent: 'center', + paddingBottom: indicatorLength, + position: 'absolute', + right: indicatorOffset, + width: indicatorLength, + + ...indicatorSx, + }, + })} + + ); +}; + +IconWithIndicator.defaultProps = ICON_WITH_INDICATOR_DEFAULT_PROPS; + +export default IconWithIndicator;