[英]Material-UI Fill Icon
I am adding the icon button in form of the start from and I want to fill it on click with solid color. 我以开始的形式添加图标按钮,我想在单击时用纯色填充它。
import StarIcon from '@material-ui/icons/StarBorder'
...
<IconButton><StarIcon className={classes.favoricon}/></IconButton>
I had a look at icon implementation, could not find a class that would control it (check code here ). 我看了一下图标的实现,找不到一个可以控制它的类( 在此处检查代码)。 I could create a separate svg, but maybe there is a better option
我可以创建一个单独的svg,但也许有更好的选择
I am not sure if there is a better way. 我不确定是否有更好的方法。
Create a state
on the component and modify the state whenever the Component is clicked. 在组件上创建一个
state
,并在单击该组件时修改该状态。
Use onClick
function to toggle the state which changes the Component from StarIcon
to Star
and vice-versa. 使用
onClick
功能可切换将组件从StarIcon
更改为Star
的状态,反之亦然。
handleChange = () => { const value = this.state.value; this.setState((prev) => ({value: !prev.value})); };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.