reactjs - 如何充满情感地设计material-ui组件的样式

标签 reactjs material-ui emotion react-tsx

我想要为 Material Ui Tooltip 组件设置样式,并且想要定位它的工具提示和箭头类,我应该如何为它们添加情感样式?

我尝试遵循本指南:https://github.com/mui-org/material-ui/issues/11467#issuecomment-423845900 但我需要定位 css 类。

这是我尝试过的:

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';
    `;

我想要的只是从 Material ui 工具提示创建自定义组件,并将样式添加到工具提示 bakcground 和箭头颜色。我应该如何用情感和 Material 来实现它?

最佳答案

这个例子应该可以工作

    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;

关于reactjs - 如何充满情感地设计material-ui组件的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66820469/

相关文章:

javascript - 如何在 React 中渲染多个 tr 行

javascript - react : how to get Material UI's grid spacing to work?

material-ui - 你如何改变 Material 中弹出框的宽度和高度?

css - 如何使用 CSS-in-JS 方法设置 body 标签的样式?

javascript - 情感/样式 - 将鼠标悬停在 SVG 组件上

reactjs - Webpack 4,babel 7,react, typescript : Unexpected token,预期的 ","

reactjs - React Material-Table 如何传递 rowData 参数?

javascript - React.js JSON 数据更新,但状态不更新,因此 UI 不更新

reactjs - Material-UI DataGrid 宽度问题

reactjs - 如何使用情感js将多个类名传递给内部子级