Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Style React-Icons

I am trying to figure out how to style icons that I import using react-icons.

In particular, I would like to be able to create a look similar to this: enter image description here

That is to say, I'd like to add a background color, padding, border-radius, etc. However, I can't find an easy way to do that.

I can add a size and color prop and that will change the actual size and color of the icon. But there is no easy way for me to change the other elements.

Does anyone know how I can do this (or can they recommend a different library that can help me with this)?

like image 359
Moshe Avatar asked Jun 17 '19 17:06

Moshe


2 Answers

Use IconContext as mentioned in the Docs.

function BlueLargeIcon() {
  return (
    <IconContext.Provider
      value={{ color: 'blue', size: '50px' }}
    >
      <div>
        <FaBeer />
      </div>
    </IconContext.Provider>
  );
}

enter image description here

To target specific Icon Components, you can use the style prop or use the same API (see Configurations) on the component itself:

const style = { color: "white", fontSize: "1.5em" }
<FaFacebookF style={style} />

// API
<FaFacebookF color="white" fontSize="1.5em" />
like image 53
Dennis Vash Avatar answered Nov 09 '22 18:11

Dennis Vash


To whoever this may be helpful...

Colours of some icons cant be changed.
For example, I tried to change the colour of { GrClose } icon by doing

<GrClose
    className="icon"
    style={{
      position: 'absolute',
      top: '20px',
      right: '20px',
    }}
    size="50px"
    color="white"
    onClick={handleExit}
/>

It just didn't change, when I replaced my icon with { AiOutlineClose } icon it worked!

like image 19
Uttkarsh Patel Avatar answered Nov 09 '22 20:11

Uttkarsh Patel