gpt4 book ai didi

reactjs - 覆盖 Material UI 按钮文本

转载 作者:行者123 更新时间:2023-12-03 15:06:56 24 4
gpt4 key购买 nike

Material UI 按钮默认按钮内的文本为大写。我想用按钮覆盖文本,使其与我输入的文本相同,而不是大写。

我试图通过使用 texttransform 覆盖样式 - 无

viewButton: 
{
backgroundColor: "#00D2BC",
radius: "3px",
color: "#FFFFFF",
texttransform: "none"
}

<Button
className={classes.viewButton}
data-document={n.id}
onClick={this.handleView}
>
View Document
</Button>

有人能帮忙吗。

谢谢

最佳答案

我在您的问题中看到的代码的唯一问题是您有“text t ransform”而不是“text T ransform”。
按钮的这一方面由主题( hereherehere )控制,因此也可以通过主题进行更改。我在下面的代码中演示了这两种方法。

import React from "react";
import ReactDOM from "react-dom";
import {
makeStyles,
createMuiTheme,
MuiThemeProvider
} from "@material-ui/core/styles";
import Button from "@material-ui/core/Button";

const useStyles = makeStyles({
button: {
textTransform: "none"
}
});
const defaultTheme = createMuiTheme();
const theme = createMuiTheme({
typography: {
button: {
textTransform: "none"
}
}
});

function App() {
const classes = useStyles();
return (
<MuiThemeProvider theme={defaultTheme}>
<Button>Default Behavior</Button>
<Button className={classes.button}>Retain Case Via makeStyles</Button>
<MuiThemeProvider theme={theme}>
<Button>Retain Case Via theme change</Button>
</MuiThemeProvider>
</MuiThemeProvider>
);
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Edit button textTransform

这是一个类似的示例,但适用于 Material-UI 的 v5:
import React from "react";
import ReactDOM from "react-dom";
import { styled, createTheme, ThemeProvider } from "@material-ui/core/styles";
import Button from "@material-ui/core/Button";

const StyledButton = styled(Button)(`
text-transform: none;
`);
const defaultTheme = createTheme();
const theme1 = createTheme({
typography: {
button: {
textTransform: "none"
}
}
});
const theme2 = createTheme({
components: {
MuiButton: {
styleOverrides: {
root: {
textTransform: "none"
}
}
}
}
});

function App() {
return (
<ThemeProvider theme={defaultTheme}>
<Button>Default Behavior</Button>
<StyledButton>Retain Case Via styled</StyledButton>
<ThemeProvider theme={theme1}>
<Button>Retain Case Via theme change</Button>
</ThemeProvider>
<ThemeProvider theme={theme2}>
<Button>Retain Case Via alternate theme change</Button>
</ThemeProvider>
</ThemeProvider>
);
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Edit button textTransform

关于reactjs - 覆盖 Material UI 按钮文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57222924/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com