如何更改Material UI的工具提示的背景颜色和颜色。我尝试了如下操作,但无法正常工作。
import { createMuiTheme } from '@material-ui/core/styles';
export const theme = createMuiTheme({
tooltip: {
color: '#ffffff',
rippleBackgroundColor: 'red'
}
});
import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider';
import { theme } from "my-path";
<MuiThemeProvider theme={theme} >
<Tooltip
title={this.props.title}
placement={this.props.placement} className="customTooltipStyle">
<em className="fa fa-info-circle"></em>
</Tooltip>
</MuiThemeProvider>
答案 0 :(得分:1)
下面是有关如何通过主题覆盖所有工具提示或仅使用withStyles自定义单个工具提示的示例。第二种方法也可以用于创建自定义工具提示组件,您可以在不强制将其全局使用的情况下重复使用它。
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
import {
createMuiTheme,
MuiThemeProvider,
withStyles
} from "@material-ui/core/styles";
import Tooltip from "@material-ui/core/Tooltip";
const theme = createMuiTheme({
overrides: {
MuiTooltip: {
tooltip: {
fontSize: "2em",
color: "yellow",
backgroundColor: "red"
}
}
}
});
const styles = {
tooltip: {
color: "lightblue",
backgroundColor: "green"
}
};
function App(props) {
return (
<div className="App">
<MuiThemeProvider theme={theme}>
<Tooltip title="This tooltip is customized via overrides in the theme">
<div>Hover to see tooltip</div>
</Tooltip>
</MuiThemeProvider>
<Tooltip
classes={props.classes}
title="This tooltip is customized via withStyles"
>
<div>Hover to see tooltip</div>
</Tooltip>
</div>
);
}
const StyledApp = withStyles(styles)(App);
const rootElement = document.getElementById("root");
ReactDOM.render(<StyledApp />, rootElement);
这是一个有效的示例:
以下是有关工具提示CSS类的文档,可用于控制工具提示行为的不同方面:https://material-ui.com/api/tooltip/#css
以下是主题中的覆盖这些类的文档:https://material-ui.com/customization/themes/#css