Procedure for using a third party icon library according to documentation not possible with TypeScript and Font Awesome #5649
Replies: 8 comments 3 replies
-
The linked codesandbox looks empty, could you kindly check? |
Beta Was this translation helpful? Give feedback.
-
Here is a new link, it can be viewed there now. |
Beta Was this translation helpful? Give feedback.
-
Kindly see the docs how to use react-icons with Chakra UI. I am not familiar with the package "@fortawesome/free-solid-svg-icons", but it looks like the imported |
Beta Was this translation helpful? Give feedback.
-
Probably not the best or optimal code but what I do for FontAwesome is: // config/fontAwesome
import { library } from '@fortawesome/fontawesome-svg-core'
import { fab } from '@fortawesome/free-brands-svg-icons'
import { far } from '@fortawesome/free-regular-svg-icons'
import { fas } from '@fortawesome/free-solid-svg-icons'
library.add(
fab,
far,
fas
) // Component FIle
import {
Box,
useColorModeValue
} from '@chakra-ui/react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import '../config/fontAwesome'
...
export default function Component() {
return (
<Box
color={useColorModeValue('LIGHTMODECOLOUR', 'DARKMODECOLOUR')} // To make it dark mode compatible/Change the colour of the icon
fontSize="1.5rem" // Control the size of the icon
>
<FontAwesomeIcon icon={['{TYPE}', '{ICONNAME}']} width="100%" />
</Box>
)
} |
Beta Was this translation helpful? Give feedback.
-
In case anyone still needs this - @DonaldLouch has a great solution but it doesn't work when trying to use a Font Awesome icon with the <ListIcon as={<FontAwesomeIcon icon={faCircleSmall} />} /> <ListIcon as={faCircleSmall} /> However, you can use the const convertIcon = faIcon => {
const { icon, iconName } = faIcon;
return createIcon({
displayName: iconName,
viewBox: `0 0 ${icon[0]} ${icon[1]}`,
d: icon[4],
});
}; and then implement it <ListIcon as={convertIcon(faCircleSmall)} /> |
Beta Was this translation helpful? Give feedback.
-
What I did and what requires almost no configuration is the wrap import { chakra } from '@chakra-ui/react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faBars } from '@fortawesome/pro-solid-svg-icons';
export const myAwesomeComponent = () => {
const Icon = chakra(FontAwesomeIcon);
return (
<Icon icon={faBars} marginRight={5} />
)
} |
Beta Was this translation helpful? Give feedback.
-
A couple helpers I find useful:
|
Beta Was this translation helpful? Give feedback.
-
Just adding a note based on some of the other answers. Using the Some examples here: CodeSandbox |
Beta Was this translation helpful? Give feedback.
-
Description
When using a third party icon library (FontAwesome) in the "as" of the Chakra UI icon component, a type error occurs
Link to Reproduction
https://codesandbox.io/s/modest-leaf-qlk5kd?file=/src/index.tsx
Steps to reproduce
Chakra UI Version
1.8.5
Browser
Microsoft Edge 98.0.1108.56
Operating System
Additional Information
No response
Beta Was this translation helpful? Give feedback.
All reactions