1
1
import { merge } from 'lodash-es'
2
2
3
3
/**
4
- * @param {String } pack
5
- * @param {Array } icon
4
+ * @param {String } prefix - prefix for the icon pack
5
+ * @param {Array } icon - icon definition
6
6
* @returns {{path: string, viewBox: string, attrs: *} }
7
7
*/
8
- const createIcon = ( pack , icon ) => {
8
+ const createIcon = ( prefix , icon ) => {
9
9
const [ w , h , content , svg , data , , attrs ] = icon
10
10
let path
11
11
@@ -21,12 +21,12 @@ const createIcon = (pack, icon) => {
21
21
return `<g fill="currentColor" class="${ prefix } -group">${ paths . join ( '' ) } </g>`
22
22
}
23
23
24
- if ( pack === 'fa' ) {
24
+ if ( prefix . startsWith ( 'fa' ) ) {
25
25
path = Array . isArray ( data )
26
- ? createGroupedPath ( data , pack )
26
+ ? createGroupedPath ( data , prefix . substr ( 0 , 2 ) )
27
27
: createPath ( data )
28
28
} else {
29
- path = pack . startsWith ( 'fe' ) ? content : svg
29
+ path = prefix . startsWith ( 'fe' ) ? content : svg
30
30
}
31
31
32
32
return {
@@ -38,17 +38,16 @@ const createIcon = (pack, icon) => {
38
38
39
39
/**
40
40
* @description Custom parse all Icons provided by user
41
- * @param {String } pack - the name of the icon pack being used (fe, fa, mdi, etc)
42
41
* @param {Object } iconSet - Registered Icons object
43
42
* @returns {Object }
44
43
*/
45
- const parseIcons = ( pack , iconSet = { } ) => {
44
+ const parseIcons = ( iconSet = { } ) => {
46
45
const parseIcon = ( iconObject ) => {
47
- const { icon, iconName } = iconObject
46
+ const { icon, prefix , iconName } = iconObject
48
47
// Is library icon
49
48
if ( icon ) {
50
49
return {
51
- [ `${ iconName } ` ] : createIcon ( pack , icon )
50
+ [ `${ iconName } ` ] : createIcon ( prefix , icon )
52
51
}
53
52
} else {
54
53
return { }
@@ -62,13 +61,12 @@ const parseIcons = (pack, iconSet = {}) => {
62
61
63
62
/**
64
63
* @description Parse Icon packs
65
- * @param {String } pack - the name of the icon pack being used (fe, fa, mdi, etc)
66
64
* @param {Object } iconSet Registered Icon set
67
65
* @returns {Object } Parsed pack icons object
68
66
*/
69
- export const parsePackIcons = ( pack , iconSet ) => {
67
+ export const parsePackIcons = ( iconSet ) => {
70
68
// TODO: Add support for other icon libraries
71
69
// - Material Icons: these are string constants, and need lots of work
72
70
// - Tailwind Icons (Hero icons)
73
- return parseIcons ( pack , iconSet )
71
+ return parseIcons ( iconSet )
74
72
}
0 commit comments