[英]How to style material-ui components with emotion
I want to style material Ui Tooltip component and I want to target it's tooltip and arrow classes, how I should add styles to them with emotion?我想设置材质 Ui Tooltip 组件的样式,并且我想定位它的工具提示和箭头类,我应该如何将 styles 情感添加到它们?
I tried to follow this guide: https://github.com/mui-org/material-ui/issues/11467#issuecomment-423845900 But I need to target css classes.我尝试遵循本指南: https://github.com/mui-org/material-ui/issues/11467#issuecomment-423845900但我需要针对 css 类。
This is what I tried:这是我尝试过的:
import Tooltip, { TooltipProps } from '@material-ui/core/Tooltip';
import { experimentalStyled } from '@material-ui/core/styles';
import { customThemeOptions } from '../utils/globalStyles';
import { Global, css } from '@emotion/react';
const PtMuiTooltip = experimentalStyled(
({ className, title, children, ...other }: TooltipProps) => (
<Tooltip
title={title}
style={{
'& .MuiTooltip-arrow': {
color: `${customThemeOptions.pt.palette.primary.main}`,
},
}}
{...other}
>
{children}
</Tooltip>
),
)`
background-color: ${customThemeOptions.pt.palette.primary.main};
box-shadow: '0px 1px 3px rgba(0, 0, 0, 0.1), 0px 0px 10px rgba(0, 0, 0, 0.06)';
padding: '1.5rem';
border-radius: '0';
`;
All I want is to create my custom component from material ui tooltip and add styles to tooltip bakcground and arrow color.我想要的只是从材料 ui 工具提示创建我的自定义组件,并将 styles 添加到工具提示 bakcground 和箭头颜色。 How I should achieve it with emotion and material-ui?我应该如何用情感和 material-ui 来实现它?
This example should work这个例子应该工作
import Tooltip, { TooltipProps } from '@material-ui/core/Tooltip';
import { experimentalStyled } from '@material-ui/core/styles';
import { customThemeOptions } from '../utils/globalStyles';
const PtMuiTooltip = experimentalStyled(
({ className, title, children, ...other }: TooltipProps) => (
<Tooltip
title={title}
classes={{ popper: className, arrow: 'arrow', tooltip: 'tooltip' }}
{...other}
>
{children}
</Tooltip>
),
)`
& .tooltip {
background-color: ${customThemeOptions.pt.palette.primary.main};
box-shadow: '0px 1px 3px rgba(0, 0, 0, 0.1), 0px 0px 10px rgba(0, 0, 0, 0.06)';
padding: '1.5rem';
border-radius: '0';
}
& .arrow {
color: ${customThemeOptions.pt.palette.primary.main};
}
`;
export default PtMuiTooltip;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.