-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move the icon-service to separate file
- Loading branch information
Showing
2 changed files
with
24 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Convert the CSS class name of mdi icons to the JS name | ||
function mdiIconName(str) { | ||
// https://github.com/Templarian/MaterialDesign-JS/blob/master/build.js#L5 | ||
let name = str.replace(/(-\w)/g, (matches) => matches[1].toUpperCase()); | ||
name = `${name[0].toUpperCase()}${name.slice(1)}`; | ||
return `mdi${name}`; | ||
} | ||
|
||
let mdi; // mdi iconSet | ||
export async function createMDIIcon(iconName, iconSize) { | ||
if (!mdi) { | ||
mdi = await import('@mdi/js') | ||
} | ||
const iconData = mdi[mdiIconName(iconName)]; | ||
const icon = document.createElement("div"); | ||
icon.style.verticalAlign = "bottom" | ||
icon.innerHTML = ` | ||
<svg style='width:${iconSize}px; height:${iconSize}px' viewBox='0 0 24 24'> | ||
<path fill='currentColor', d='${iconData}'/> | ||
<svg/> | ||
` | ||
return icon | ||
} |
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