-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added custom Vuetify icons import functionality
- Loading branch information
Showing
2 changed files
with
65 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import ObjectUtil from './Object.js'; | ||
|
||
/** | ||
* Icon related utility methods. | ||
*/ | ||
const IconUtil = { | ||
|
||
/** | ||
* Import custom icons from 'app/icons'. Those icons will be included in an | ||
* object ready to be injected inside Vuetify configuration options object under | ||
* the icons['values'] property. | ||
* | ||
* @returns {Object} An object containing the imported icons. | ||
* Key is the icon name, value contains the icon. | ||
*/ | ||
importIcons () { | ||
const icons = {}; | ||
|
||
try { | ||
const pathIcons = IconUtil.importPathIcons(); | ||
ObjectUtil.mergeDeep(icons, pathIcons); | ||
} catch (e) { | ||
} | ||
|
||
return icons; | ||
}, | ||
|
||
/** | ||
* Import custom icons from 'app/icons/*.js'. Those icons will be included in an | ||
* object ready to be injected inside Vuetify configuration options object under | ||
* the icons['values'] property. | ||
* The icons must be .js files with a default export which contains an SVG path. | ||
* | ||
* @returns {Object} An object containing icon SVG paths. | ||
* Key is the icon name, value contains the path. | ||
*/ | ||
importPathIcons () { | ||
const moduleDefaultExtractor = (i) => i.default; | ||
const testExp = /icons\/(?:.+\/)*([a-z0-9_-]+).js$/i; | ||
|
||
const context = require.context( | ||
'../../app', | ||
true, | ||
/icons\/(?:(?:.+)\/)*([a-z0-9_-]+).js$/i | ||
); | ||
const pathIcons = {}; | ||
for (const key of context.keys()) { | ||
const iconName = key.match(testExp)[1]; | ||
pathIcons[iconName] = moduleDefaultExtractor(context(key)); | ||
} | ||
|
||
return pathIcons; | ||
} | ||
} | ||
|
||
export default IconUtil; |