如何用MUI制作圆形复选框? [英] How to make a circle checkbox with MUI?

查看:75
本文介绍了如何用MUI制作圆形复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要尝试匹配的设计要求复选框为圆形。我正在将MUI与Reaction一起使用。

边框半径不起作用,因为实际图标的边框不是"可见"复选框的边框。

我不能只使用像Font Awesom这样的内容,因为它实际上需要选中和取消选中。

// Current Styling
const styles = theme => ({
  nested: {
    paddingLeft: theme.spacing.unit * 4,
  },
  icon: {
    margin: theme.spacing.unit,
    fontSize: 25,
  },
  root: {
    color: cyan['A400'],
    '&$checked': {
      color: cyan['A400'],
    },
  },
  checked: {},
});

// Actual checkbox code
return (
  // Holds the individual step with edit icon and delete icon
  <>
    <ListItemIcon>
      {/* Checkbox */}
      <Checkbox
        type="checkbox"
        defaultChecked={step.completed} 
        onChange={this.onChange}
        value="true"
        classes={{
          root: classes.root,
          checked: classes.checked,
        }}
      />
    </ListItemIcon>

我希望保留MUICheckbox的工作代码,但只需更改一些样式,使边缘成为完美的圆形(类似于单选按钮,但中间带有复选标记)。

推荐答案

材料的Checkboxsupports custom icons。有圆形checked circle Material icons,对于空的圆可以稍微作弊一下,Radio输入使用图标(大小一样,效果很好):

import Checkbox from '@material-ui/core/Checkbox';
import CircleChecked from '@material-ui/icons/CheckCircleOutline';
import CircleCheckedFilled from '@material-ui/icons/CheckCircle';
import CircleUnchecked from '@material-ui/icons/RadioButtonUnchecked';

…

<Checkbox
  icon={<CircleUnchecked />}
  checkedIcon={<CircleChecked />}
  …
/>

// or with filled checked icon:

<Checkbox
  icon={<CircleUnchecked />}
  checkedIcon={<CircleCheckedFilled />}
  …
/>

…看起来是这样的(fooisCheckCircleOutlinebarisCheckCircle):

这篇关于如何用MUI制作圆形复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆