Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to scale (large) font-awesome icons from the react-icons package

Tags:

I am using the marvelouse react-icons package (http://gorangajic.github.io/react-icons/fa.html), specifically the font awesome package.

If this was not react, then I would just add an attribute to the tag, such as:

<i class="fa fa-camera-retro fa-5x"></i>  

However, if I add the fa-5x to the FaFolderOpen tag, it does not do anything. As you can see, I am using react-bootstrap, and placing the icon a button (should it be a block)?

I have to believe this has been asked before, but I did not find it via search.

Here is what it looks like, and I want it larger:

enter image description here

const React = require('react') import { Form, FormControl, FormGroup, ControlLabel, Col, Button, Tooltip, OverlayTrigger } from 'react-bootstrap' import FaFolderOpen from 'react-icons/lib/fa/folder-open' import FaFileCodeO from 'react-icons/lib/fa/file-code-o' import FaFolderOpen from 'react-icons/lib/fa/folder-open' import FaFileCodeO from 'react-icons/lib/fa/file-code-o'  <Button type="button" bsStyle="success" block onClick={(e) => folderChooser(e)}>      <FaFolderOpen /> </Button> 
like image 395
Dr.YSG Avatar asked May 03 '17 19:05

Dr.YSG


People also ask

How do I resize font awesome icons?

To increase icon sizes relative to their container, use the fa-lg (33% increase), fa-2x , fa-3x , fa-4x , or fa-5x classes. If your icons are getting chopped off on top and bottom, make sure you have sufficient line-height.

How do I increase icon size in react icons?

To increase icon sizes relative to their container, use size prop with xs , sm , lg (33% increase), or use literal sizes (to scale it from 1x to 10x) 2x , 3x , 4x , 5x , 6x , 7x , 8x , 9x , 10x . You can make all your icons the same width so they can easily vertically align, like in a list or navigation menu.


2 Answers

if you want a 5x icon size you need to pass it to the react class as size

// Font awesome pixel sizes relative to the multiplier.  // 1x - 14px // 2x - 28px // 3x - 42px // 4x - 56px // 5x - 70px  <FaFolderOpen size={70} /> 

if you notice it jumps by 14 each time

from the github readme it shows everything is overridden inline. its rendering a svg so you cant use 5x you have to use a pixel size

Edit

Coming back to this a few years later, with newer versions of FontAwesome/ReactIcons the recommended way to handle different sizings is with their icon provider that utilizes the React Context API. This requires React v16.3+

import { IconContext } from "react-icons";  <IconContext.Provider value={{ className: "shared-class", size: 70 }}>   <>     <FaFolder />     <FaBeer />   </> </IconContext.Provider> 
like image 137
John Ruddell Avatar answered Oct 20 '22 19:10

John Ruddell


In reactjs you can use size = 'with your preferred size which be from sm to lg or 1x to 10x'

this is example for font awesome 5 in react

<FontAwesomeIcon icon={faBars} size = '10x'/> 
like image 25
solomon njobvu Avatar answered Oct 20 '22 20:10

solomon njobvu