Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit d7dcdae

Browse files
authored
fix: support multiple paths in icons
FontAwesome duotone icons require multiple path elements, as well as className defs, and a default style def for the opacity of fa-secondary.
1 parent 81291cf commit d7dcdae

File tree

1 file changed

+19
-1
lines changed
  • packages/chakra-ui-core/src/utils

1 file changed

+19
-1
lines changed

packages/chakra-ui-core/src/utils/icons.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
import { merge } from 'lodash-es'
22

3+
/**
4+
* @description Parse FontAwesome icon path
5+
* @param {String|Array} path a single svg path, or array of paths
6+
* @returns {String}
7+
*/
8+
const parseFontAwesomeIcon = (path) => {
9+
// duotone icon
10+
if (Array.isArray(path) && path.length === 2) {
11+
const paths = path.map((d, idx) =>
12+
`<path d="${d}" fill="currentColor" class="${idx ? 'fa-primary' : 'fa-secondary'}" />`
13+
)
14+
15+
return `<defs><style>.fa-secondary{opacity:.4}</style></defs><g class="fa-group">${paths.join('')}</g>`
16+
}
17+
18+
return `<path d="${path}" fill="currentColor" />`
19+
}
20+
321
/**
422
* @description Custom parse all Icons provided by user
523
* @param {Object} iconSet - Registered Icons object
@@ -14,7 +32,7 @@ const parseIcons = (iconSet = {}) => {
1432
return {
1533
[`${iconObject.iconName}`]: {
1634
path: iconObject.prefix.startsWith('fa')
17-
? `<path d="${path}" fill="currentColor" />`
35+
? parseFontAwesomeIcon(path)
1836
: iconObject.prefix.startsWith('fe')
1937
? content
2038
: svg,

0 commit comments

Comments
 (0)