anvil/striker-ui/components/Decorator.tsx

63 lines
1.1 KiB
TypeScript
Raw Normal View History

import { Box as MUIBox, BoxProps as MUIBoxProps } from '@mui/material';
import { FC } from 'react';
import {
BLUE,
GREY,
PURPLE,
RED,
BORDER_RADIUS,
} from '../lib/consts/DEFAULT_THEME';
2021-04-30 16:42:52 +00:00
export type Colours = 'ok' | 'off' | 'error' | 'warning';
type DecoratorProps = MUIBoxProps & {
colour: Colours;
};
const PREFIX = 'Decorator';
2021-04-30 16:42:52 +00:00
const classes = {
ok: `${PREFIX}-ok`,
warning: `${PREFIX}-warning`,
error: `${PREFIX}-error`,
off: `${PREFIX}-off`,
};
const Decorator: FC<DecoratorProps> = ({
colour,
sx,
...restDecoratorProps
}): JSX.Element => (
<MUIBox
{...{
...restDecoratorProps,
className: classes[colour],
sx: {
borderRadius: BORDER_RADIUS,
height: '100%',
width: '1.4em',
[`&.${classes.ok}`]: {
backgroundColor: BLUE,
},
[`&.${classes.warning}`]: {
backgroundColor: PURPLE,
},
[`&.${classes.error}`]: {
backgroundColor: RED,
},
[`&.${classes.off}`]: {
backgroundColor: GREY,
},
...sx,
},
}}
/>
);
2021-04-30 16:42:52 +00:00
export default Decorator;