You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.1 KiB
64 lines
1.1 KiB
import { |
|
Button as MuiButton, |
|
buttonClasses as muiButtonClasses, |
|
styled, |
|
} from '@mui/material'; |
|
import { FC } from 'react'; |
|
|
|
import { |
|
BLACK, |
|
BLUE, |
|
DISABLED, |
|
GREY, |
|
RED, |
|
TEXT, |
|
} from '../lib/consts/DEFAULT_THEME'; |
|
|
|
const MAP_TO_COLOUR: Record<ContainedButtonBackground, string> = { |
|
blue: BLUE, |
|
normal: GREY, |
|
red: RED, |
|
}; |
|
|
|
const BaseStyle = styled(MuiButton)({ |
|
backgroundColor: GREY, |
|
color: BLACK, |
|
textTransform: 'none', |
|
|
|
'&:hover': { |
|
backgroundColor: `${GREY}F0`, |
|
}, |
|
|
|
[`&.${muiButtonClasses.disabled}`]: { |
|
backgroundColor: DISABLED, |
|
}, |
|
}); |
|
|
|
const Base: FC<ContainedButtonProps> = (props) => ( |
|
<BaseStyle variant="contained" {...props} /> |
|
); |
|
|
|
const ContainedButton = styled(Base)((props) => { |
|
const { background = 'normal' } = props; |
|
|
|
let bg: string | undefined; |
|
let color: string | undefined; |
|
|
|
if (background !== 'normal') { |
|
bg = MAP_TO_COLOUR[background]; |
|
color = TEXT; |
|
} |
|
|
|
return { |
|
backgroundColor: bg, |
|
color, |
|
|
|
'&:hover': { |
|
backgroundColor: `${bg}F0`, |
|
}, |
|
}; |
|
}); |
|
|
|
export { MAP_TO_COLOUR }; |
|
|
|
export default ContainedButton;
|
|
|