Created
April 16, 2020 16:16
-
-
Save dstaley41/495dca87a04d168519a57c93a040c86e to your computer and use it in GitHub Desktop.
Bootstrap Icon w/ Svelte
This file contains hidden or 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
| <script> | |
| /*** | |
| * This is super hackish, but way easier than pasting these fkn | |
| * things everywhere in the codebase... run on icons.bootstrap.com in | |
| * console to get new map like so: | |
| function dumpIcons(){ | |
| var icons = $$("svg.bi"); | |
| var pathMap = {}; | |
| icons.forEach((svg) => { | |
| var id = svg.className.baseVal.replace('bi bi-', ''); | |
| // get rid of some of the formatting like new line/tab | |
| pathMap[id] = svg.innerHTML.replace(/\r\n\t/g, '').trim(); | |
| }); | |
| return pathMap; | |
| } | |
| var svgs = dumpIcons(); | |
| copy(svgs); //copy to clipboard | |
| paste results to iconMap var below | |
| Usage: | |
| <BootstrapIcon icon="alarm" [width="1em" height="1em"] /> | |
| ouput: | |
| <svg class="bi bi-alarm" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"> | |
| <path fill-rule="evenodd" d="M8 15A6 6 0 108 3a6 6 0 000 12zm0 1A7 7 0 108 2a7 7 0 000 14z" clip-rule="evenodd"/> | |
| <path fill-rule="evenodd" d="M8 4.5a.5.5 0 01.5.5v4a.5.5 0 01-.053.224l-1.5 3a.5.5 0 11-.894-.448L7.5 8.882V5a.5.5 0 01.5-.5z" clip-rule="evenodd"/> | |
| <path d="M.86 5.387A2.5 2.5 0 114.387 1.86 8.035 8.035 0 00.86 5.387zM11.613 1.86a2.5 2.5 0 113.527 3.527 8.035 8.035 0 00-3.527-3.527z"/> | |
| <path fill-rule="evenodd" d="M11.646 14.146a.5.5 0 01.708 0l1 1a.5.5 0 01-.708.708l-1-1a.5.5 0 010-.708zm-7.292 0a.5.5 0 00-.708 0l-1 1a.5.5 0 00.708.708l1-1a.5.5 0 000-.708zM5.5.5A.5.5 0 016 0h4a.5.5 0 010 1H6a.5.5 0 01-.5-.5z" clip-rule="evenodd"/> | |
| <path d="M7 1h2v2H7V1z"/> | |
| </svg> | |
| */ | |
| export let icon; | |
| export let width = '1em'; | |
| export let height = '1em'; | |
| // needs to be populated as described above | |
| let iconMap = {}; | |
| </script> | |
| {#if iconMap.hasOwnProperty(icon)} | |
| <svg class="bi bi-{icon}" {width} {height} viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"> | |
| {@html iconMap[icon]} | |
| </svg> | |
| {/if} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment