在我的 case 中,按钮是一个可重复使用的组件.它可以是带有白色文本的绿色,也可以是带有绿色文本和边框的白色.有更好的mui方法如何处理吗?
页面 :
<MainButton title="Login" />
<MainButton
title="Register"
additionalStyles={{ // add other styles
backgroundColor: "#e5f3fd",
color: "#33b864",
border: `1px solid ${theme.palette.secondary.main}`,
"&:hover": {
backgroundColor: "rgba(46, 171, 92, 0.1)",
},
}}
/>
-oh my 天.
export const MainButton = ({ title, additionalStyles }: MainButtonProps) => {
const theme = useTheme();
return (
<Button
sx={{
height: 40,
bgcolor: theme.palette.secondary.main,
color: "#ffffff",
textTransform: "none",
fontSize: 15,
fontWeight: 600,
borderRadius: 2,
"&:hover": {
bgcolor: "#2eab5c",
},
...additionalStyles,
}}
>
{title}
</Button>
);
};