react-icons - Can't change color Grommet icons

3.9k Views Asked by At

I'm using react-icons and with Font Awesome icons I managed to change color easily with 2 approaches:

Works with color prop:

<FaUserTimes /* color="#023373" */ className="icone icone-40" />

Works with css:

.icone {
  color: #023373; 
}

Now, using Grommet icons nothing seems to work, icons are always black

<GrFormAdd color="#023373" className="icones" />

.icones {
    font-size: 30px; **Font size works!?**
    color: #023373;
}

enter image description here

2

There are 2 best solutions below

1
On BEST ANSWER

Full Code : https://codesandbox.io/s/pensive-rgb-r8g1t?file=/src/App.js

For color pass a props (i called it blue) like this.

<Apple color="blue" size="xlarge" />

So on the other end style your icon like this.

const customColorTheme = deepMerge(base, {
    icon: {
      extend: css`
        ${(props) =>
          props.color === "blue" &&
          `
        fill: #023373;
      `}
      `
    }
  });
1
On

If you don't want to use the 'grommet-icons' dependency, but only 'react-icons' :

you can style them with simple css :

svg path {
    stroke: #023373;
}