@momentum-design/components 0.16.0 → 0.16.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/browser/index.js +27 -25
- package/dist/browser/index.js.map +3 -3
- package/dist/components/icon/icon.component.d.ts +18 -0
- package/dist/components/icon/icon.component.js +46 -7
- package/dist/components/presence/presence.component.d.ts +14 -0
- package/dist/components/presence/presence.component.js +28 -2
- package/dist/custom-elements.json +62 -0
- package/package.json +1 -1
@@ -61,6 +61,11 @@ declare class Icon extends Component {
|
|
61
61
|
private readonly iconProviderContext;
|
62
62
|
private abortController;
|
63
63
|
constructor();
|
64
|
+
/**
|
65
|
+
* Dispatches a 'load' event on the component once the icon has been successfully loaded.
|
66
|
+
* This event bubbles and is cancelable.
|
67
|
+
*/
|
68
|
+
private triggerIconLoaded;
|
64
69
|
/**
|
65
70
|
* Get Icon Data function which will fetch the icon (currently only svg)
|
66
71
|
* and sets state and attributes once fetched successfully
|
@@ -70,6 +75,19 @@ declare class Icon extends Component {
|
|
70
75
|
* then attempting to read the response body will reject with an AbortError exception.
|
71
76
|
*/
|
72
77
|
private getIconData;
|
78
|
+
/**
|
79
|
+
* Sets the iconData state to the fetched icon,
|
80
|
+
* and calls functions to set role, aria-label and aria-hidden attributes on the icon.
|
81
|
+
* Dispatches a 'load' event on the component once the icon has been successfully loaded.
|
82
|
+
* @param iconHtml - The icon html element which has been fetched from the icon provider.
|
83
|
+
*/
|
84
|
+
private handleIconLoadedSuccess;
|
85
|
+
/**
|
86
|
+
* Dispatches an 'error' event on the component when the icon fetching has failed.
|
87
|
+
* This event bubbles and is cancelable.
|
88
|
+
* The error detail is set to the error object.
|
89
|
+
*/
|
90
|
+
private handleIconLoadedFailure;
|
73
91
|
/**
|
74
92
|
* Updates the size by setting the width and height
|
75
93
|
*/
|
@@ -66,6 +66,17 @@ class Icon extends Component {
|
|
66
66
|
this.iconProviderContext = providerUtils.consume({ host: this, context: IconProvider.Context });
|
67
67
|
this.abortController = new AbortController(); // Initialize AbortController
|
68
68
|
}
|
69
|
+
/**
|
70
|
+
* Dispatches a 'load' event on the component once the icon has been successfully loaded.
|
71
|
+
* This event bubbles and is cancelable.
|
72
|
+
*/
|
73
|
+
triggerIconLoaded() {
|
74
|
+
const loadEvent = new Event('load', {
|
75
|
+
bubbles: true,
|
76
|
+
cancelable: true,
|
77
|
+
});
|
78
|
+
this.dispatchEvent(loadEvent);
|
79
|
+
}
|
69
80
|
/**
|
70
81
|
* Get Icon Data function which will fetch the icon (currently only svg)
|
71
82
|
* and sets state and attributes once fetched successfully
|
@@ -80,16 +91,44 @@ class Icon extends Component {
|
|
80
91
|
if (url && fileExtension && this.name) {
|
81
92
|
this.abortController.abort();
|
82
93
|
this.abortController = new AbortController();
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
94
|
+
try {
|
95
|
+
const iconHtml = await dynamicSVGImport(url, this.name, fileExtension, this.abortController.signal);
|
96
|
+
this.handleIconLoadedSuccess(iconHtml);
|
97
|
+
}
|
98
|
+
catch (error) {
|
99
|
+
this.handleIconLoadedFailure(error);
|
100
|
+
}
|
90
101
|
}
|
91
102
|
}
|
92
103
|
}
|
104
|
+
/**
|
105
|
+
* Sets the iconData state to the fetched icon,
|
106
|
+
* and calls functions to set role, aria-label and aria-hidden attributes on the icon.
|
107
|
+
* Dispatches a 'load' event on the component once the icon has been successfully loaded.
|
108
|
+
* @param iconHtml - The icon html element which has been fetched from the icon provider.
|
109
|
+
*/
|
110
|
+
handleIconLoadedSuccess(iconHtml) {
|
111
|
+
// update iconData state once fetched:
|
112
|
+
this.iconData = iconHtml;
|
113
|
+
// when icon is fetched successfully, set the role, aria-label and invoke function to trigger icon load event.
|
114
|
+
this.setRoleOnIcon();
|
115
|
+
this.setAriaLabelOnIcon();
|
116
|
+
this.setAriaHiddenOnIcon();
|
117
|
+
this.triggerIconLoaded();
|
118
|
+
}
|
119
|
+
/**
|
120
|
+
* Dispatches an 'error' event on the component when the icon fetching has failed.
|
121
|
+
* This event bubbles and is cancelable.
|
122
|
+
* The error detail is set to the error object.
|
123
|
+
*/
|
124
|
+
handleIconLoadedFailure(error) {
|
125
|
+
const errorEvent = new CustomEvent('error', {
|
126
|
+
bubbles: true,
|
127
|
+
cancelable: true,
|
128
|
+
detail: { error },
|
129
|
+
});
|
130
|
+
this.dispatchEvent(errorEvent);
|
131
|
+
}
|
93
132
|
/**
|
94
133
|
* Updates the size by setting the width and height
|
95
134
|
*/
|
@@ -47,6 +47,11 @@ declare class Presence extends Component {
|
|
47
47
|
* @default small
|
48
48
|
*/
|
49
49
|
size: PresenceSize;
|
50
|
+
/**
|
51
|
+
* @internal
|
52
|
+
* State to track the current icon type (previous type until the new icon is loaded)
|
53
|
+
*/
|
54
|
+
private currentIconType;
|
50
55
|
/**
|
51
56
|
* Get the size of the presence icon based on the given size type
|
52
57
|
*/
|
@@ -55,6 +60,15 @@ declare class Presence extends Component {
|
|
55
60
|
* Get the icon name based on the presence type
|
56
61
|
*/
|
57
62
|
private get icon();
|
63
|
+
/**
|
64
|
+
* Handles the successful load of an icon.
|
65
|
+
* Sets the `currentIconType` property to match the `type` property.
|
66
|
+
*/
|
67
|
+
private handleOnLoad;
|
68
|
+
/**
|
69
|
+
* Handles an error that occurs when loading an icon.
|
70
|
+
*/
|
71
|
+
private handleOnError;
|
58
72
|
render(): import("lit-html").TemplateResult<1>;
|
59
73
|
static styles: Array<CSSResult>;
|
60
74
|
}
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
9
|
};
|
10
10
|
import { html } from 'lit';
|
11
|
-
import { property } from 'lit/decorators.js';
|
11
|
+
import { property, state } from 'lit/decorators.js';
|
12
12
|
import { Component } from '../../models';
|
13
13
|
import { DEFAULTS, SIZE } from './presence.constants';
|
14
14
|
import styles from './presence.styles';
|
@@ -61,6 +61,11 @@ class Presence extends Component {
|
|
61
61
|
* @default small
|
62
62
|
*/
|
63
63
|
this.size = DEFAULTS.SIZE;
|
64
|
+
/**
|
65
|
+
* @internal
|
66
|
+
* State to track the current icon type (previous type until the new icon is loaded)
|
67
|
+
*/
|
68
|
+
this.currentIconType = DEFAULTS.TYPE;
|
64
69
|
}
|
65
70
|
/**
|
66
71
|
* Get the size of the presence icon based on the given size type
|
@@ -93,13 +98,30 @@ class Presence extends Component {
|
|
93
98
|
}
|
94
99
|
return iconName;
|
95
100
|
}
|
101
|
+
/**
|
102
|
+
* Handles the successful load of an icon.
|
103
|
+
* Sets the `currentIconType` property to match the `type` property.
|
104
|
+
*/
|
105
|
+
handleOnLoad() {
|
106
|
+
this.currentIconType = this.type;
|
107
|
+
}
|
108
|
+
/**
|
109
|
+
* Handles an error that occurs when loading an icon.
|
110
|
+
*/
|
111
|
+
handleOnError() {
|
112
|
+
if (this.onerror) {
|
113
|
+
this.onerror('There was a problem while fetching the icon. Please check the icon name and try again.');
|
114
|
+
}
|
115
|
+
}
|
96
116
|
render() {
|
97
117
|
return html `
|
98
118
|
<div class="mdc-presence mdc-presence__${this.size}">
|
99
119
|
<mdc-icon
|
100
|
-
class="mdc-presence-icon mdc-presence-icon__${this.
|
120
|
+
class="mdc-presence-icon mdc-presence-icon__${this.currentIconType}"
|
101
121
|
name="${this.icon}"
|
102
122
|
size="${this.iconSize}"
|
123
|
+
@load="${this.handleOnLoad}"
|
124
|
+
@error="${this.handleOnError}"
|
103
125
|
></mdc-icon>
|
104
126
|
</div>
|
105
127
|
`;
|
@@ -114,4 +136,8 @@ __decorate([
|
|
114
136
|
property({ type: String, reflect: true }),
|
115
137
|
__metadata("design:type", String)
|
116
138
|
], Presence.prototype, "size", void 0);
|
139
|
+
__decorate([
|
140
|
+
state(),
|
141
|
+
__metadata("design:type", String)
|
142
|
+
], Presence.prototype, "currentIconType", void 0);
|
117
143
|
export default Presence;
|
@@ -2222,12 +2222,52 @@
|
|
2222
2222
|
"privacy": "private",
|
2223
2223
|
"default": "new AbortController()"
|
2224
2224
|
},
|
2225
|
+
{
|
2226
|
+
"kind": "method",
|
2227
|
+
"name": "triggerIconLoaded",
|
2228
|
+
"privacy": "private",
|
2229
|
+
"return": {
|
2230
|
+
"type": {
|
2231
|
+
"text": "void"
|
2232
|
+
}
|
2233
|
+
},
|
2234
|
+
"description": "Dispatches a 'load' event on the component once the icon has been successfully loaded.\nThis event bubbles and is cancelable."
|
2235
|
+
},
|
2225
2236
|
{
|
2226
2237
|
"kind": "method",
|
2227
2238
|
"name": "getIconData",
|
2228
2239
|
"privacy": "private",
|
2229
2240
|
"description": "Get Icon Data function which will fetch the icon (currently only svg)\nand sets state and attributes once fetched successfully\n\nThis method uses abortController.signal to cancel the fetch request when the component is disconnected or updated.\nIf the request is aborted after the fetch() call has been fulfilled but before the response body has been read,\nthen attempting to read the response body will reject with an AbortError exception."
|
2230
2241
|
},
|
2242
|
+
{
|
2243
|
+
"kind": "method",
|
2244
|
+
"name": "handleIconLoadedSuccess",
|
2245
|
+
"privacy": "private",
|
2246
|
+
"parameters": [
|
2247
|
+
{
|
2248
|
+
"name": "iconHtml",
|
2249
|
+
"type": {
|
2250
|
+
"text": "HTMLElement"
|
2251
|
+
},
|
2252
|
+
"description": "The icon html element which has been fetched from the icon provider."
|
2253
|
+
}
|
2254
|
+
],
|
2255
|
+
"description": "Sets the iconData state to the fetched icon,\nand calls functions to set role, aria-label and aria-hidden attributes on the icon.\nDispatches a 'load' event on the component once the icon has been successfully loaded."
|
2256
|
+
},
|
2257
|
+
{
|
2258
|
+
"kind": "method",
|
2259
|
+
"name": "handleIconLoadedFailure",
|
2260
|
+
"privacy": "private",
|
2261
|
+
"parameters": [
|
2262
|
+
{
|
2263
|
+
"name": "error",
|
2264
|
+
"type": {
|
2265
|
+
"text": "unknown"
|
2266
|
+
}
|
2267
|
+
}
|
2268
|
+
],
|
2269
|
+
"description": "Dispatches an 'error' event on the component when the icon fetching has failed.\nThis event bubbles and is cancelable.\nThe error detail is set to the error object."
|
2270
|
+
},
|
2231
2271
|
{
|
2232
2272
|
"kind": "method",
|
2233
2273
|
"name": "updateSize",
|
@@ -2564,6 +2604,28 @@
|
|
2564
2604
|
"privacy": "private",
|
2565
2605
|
"description": "Get the icon name based on the presence type",
|
2566
2606
|
"readonly": true
|
2607
|
+
},
|
2608
|
+
{
|
2609
|
+
"kind": "method",
|
2610
|
+
"name": "handleOnLoad",
|
2611
|
+
"privacy": "private",
|
2612
|
+
"return": {
|
2613
|
+
"type": {
|
2614
|
+
"text": "void"
|
2615
|
+
}
|
2616
|
+
},
|
2617
|
+
"description": "Handles the successful load of an icon.\nSets the `currentIconType` property to match the `type` property."
|
2618
|
+
},
|
2619
|
+
{
|
2620
|
+
"kind": "method",
|
2621
|
+
"name": "handleOnError",
|
2622
|
+
"privacy": "private",
|
2623
|
+
"return": {
|
2624
|
+
"type": {
|
2625
|
+
"text": "void"
|
2626
|
+
}
|
2627
|
+
},
|
2628
|
+
"description": "Handles an error that occurs when loading an icon."
|
2567
2629
|
}
|
2568
2630
|
],
|
2569
2631
|
"attributes": [
|
package/package.json
CHANGED