@umbraco-ui/uui-icon-registry 1.2.0 → 1.3.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +50 -0
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -28,18 +28,31 @@ class UUIIconRegistry {
|
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Attach an element to provide this registry. Use detach when disconnected.
|
|
33
|
+
* @param {EventTarget} element the element of which to provide this icon-set.
|
|
34
|
+
*/
|
|
31
35
|
attach(element) {
|
|
32
36
|
element.addEventListener(
|
|
33
37
|
UUIIconRequestEvent.ICON_REQUEST,
|
|
34
38
|
this._onIconRequest
|
|
35
39
|
);
|
|
36
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Detach an element from providing this registry.
|
|
43
|
+
* @param {EventTarget} element the element of which to stop providing this icon-set.
|
|
44
|
+
*/
|
|
37
45
|
detach(element) {
|
|
38
46
|
element.removeEventListener(
|
|
39
47
|
UUIIconRequestEvent.ICON_REQUEST,
|
|
40
48
|
this._onIconRequest
|
|
41
49
|
);
|
|
42
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Define a icon to be served by this registry.
|
|
53
|
+
* @param {string} iconName the name to use for this icon.
|
|
54
|
+
* @param {string} svgString the svg source for this icon.
|
|
55
|
+
*/
|
|
43
56
|
defineIcon(iconName, svgString) {
|
|
44
57
|
if (this.icons[iconName]) {
|
|
45
58
|
this.icons[iconName].svg = svgString;
|
|
@@ -47,18 +60,55 @@ class UUIIconRegistry {
|
|
|
47
60
|
}
|
|
48
61
|
this.icons[iconName] = new UUIIconHost(svgString);
|
|
49
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Retrieve the SVG source of an icon, Returns ´null´ if the name does not exist.
|
|
65
|
+
* @param {string} iconName the name of the icon to retrieve.
|
|
66
|
+
*/
|
|
50
67
|
getIcon(iconName) {
|
|
51
68
|
if (!!this.icons[iconName] || this.acceptIcon(iconName)) {
|
|
52
69
|
return this.icons[iconName].promise;
|
|
53
70
|
}
|
|
54
71
|
return null;
|
|
55
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Declare that this registry will be providing a icon for this name
|
|
75
|
+
* @param {string} iconName the name of the icon to be provided.
|
|
76
|
+
*/
|
|
56
77
|
provideIcon(iconName) {
|
|
57
78
|
return this.icons[iconName] = new UUIIconHost();
|
|
58
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* extend this method to provide your own logic.
|
|
82
|
+
* @param iconName
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
//@ts-ignore-start
|
|
86
|
+
// eslint-disable-next-line
|
|
59
87
|
acceptIcon(iconName) {
|
|
60
88
|
return false;
|
|
61
89
|
}
|
|
90
|
+
//@ts-ignore-end
|
|
91
|
+
/**
|
|
92
|
+
* Dynamic concept by extending this class:
|
|
93
|
+
* extend getIcon in this way:
|
|
94
|
+
|
|
95
|
+
protected acceptIcon(iconName: string): boolean {
|
|
96
|
+
|
|
97
|
+
// Check if this is something we want to accept and provide.
|
|
98
|
+
if(iconName === "myCustomIcon") {
|
|
99
|
+
|
|
100
|
+
// Inform that we will be providing this.
|
|
101
|
+
const icon = this.provideIcon(iconName);
|
|
102
|
+
|
|
103
|
+
// When data is available set it on this icon object, this can be done at any point in time:
|
|
104
|
+
icon.svg = "...";
|
|
105
|
+
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
*/
|
|
62
112
|
getIconNames() {
|
|
63
113
|
return Object.keys(this.icons);
|
|
64
114
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umbraco-ui/uui-icon-registry",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Umbraco",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"custom-elements.json"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@umbraco-ui/uui-base": "1.
|
|
34
|
-
"@umbraco-ui/uui-icon": "1.
|
|
33
|
+
"@umbraco-ui/uui-base": "1.3.0-rc.0",
|
|
34
|
+
"@umbraco-ui/uui-icon": "1.3.0-rc.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js",
|
|
38
|
-
"clean": "tsc --build --clean && rimraf dist lib/*.js lib/**/*.js custom-elements.json",
|
|
38
|
+
"clean": "tsc --build --clean && rimraf -g dist lib/*.js lib/**/*.js custom-elements.json",
|
|
39
39
|
"analyze": "web-component-analyzer **/*.element.ts --outFile custom-elements.json"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"homepage": "https://uui.umbraco.com/?path=/story/uui-icon-registry",
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "45c3824056586d9817efb3f61dc0bef5478747f0"
|
|
46
46
|
}
|