Created
February 25, 2021 14:50
-
-
Save davidecampello/c3ac37c20e402d1843b69e7b3566adbf to your computer and use it in GitHub Desktop.
ionic-icon-extractor and directive
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
| export async function http<T>(request: RequestInfo): Promise<T> { | |
| const response = await fetch(request); | |
| const body = await response.json(); | |
| return body; | |
| } | |
| async function get() { | |
| console.log("get"); | |
| const icons = await http<{ | |
| icons: { | |
| name: string; | |
| }[]; | |
| }>( | |
| "https://raw.githubusercontent.com/ionic-team/ionicons/master/src/data.json" | |
| ); | |
| console.log(icons); | |
| const set = new Set<string>(); | |
| icons.icons.forEach(i => { | |
| set.add(i.name.replace("-outline", "").replace("-sharp", "")); | |
| }); | |
| console.log([...Array.from(set)].map(s => `'${s}'`).join(" | \n")); | |
| } | |
| get(); | |
| /* | |
| export type IonIconName = | |
| 'accessibility' | | |
| 'add' | | |
| ...... | |
| ; | |
| @Directive({ | |
| selector: '[iconAdaptive]' | |
| }) | |
| export class IonIconAdaptiveDirective implements OnInit { | |
| private iconName: IonIconName; | |
| @Input() set iconAdaptive(name: IonIconName) { | |
| this.iconName = name; | |
| this.setIcon(); | |
| } | |
| constructor(@Host() private baseComponent: IonIcon) { | |
| } | |
| ngOnInit(): void { | |
| this.setIcon(); | |
| } | |
| private setIcon() { | |
| this.baseComponent.ios = `${this.iconName}-outline`; | |
| this.baseComponent.md = `${this.iconName}-sharp`; | |
| } | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment