Material UI 的工具提示 - 自定义样式
Material UI's Tooltip - Customization Style
如何更改 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>
以下是如何通过主题覆盖所有工具提示,或使用 withStyles 仅自定义单个工具提示的示例(两个不同的示例)。第二种方法也可用于创建自定义工具提示组件,您可以重复使用该组件而无需强制在全局范围内使用它。
import React from "react";
import ReactDOM from "react-dom";
import {
createMuiTheme,
MuiThemeProvider,
withStyles
} from "@material-ui/core/styles";
import Tooltip from "@material-ui/core/Tooltip";
const defaultTheme = createMuiTheme();
const theme = createMuiTheme({
overrides: {
MuiTooltip: {
tooltip: {
fontSize: "2em",
color: "yellow",
backgroundColor: "red"
}
}
}
});
const BlueOnGreenTooltip = withStyles({
tooltip: {
color: "lightblue",
backgroundColor: "green"
}
})(Tooltip);
const TextOnlyTooltip = withStyles({
tooltip: {
color: "black",
backgroundColor: "transparent"
}
})(Tooltip);
function App(props) {
return (
<MuiThemeProvider theme={defaultTheme}>
<div className="App">
<MuiThemeProvider theme={theme}>
<Tooltip title="This tooltip is customized via overrides in the theme">
<div style={{ marginBottom: "20px" }}>
Hover to see tooltip customized via theme
</div>
</Tooltip>
</MuiThemeProvider>
<BlueOnGreenTooltip title="This tooltip is customized via withStyles">
<div style={{ marginBottom: "20px" }}>
Hover to see blue-on-green tooltip customized via withStyles
</div>
</BlueOnGreenTooltip>
<TextOnlyTooltip title="This tooltip is customized via withStyles">
<div>Hover to see text-only tooltip customized via withStyles</div>
</TextOnlyTooltip>
</div>
</MuiThemeProvider>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
这里是关于工具提示 CSS 类 的文档,可用于控制工具提示行为的不同方面:https://material-ui.com/api/tooltip/#css
这里是关于在主题中覆盖这些 类 的文档:https://material-ui.com/customization/components/#global-theme-override
如何更改 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>
以下是如何通过主题覆盖所有工具提示,或使用 withStyles 仅自定义单个工具提示的示例(两个不同的示例)。第二种方法也可用于创建自定义工具提示组件,您可以重复使用该组件而无需强制在全局范围内使用它。
import React from "react";
import ReactDOM from "react-dom";
import {
createMuiTheme,
MuiThemeProvider,
withStyles
} from "@material-ui/core/styles";
import Tooltip from "@material-ui/core/Tooltip";
const defaultTheme = createMuiTheme();
const theme = createMuiTheme({
overrides: {
MuiTooltip: {
tooltip: {
fontSize: "2em",
color: "yellow",
backgroundColor: "red"
}
}
}
});
const BlueOnGreenTooltip = withStyles({
tooltip: {
color: "lightblue",
backgroundColor: "green"
}
})(Tooltip);
const TextOnlyTooltip = withStyles({
tooltip: {
color: "black",
backgroundColor: "transparent"
}
})(Tooltip);
function App(props) {
return (
<MuiThemeProvider theme={defaultTheme}>
<div className="App">
<MuiThemeProvider theme={theme}>
<Tooltip title="This tooltip is customized via overrides in the theme">
<div style={{ marginBottom: "20px" }}>
Hover to see tooltip customized via theme
</div>
</Tooltip>
</MuiThemeProvider>
<BlueOnGreenTooltip title="This tooltip is customized via withStyles">
<div style={{ marginBottom: "20px" }}>
Hover to see blue-on-green tooltip customized via withStyles
</div>
</BlueOnGreenTooltip>
<TextOnlyTooltip title="This tooltip is customized via withStyles">
<div>Hover to see text-only tooltip customized via withStyles</div>
</TextOnlyTooltip>
</div>
</MuiThemeProvider>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
这里是关于工具提示 CSS 类 的文档,可用于控制工具提示行为的不同方面:https://material-ui.com/api/tooltip/#css
这里是关于在主题中覆盖这些 类 的文档:https://material-ui.com/customization/components/#global-theme-override