css - Material UI - 为 SVG 设置颜色
问题描述
我在 ReactJS 中使用 Material UI,并使用以下组件来渲染 SVG:
import React, { FunctionComponent } from "react";
import SvgIconMUI from "@material-ui/core/SvgIcon";
import { SvgIconProps } from "./types";
import { ReactComponent as HelloWorld } from "Icon/Sections/icon-flat.svg";
const SvgIcon: FunctionComponent<SvgIconProps> = ({
slug,
classes,
svgIconViewBox = "0 0 96 96",
}) => {
const SpecificSpartenIcon = HelloWorld;
return (
SpecificSpartenIcon && (
<div className={classes.svgContainer}>
<SvgIconMUI viewBox={svgIconViewBox} className={classes.svgIcon}>
<SpecificSpartenIcon />
</SvgIconMUI>
</div>
)
);
};
export default SvgIcon;
我想要实现的目标:为 SVG 设置另一种颜色。
我试图改变颜色:
import { makeStyles, Theme } from "@material-ui/core";
interface Props {
colors: ExpertColor;
}
const svgIconViewBox = "0 0 96 96";
const selectedIconStyles = { fontSize: 30 };
const useStyles = makeStyles<Theme, Props>((theme: Theme) => ({
svgContainer: {
display: "flex",
justifyContent: "center",
position: "relative",
height: "100%",
width: "100%",
padding: 0,
fill: "red !important;",
color: "red !important;",
},
svgIcon: {
position: "absolute",
height: "55px",
width: "55px",
top: 0,
fill: "red !important;",
color: "red !important;",
},
}));
export default { useStyles, svgIconViewBox, selectedIconStyles };
这没用。你有想法吗 ?
解决方案
推荐阅读
- ios - 您可以定义应用内购买并在不使用的情况下提交应用以供审核吗?
- javascript - MutationObserver 使用的一些实际例子是什么?
- amazon-web-services - 配置 confluence 调用 postfix setup 发送邮件
- google-chrome-extension - 如何使用 DevTools 或其他调试器调试 chrome 扩展?
- python-3.x - Docker 和 Plotly
- mongodb - MongoDB $group 操作 - 内存使用优化
- angular - 更改 firebase-messaging-sw.js 位置
- python - 如何将我的 django 路径设置为 http://127.0.0.1:8000/myproject/admin
- erlang - mnesia:read 在 mnesia 中使用表碎片时返回空,但有记录
- scala - 在播放控制器中注入模拟服务对象的依赖项,同时对其进行单元测试