小编ser*_*san的帖子

如何在全局 Material UI 中为 Alert 组件添加自定义关闭图标

我们可以通过主题全局自定义Alert组件中显示的严重性图标:

  MuiAlert: {
    defaultProps: {
      iconMapping: {
        info: <Info/>,
        success: <Success/>,
        warning: <Warning>,
        error: <Error/>,
      }
    },
    styleOverrides: {
    ...
    }
Run Code Online (Sandbox Code Playgroud)

但是,有没有一种方法可以对定义OnClose属性时显示的关闭图标执行相同的操作?

  /**
   * Callback fired when the component requests to be closed.
   * When provided and no `action` prop is set, a close icon button is displayed that triggers the callback when clicked.
   * @param {React.SyntheticEvent} event The event source of the callback.
   */
  onClose?: (event: React.SyntheticEvent) => void;
Run Code Online (Sandbox Code Playgroud)

我知道替代解决方案是创建从警报组件派生的我自己的样式组件并设置我的自定义关闭图标,但希望避免这种情况并看看是否可以通过主题组件自定义来实现。

否则我认为这是一个很好的选择,也许应该提出一个请求。

customization reactjs material-ui

8
推荐指数
1
解决办法
3974
查看次数

标签 统计

customization ×1

material-ui ×1

reactjs ×1