英文:
Override Material UI 5 Button Text in my theme
问题
我正在尝试将 MuiButton 文本改为小写,但我找不到方法。
我分享代码和截图。
theme.jsx
import { createTheme } from "@mui/material/styles";
export const theme = createTheme({
palette: {
mode: "light",
primary: {
main: "#E9531E",
},
secondary: {
main: "#4357AD",
},
},
typography: {
fontFamily: "Roboto",
textTransform: "none",
},...
overrides: {
MuiButton: {
root: {
background: "linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)",
border: 0,
borderRadius: 3,
boxShadow: "0 3px 5px 2px rgba(255, 105, 135, .3)",
color: "white",
height: 48,
padding: "0 30px",
textTransform: "none",
},
},
App.jsx
import Navbar from "./components/Navbar";
import Login from "./pages/Login";
function App() {
return (
<div className="App">
<Navbar />
<Login />
</div>
);
}
export default App;
index.jsx
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import { ThemeProvider } from "@mui/material";
import { theme } from "./theme";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>
);
我尝试过使用 styled,但我不知道如何正确使用它们。
英文:
I'm trying to change the MuiButton text to lowercase but I can't find a way.
I share code and screenshot.
theme.jsx
import { createTheme, } from "@mui/material/styles";
export const theme = createTheme({
palette: {
mode: "light",
primary: {
main: "#E9531E",
},
secondary: {
main: "#4357AD",
},
},
typography: {
fontFamily: "Roboto",
textTransform: "none",
},...
overrides: {
MuiButton: {
root: {
background: "linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)",
border: 0,
borderRadius: 3,
boxShadow: "0 3px 5px 2px rgba(255, 105, 135, .3)",
color: "white",
height: 48,
padding: "0 30px",
textTransform: "none",
},
},
App.jsx
import Navbar from "./components/Navbar";
import Login from "./pages/Login";
function App() {
return (
<div className="App">
<Navbar />
<Login />
</div>
);
}
export default App;
index.jsx
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import { ThemeProvider } from "@mui/material";
import { theme } from "./theme";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>
);
The global text style changes but the button style does not.
I have tried styled but I don't know how to use them well.
答案1
得分: 0
你需要将样式覆盖更改为以下内容:
const theme = createTheme({
...,
components: {
MuiButton: {
styleOverrides: {
root: {
background: "linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)",
border: 0,
borderRadius: 3,
boxShadow: "0 3px 5px 2px rgba(255, 105, 135, .3)",
color: "white",
height: 48,
padding: "0 30px",
textTransform: "none",
},
},
},
},
});
查看文档以获取更多信息:
https://mui.com/material-ui/customization/theme-components/#theme-style-overrides
英文:
You need to change the style overrides to this:
const theme = createTheme({
...,
components: {
MuiButton: {
styleOverrides: {
root: {
background: "linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)",
border: 0,
borderRadius: 3,
boxShadow: "0 3px 5px 2px rgba(255, 105, 135, .3)",
color: "white",
height: 48,
padding: "0 30px",
textTransform: "none",
},
},
},
},
});
Check out the docs for more information:
https://mui.com/material-ui/customization/theme-components/#theme-style-overrides
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论