简体   繁体   English

如何更改复选框材料表ReactJS的颜色

[英]How to change color of checkbox material table ReactJS

I am using Material table in my project and want to change color of checkbox on selection我在我的项目中使用材料表,并希望在选择时更改复选框的颜色在此处输入图片说明 . . How to do that??怎么做??

function BasicSelection() {
  return (
    <MaterialTable
      title="Basic Selection Preview"
      columns={[
        { title: 'Name', field: 'name' },
        { title: 'Surname', field: 'surname' },
        { title: 'Birth Year', field: 'birthYear', type: 'numeric' },
        {
          title: 'Birth Place',
          field: 'birthCity',
          lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
        },
      ]}
      data={[
        { name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 },
        { name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 },
      ]}        
      options={{
        selection: true
      }}
    />
  )
}

I think if you want to change that color, chances are high you are using that color else where in your components.我认为如果您想更改该颜色,那么您很有可能在组件中的其他位置使用该颜色。 Probably think about theming the table to match the app look.可能会考虑将表格主题化以匹配应用程序外观。 Material Table provides a theming snipped that you can use to override the default secondary.main color applied to the checkbox. Material Table 提供了一个主题片段,您可以使用它来覆盖应用于复选框的默认secondary.main颜色。

Styling with MuiThemeProvider Example使用 MuiThemeProvider 示例进行样式设置

function StylingWithMuiThemeProvider() {
  const theme = createMuiTheme({
    palette: {
      primary: {
        main: '#4caf50',
      },
      secondary: {
        main: '#ff0000',
      },
    },

  });

  return (
    <MuiThemeProvider theme={theme}>

    <MaterialTable
      title="Basic Selection Preview"
      columns={[
        { title: 'Name', field: 'name' },
        { title: 'Surname', field: 'surname' },
        { title: 'Birth Year', field: 'birthYear', type: 'numeric' },
        {
          title: 'Birth Place',
          field: 'birthCity',
          lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
        },
      ]}
      data={[
        { name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 },
        { name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 },
      ]}        
      options={{
        selection: true
      }}
    />
    </MuiThemeProvider>
  )
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM