React Fluent UI - 更改复选框选中标记和标签的颜色

发布于 2025-01-14 12:11:22 字数 812 浏览 5 评论 0原文

我有一个使用 Fluent UI 的 React 应用程序。我正在使用 组件,但它具有默认颜色和行为。像这样:

“在此处输入图像描述”

我想更改选中标记和标签的颜色(绿色选中标记和棕色标签)。我尝试了以下方法来执行此操作,但没有成功。

const checkBoxStyles = {
  root: {
    color: 'brown'
  },
  checkbox: {
    color:'green'
  }
}
  return (
    <Stack tokens={stackTokens}>
      <Checkbox
        styles={checkBoxStyles}
        label="Controlled checkbox"
        checked={isChecked}
        onChange={onChange}
      />
    </Stack>
  );
};

codepen 上的完整工作代码 - https://codepen.io/AnkitSaxena2605/pen/eYyppLj

I've a react app using Fluent UI. I'm using <Checkbox/> component but it's having it's default colors and behavious. Like this:

enter image description here

I want to change the color of the checked mark and also the label (Green checked mark and brown lable). I tried the below way to do so but it didn't work.

const checkBoxStyles = {
  root: {
    color: 'brown'
  },
  checkbox: {
    color:'green'
  }
}
  return (
    <Stack tokens={stackTokens}>
      <Checkbox
        styles={checkBoxStyles}
        label="Controlled checkbox"
        checked={isChecked}
        onChange={onChange}
      />
    </Stack>
  );
};

Full working code at codepen - https://codepen.io/AnkitSaxena2605/pen/eYyppLj

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思碎 2025-01-21 12:11:22

尝试在 checkBoxStyles 中进行以下更改:

 const checkBoxStyles = {
    checkmark: {
      background: 'green',
      color: 'white'
    },
    checkbox: {
      background: 'white',
      borderColor: 'black'
    },
    text: {
      fontWeight: "bold",
      color:'brown'
    }
  };

checkboxcheckmark 用于设置复选框样式,text 用于设置复选框样式设计标签的样式。

Try to do the following changes in your checkBoxStyles:

 const checkBoxStyles = {
    checkmark: {
      background: 'green',
      color: 'white'
    },
    checkbox: {
      background: 'white',
      borderColor: 'black'
    },
    text: {
      fontWeight: "bold",
      color:'brown'
    }
  };

checkbox and checkmark are for styling the checkbox and text is for styling the label.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文