mirror of
https://github.com/ionic-team/ionicons.git
synced 2026-11-30 16:48:16 +01:00
fix(map): global map
This commit is contained in:
Vendored
-2
@@ -25,7 +25,6 @@ export namespace Components {
|
||||
* A combination of both `name` and `src`. If a `src` url is detected it will set the `src` property. Otherwise it assumes it's a built-in named SVG and set the `name` property.
|
||||
*/
|
||||
'icon'?: string;
|
||||
'iconMap'?: {[name: string]: string};
|
||||
/**
|
||||
* Specifies which icon to use on `ios` mode.
|
||||
*/
|
||||
@@ -68,7 +67,6 @@ export namespace Components {
|
||||
* A combination of both `name` and `src`. If a `src` url is detected it will set the `src` property. Otherwise it assumes it's a built-in named SVG and set the `name` property.
|
||||
*/
|
||||
'icon'?: string;
|
||||
'iconMap'?: {[name: string]: string};
|
||||
/**
|
||||
* Specifies which icon to use on `ios` mode.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Component, Element, Prop, State, Watch } from '@stencil/core';
|
||||
import { getName, getSrc, isValid } from './utils';
|
||||
import { getIconMap, getName, getSrc, isValid } from './utils';
|
||||
|
||||
@Component({
|
||||
tag: 'ion-icon',
|
||||
@@ -20,9 +20,6 @@ export class Icon {
|
||||
@Prop({ context: 'document' }) doc!: Document;
|
||||
@Prop({ context: 'window' }) win: any;
|
||||
|
||||
/** @internal */
|
||||
@Prop() iconMap?: {[name: string]: string};
|
||||
|
||||
/**
|
||||
* The color to use for the background of the item.
|
||||
*/
|
||||
@@ -167,8 +164,9 @@ export class Icon {
|
||||
}
|
||||
|
||||
private getNamedUrl(name: string) {
|
||||
if (this.iconMap) {
|
||||
return this.iconMap[name];
|
||||
const url = getIconMap().get(name);
|
||||
if (url) {
|
||||
return url;
|
||||
}
|
||||
return `${this.resourcesUrl}svg/${name}.svg`;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,22 @@
|
||||
|
||||
let CACHED_MAP: Map<string, string>;
|
||||
|
||||
export function getIconMap(): Map<string, string> {
|
||||
if (!CACHED_MAP) {
|
||||
const win = window as any;
|
||||
win.Ionicons = win.Ionicons || {};
|
||||
CACHED_MAP = win.Ionicons.map = win.Ionicons.map || new Map();
|
||||
}
|
||||
return CACHED_MAP;
|
||||
}
|
||||
|
||||
export function addIcons(icons: {[name: string]: string }) {
|
||||
const map = getIconMap();
|
||||
Object.keys(icons).forEach(name => {
|
||||
map.set(name, icons[name]);
|
||||
});
|
||||
}
|
||||
|
||||
export function getName(
|
||||
name: string | undefined,
|
||||
mode: string | undefined,
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
export { addIcons } from './icon/utils';
|
||||
Reference in New Issue
Block a user