@momentum-design/components 0.12.5 → 0.12.6
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/browser/index.js +24 -24
- package/dist/browser/index.js.map +3 -3
- package/dist/components/button/button.component.d.ts +1 -6
- package/dist/components/button/button.component.js +9 -19
- package/dist/components/button/button.styles.js +7 -7
- package/dist/components/icon/icon.component.d.ts +6 -0
- package/dist/components/icon/icon.component.js +16 -4
- package/dist/components/icon/icon.utils.d.ts +3 -1
- package/dist/components/icon/icon.utils.js +4 -2
- package/dist/custom-elements.json +82 -88
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/package.json +1 -1
@@ -145,11 +145,6 @@ declare class Button extends Component {
|
|
145
145
|
* @param active - The active state.
|
146
146
|
*/
|
147
147
|
private modifyIconName;
|
148
|
-
/**
|
149
|
-
* Sets the class of 'icon' for icon buttons.
|
150
|
-
* @param type - The type of the button.
|
151
|
-
*/
|
152
|
-
private setClassBasedOnType;
|
153
148
|
/**
|
154
149
|
* Sets the variant attribute for the button component.
|
155
150
|
* If the provided variant is not included in the BUTTON_VARIANTS,
|
@@ -174,7 +169,7 @@ declare class Button extends Component {
|
|
174
169
|
*/
|
175
170
|
private setColor;
|
176
171
|
/**
|
177
|
-
* Sets
|
172
|
+
* Sets the aria-pressed attribute based on the active state.
|
178
173
|
*
|
179
174
|
* @param element - The target element.
|
180
175
|
* @param active - The active state.
|
@@ -157,7 +157,6 @@ class Button extends Component {
|
|
157
157
|
}
|
158
158
|
if (changedProperties.has('typeInternal')) {
|
159
159
|
this.setSize(this.size);
|
160
|
-
this.setClassBasedOnType(this.typeInternal);
|
161
160
|
}
|
162
161
|
if (changedProperties.has('prefixIcon') || changedProperties.has('postfixIcon')) {
|
163
162
|
this.inferButtonType();
|
@@ -199,18 +198,6 @@ class Button extends Component {
|
|
199
198
|
}
|
200
199
|
}
|
201
200
|
}
|
202
|
-
/**
|
203
|
-
* Sets the class of 'icon' for icon buttons.
|
204
|
-
* @param type - The type of the button.
|
205
|
-
*/
|
206
|
-
setClassBasedOnType(type) {
|
207
|
-
if (type === BUTTON_TYPE_INTERNAL.ICON) {
|
208
|
-
this.classList.add('mdc-icon-button');
|
209
|
-
}
|
210
|
-
else {
|
211
|
-
this.classList.remove('mdc-icon-button');
|
212
|
-
}
|
213
|
-
}
|
214
201
|
/**
|
215
202
|
* Sets the variant attribute for the button component.
|
216
203
|
* If the provided variant is not included in the BUTTON_VARIANTS,
|
@@ -252,17 +239,17 @@ class Button extends Component {
|
|
252
239
|
}
|
253
240
|
}
|
254
241
|
/**
|
255
|
-
* Sets
|
242
|
+
* Sets the aria-pressed attribute based on the active state.
|
256
243
|
*
|
257
244
|
* @param element - The target element.
|
258
245
|
* @param active - The active state.
|
259
246
|
*/
|
260
247
|
setAriaPressed(element, active) {
|
261
248
|
if (active) {
|
262
|
-
element.setAttribute('aria-pressed', '');
|
249
|
+
element.setAttribute('aria-pressed', 'true');
|
263
250
|
}
|
264
251
|
else {
|
265
|
-
element.
|
252
|
+
element.setAttribute('aria-pressed', 'false');
|
266
253
|
}
|
267
254
|
}
|
268
255
|
/**
|
@@ -275,10 +262,10 @@ class Button extends Component {
|
|
275
262
|
*/
|
276
263
|
setSoftDisabled(element, softDisabled) {
|
277
264
|
if (softDisabled) {
|
278
|
-
element.setAttribute('aria-disabled', '');
|
265
|
+
element.setAttribute('aria-disabled', 'true');
|
279
266
|
}
|
280
267
|
else {
|
281
|
-
element.
|
268
|
+
element.setAttribute('aria-disabled', 'false');
|
282
269
|
}
|
283
270
|
}
|
284
271
|
/**
|
@@ -292,7 +279,7 @@ class Button extends Component {
|
|
292
279
|
*/
|
293
280
|
setDisabled(element, disabled) {
|
294
281
|
if (disabled) {
|
295
|
-
element.setAttribute('aria-disabled', '');
|
282
|
+
element.setAttribute('aria-disabled', 'true');
|
296
283
|
this.prevTabindex = this.tabIndex;
|
297
284
|
this.tabIndex = -1;
|
298
285
|
}
|
@@ -349,12 +336,15 @@ class Button extends Component {
|
|
349
336
|
const slot = (_b = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('slot')) === null || _b === void 0 ? void 0 : _b.assignedNodes().length;
|
350
337
|
if (slot && (this.prefixIcon || this.postfixIcon)) {
|
351
338
|
this.typeInternal = BUTTON_TYPE_INTERNAL.PILL_WITH_ICON;
|
339
|
+
this.setAttribute('data-btn-type', 'pill-with-icon');
|
352
340
|
}
|
353
341
|
else if (!slot && (this.prefixIcon || this.postfixIcon)) {
|
354
342
|
this.typeInternal = BUTTON_TYPE_INTERNAL.ICON;
|
343
|
+
this.setAttribute('data-btn-type', 'icon');
|
355
344
|
}
|
356
345
|
else {
|
357
346
|
this.typeInternal = BUTTON_TYPE_INTERNAL.PILL;
|
347
|
+
this.setAttribute('data-btn-type', 'pill');
|
358
348
|
}
|
359
349
|
}
|
360
350
|
// Note: @click is attached to each of the children of the button.
|
@@ -47,7 +47,6 @@ const styles = [hostFitContentStyles, css `
|
|
47
47
|
font-weight: var(--mds-font-apps-body-large-bold-font-weight);
|
48
48
|
}
|
49
49
|
|
50
|
-
|
51
50
|
:host([variant="primary"]){
|
52
51
|
background: var(--mdc-button-primary-background-color);
|
53
52
|
color: var(--mdc-button-primary-color);
|
@@ -99,12 +98,12 @@ const styles = [hostFitContentStyles, css `
|
|
99
98
|
cursor: auto;
|
100
99
|
}
|
101
100
|
|
102
|
-
:host([size="64"]
|
103
|
-
:host([size="52"]
|
104
|
-
:host([size="40"]
|
105
|
-
:host([size="32"]
|
106
|
-
:host([size="28"]
|
107
|
-
:host([size="24"]
|
101
|
+
:host([size="64"][data-btn-type='icon']),
|
102
|
+
:host([size="52"][data-btn-type='icon']),
|
103
|
+
:host([size="40"][data-btn-type='icon']),
|
104
|
+
:host([size="32"][data-btn-type='icon']),
|
105
|
+
:host([size="28"][data-btn-type='icon']),
|
106
|
+
:host([size="24"][data-btn-type='icon']){
|
108
107
|
border-radius: 6.25rem;
|
109
108
|
aspect-ratio: 1;
|
110
109
|
padding: unset;
|
@@ -145,6 +144,7 @@ const styles = [hostFitContentStyles, css `
|
|
145
144
|
}
|
146
145
|
:host([size="20"]){
|
147
146
|
height: var(--mdc-button-height-size-20);
|
147
|
+
padding: 0.0625rem;
|
148
148
|
}
|
149
149
|
|
150
150
|
:host([color="accent"]){
|
@@ -59,9 +59,15 @@ declare class Icon extends Component {
|
|
59
59
|
*/
|
60
60
|
ariaLabel: string | null;
|
61
61
|
private readonly iconProviderContext;
|
62
|
+
private abortController;
|
63
|
+
constructor();
|
62
64
|
/**
|
63
65
|
* Get Icon Data function which will fetch the icon (currently only svg)
|
64
66
|
* and sets state and attributes once fetched successfully
|
67
|
+
*
|
68
|
+
* This method uses abortController.signal to cancel the fetch request when the component is disconnected or updated.
|
69
|
+
* If the request is aborted after the fetch() call has been fulfilled but before the response body has been read,
|
70
|
+
* then attempting to read the response body will reject with an AbortError exception.
|
65
71
|
*/
|
66
72
|
private getIconData;
|
67
73
|
/**
|
@@ -54,7 +54,7 @@ import { DEFAULTS } from './icon.constants';
|
|
54
54
|
*/
|
55
55
|
class Icon extends Component {
|
56
56
|
constructor() {
|
57
|
-
super(
|
57
|
+
super();
|
58
58
|
/**
|
59
59
|
* Name of the icon (= filename)
|
60
60
|
*/
|
@@ -64,16 +64,23 @@ class Icon extends Component {
|
|
64
64
|
*/
|
65
65
|
this.ariaLabel = null;
|
66
66
|
this.iconProviderContext = providerUtils.consume({ host: this, context: IconProvider.Context });
|
67
|
+
this.abortController = new AbortController(); // Initialize AbortController
|
67
68
|
}
|
68
69
|
/**
|
69
70
|
* Get Icon Data function which will fetch the icon (currently only svg)
|
70
71
|
* and sets state and attributes once fetched successfully
|
72
|
+
*
|
73
|
+
* This method uses abortController.signal to cancel the fetch request when the component is disconnected or updated.
|
74
|
+
* If the request is aborted after the fetch() call has been fulfilled but before the response body has been read,
|
75
|
+
* then attempting to read the response body will reject with an AbortError exception.
|
71
76
|
*/
|
72
77
|
async getIconData() {
|
73
78
|
if (this.iconProviderContext.value) {
|
74
79
|
const { fileExtension, url } = this.iconProviderContext.value;
|
75
80
|
if (url && fileExtension && this.name) {
|
76
|
-
|
81
|
+
this.abortController.abort();
|
82
|
+
this.abortController = new AbortController();
|
83
|
+
const iconHtml = await dynamicSVGImport(url, this.name, fileExtension, this.abortController.signal);
|
77
84
|
// update iconData state once fetched:
|
78
85
|
this.iconData = iconHtml;
|
79
86
|
// when icon got fetched, set role and aria-label:
|
@@ -122,8 +129,9 @@ class Icon extends Component {
|
|
122
129
|
if (changedProperties.has('name')) {
|
123
130
|
// fetch icon data if name changes:
|
124
131
|
this.getIconData().catch((err) => {
|
125
|
-
|
126
|
-
|
132
|
+
if (err.name !== 'AbortError' && this.onerror) {
|
133
|
+
this.onerror(err);
|
134
|
+
}
|
127
135
|
});
|
128
136
|
}
|
129
137
|
if (changedProperties.has('ariaLabel')) {
|
@@ -175,4 +183,8 @@ __decorate([
|
|
175
183
|
property({ type: String, attribute: 'aria-label' }),
|
176
184
|
__metadata("design:type", Object)
|
177
185
|
], Icon.prototype, "ariaLabel", void 0);
|
186
|
+
__decorate([
|
187
|
+
state(),
|
188
|
+
__metadata("design:type", AbortController)
|
189
|
+
], Icon.prototype, "abortController", void 0);
|
178
190
|
export default Icon;
|
@@ -5,8 +5,10 @@
|
|
5
5
|
* @param url - The base url of the icon
|
6
6
|
* @param name - The name of the icon
|
7
7
|
* @param fileExtension - The file extension of the icon
|
8
|
+
* @param signal - The signal to abort the fetch.
|
9
|
+
* It is used to cancel the fetch when the component is disconnected or updated.
|
8
10
|
* @returns The valid icon element
|
9
11
|
* @throws Error if the response is not ok
|
10
12
|
*/
|
11
|
-
declare const dynamicSVGImport: (url: string, name: string, fileExtension: string) => Promise<Element>;
|
13
|
+
declare const dynamicSVGImport: (url: string, name: string, fileExtension: string, signal: AbortSignal) => Promise<Element>;
|
12
14
|
export { dynamicSVGImport };
|
@@ -6,11 +6,13 @@
|
|
6
6
|
* @param url - The base url of the icon
|
7
7
|
* @param name - The name of the icon
|
8
8
|
* @param fileExtension - The file extension of the icon
|
9
|
+
* @param signal - The signal to abort the fetch.
|
10
|
+
* It is used to cancel the fetch when the component is disconnected or updated.
|
9
11
|
* @returns The valid icon element
|
10
12
|
* @throws Error if the response is not ok
|
11
13
|
*/
|
12
|
-
const dynamicSVGImport = async (url, name, fileExtension) => {
|
13
|
-
const response = await fetch(`${url}/${name}.${fileExtension}
|
14
|
+
const dynamicSVGImport = async (url, name, fileExtension, signal) => {
|
15
|
+
const response = await fetch(`${url}/${name}.${fileExtension}`, { signal });
|
14
16
|
if (!response.ok) {
|
15
17
|
throw new Error('There was a problem while fetching the icon!');
|
16
18
|
}
|
@@ -180,77 +180,6 @@
|
|
180
180
|
}
|
181
181
|
]
|
182
182
|
},
|
183
|
-
{
|
184
|
-
"kind": "javascript-module",
|
185
|
-
"path": "components/bullet/bullet.component.js",
|
186
|
-
"declarations": [
|
187
|
-
{
|
188
|
-
"kind": "class",
|
189
|
-
"description": "Bullet component, which is a visual marker\nand be used to organize and present items in a list format.",
|
190
|
-
"name": "Bullet",
|
191
|
-
"cssProperties": [
|
192
|
-
{
|
193
|
-
"description": "background color of the bullet",
|
194
|
-
"name": "--mdc-bullet-background-color"
|
195
|
-
},
|
196
|
-
{
|
197
|
-
"description": "small size value of the bullet",
|
198
|
-
"name": "--mdc-bullet-size-small"
|
199
|
-
},
|
200
|
-
{
|
201
|
-
"description": "medium size value of the bullet",
|
202
|
-
"name": "--mdc-bullet-size-medium"
|
203
|
-
},
|
204
|
-
{
|
205
|
-
"description": "large size value of the bullet",
|
206
|
-
"name": "--mdc-bullet-size-large"
|
207
|
-
}
|
208
|
-
],
|
209
|
-
"members": [
|
210
|
-
{
|
211
|
-
"kind": "field",
|
212
|
-
"name": "size",
|
213
|
-
"type": {
|
214
|
-
"text": "Size"
|
215
|
-
},
|
216
|
-
"privacy": "public",
|
217
|
-
"description": "Size of the bullet\n\nPossible values: 'small', 'medium', 'large'",
|
218
|
-
"default": "small",
|
219
|
-
"attribute": "size",
|
220
|
-
"reflects": true
|
221
|
-
}
|
222
|
-
],
|
223
|
-
"attributes": [
|
224
|
-
{
|
225
|
-
"name": "size",
|
226
|
-
"type": {
|
227
|
-
"text": "Size"
|
228
|
-
},
|
229
|
-
"description": "Size of the bullet\n\nPossible values: 'small', 'medium', 'large'",
|
230
|
-
"default": "small",
|
231
|
-
"fieldName": "size"
|
232
|
-
}
|
233
|
-
],
|
234
|
-
"superclass": {
|
235
|
-
"name": "Component",
|
236
|
-
"module": "/src/models"
|
237
|
-
},
|
238
|
-
"tagName": "mdc-bullet",
|
239
|
-
"jsDoc": "/**\n * Bullet component, which is a visual marker\n * and be used to organize and present items in a list format.\n *\n * @tagname mdc-bullet\n *\n * @cssproperty --mdc-bullet-background-color - background color of the bullet\n * @cssproperty --mdc-bullet-size-small - small size value of the bullet\n * @cssproperty --mdc-bullet-size-medium - medium size value of the bullet\n * @cssproperty --mdc-bullet-size-large - large size value of the bullet\n*/",
|
240
|
-
"customElement": true
|
241
|
-
}
|
242
|
-
],
|
243
|
-
"exports": [
|
244
|
-
{
|
245
|
-
"kind": "js",
|
246
|
-
"name": "default",
|
247
|
-
"declaration": {
|
248
|
-
"name": "Bullet",
|
249
|
-
"module": "components/bullet/bullet.component.js"
|
250
|
-
}
|
251
|
-
}
|
252
|
-
]
|
253
|
-
},
|
254
183
|
{
|
255
184
|
"kind": "javascript-module",
|
256
185
|
"path": "components/badge/badge.component.js",
|
@@ -512,6 +441,77 @@
|
|
512
441
|
}
|
513
442
|
]
|
514
443
|
},
|
444
|
+
{
|
445
|
+
"kind": "javascript-module",
|
446
|
+
"path": "components/bullet/bullet.component.js",
|
447
|
+
"declarations": [
|
448
|
+
{
|
449
|
+
"kind": "class",
|
450
|
+
"description": "Bullet component, which is a visual marker\nand be used to organize and present items in a list format.",
|
451
|
+
"name": "Bullet",
|
452
|
+
"cssProperties": [
|
453
|
+
{
|
454
|
+
"description": "background color of the bullet",
|
455
|
+
"name": "--mdc-bullet-background-color"
|
456
|
+
},
|
457
|
+
{
|
458
|
+
"description": "small size value of the bullet",
|
459
|
+
"name": "--mdc-bullet-size-small"
|
460
|
+
},
|
461
|
+
{
|
462
|
+
"description": "medium size value of the bullet",
|
463
|
+
"name": "--mdc-bullet-size-medium"
|
464
|
+
},
|
465
|
+
{
|
466
|
+
"description": "large size value of the bullet",
|
467
|
+
"name": "--mdc-bullet-size-large"
|
468
|
+
}
|
469
|
+
],
|
470
|
+
"members": [
|
471
|
+
{
|
472
|
+
"kind": "field",
|
473
|
+
"name": "size",
|
474
|
+
"type": {
|
475
|
+
"text": "Size"
|
476
|
+
},
|
477
|
+
"privacy": "public",
|
478
|
+
"description": "Size of the bullet\n\nPossible values: 'small', 'medium', 'large'",
|
479
|
+
"default": "small",
|
480
|
+
"attribute": "size",
|
481
|
+
"reflects": true
|
482
|
+
}
|
483
|
+
],
|
484
|
+
"attributes": [
|
485
|
+
{
|
486
|
+
"name": "size",
|
487
|
+
"type": {
|
488
|
+
"text": "Size"
|
489
|
+
},
|
490
|
+
"description": "Size of the bullet\n\nPossible values: 'small', 'medium', 'large'",
|
491
|
+
"default": "small",
|
492
|
+
"fieldName": "size"
|
493
|
+
}
|
494
|
+
],
|
495
|
+
"superclass": {
|
496
|
+
"name": "Component",
|
497
|
+
"module": "/src/models"
|
498
|
+
},
|
499
|
+
"tagName": "mdc-bullet",
|
500
|
+
"jsDoc": "/**\n * Bullet component, which is a visual marker\n * and be used to organize and present items in a list format.\n *\n * @tagname mdc-bullet\n *\n * @cssproperty --mdc-bullet-background-color - background color of the bullet\n * @cssproperty --mdc-bullet-size-small - small size value of the bullet\n * @cssproperty --mdc-bullet-size-medium - medium size value of the bullet\n * @cssproperty --mdc-bullet-size-large - large size value of the bullet\n*/",
|
501
|
+
"customElement": true
|
502
|
+
}
|
503
|
+
],
|
504
|
+
"exports": [
|
505
|
+
{
|
506
|
+
"kind": "js",
|
507
|
+
"name": "default",
|
508
|
+
"declaration": {
|
509
|
+
"name": "Bullet",
|
510
|
+
"module": "components/bullet/bullet.component.js"
|
511
|
+
}
|
512
|
+
}
|
513
|
+
]
|
514
|
+
},
|
515
515
|
{
|
516
516
|
"kind": "javascript-module",
|
517
517
|
"path": "components/button/button.component.js",
|
@@ -660,21 +660,6 @@
|
|
660
660
|
],
|
661
661
|
"description": "Modifies the icon name based on the active state.\nIf the button is active, the icon name is suffixed with '-filled'.\nIf the button is inactive, the icon name is restored to its original value.\nIf '-filled' icon is not available, the icon name remains unchanged."
|
662
662
|
},
|
663
|
-
{
|
664
|
-
"kind": "method",
|
665
|
-
"name": "setClassBasedOnType",
|
666
|
-
"privacy": "private",
|
667
|
-
"parameters": [
|
668
|
-
{
|
669
|
-
"name": "type",
|
670
|
-
"type": {
|
671
|
-
"text": "string"
|
672
|
-
},
|
673
|
-
"description": "The type of the button."
|
674
|
-
}
|
675
|
-
],
|
676
|
-
"description": "Sets the class of 'icon' for icon buttons."
|
677
|
-
},
|
678
663
|
{
|
679
664
|
"kind": "method",
|
680
665
|
"name": "setVariant",
|
@@ -740,7 +725,7 @@
|
|
740
725
|
"description": "The active state."
|
741
726
|
}
|
742
727
|
],
|
743
|
-
"description": "Sets
|
728
|
+
"description": "Sets the aria-pressed attribute based on the active state."
|
744
729
|
},
|
745
730
|
{
|
746
731
|
"kind": "method",
|
@@ -1036,11 +1021,20 @@
|
|
1036
1021
|
"privacy": "private",
|
1037
1022
|
"readonly": true
|
1038
1023
|
},
|
1024
|
+
{
|
1025
|
+
"kind": "field",
|
1026
|
+
"name": "abortController",
|
1027
|
+
"type": {
|
1028
|
+
"text": "AbortController"
|
1029
|
+
},
|
1030
|
+
"privacy": "private",
|
1031
|
+
"default": "new AbortController()"
|
1032
|
+
},
|
1039
1033
|
{
|
1040
1034
|
"kind": "method",
|
1041
1035
|
"name": "getIconData",
|
1042
1036
|
"privacy": "private",
|
1043
|
-
"description": "Get Icon Data function which will fetch the icon (currently only svg)\nand sets state and attributes once fetched successfully"
|
1037
|
+
"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."
|
1044
1038
|
},
|
1045
1039
|
{
|
1046
1040
|
"kind": "method",
|
package/dist/react/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
export { default as Avatar } from './avatar';
|
2
|
-
export { default as Bullet } from './bullet';
|
3
2
|
export { default as Badge } from './badge';
|
3
|
+
export { default as Bullet } from './bullet';
|
4
4
|
export { default as Button } from './button';
|
5
5
|
export { default as Icon } from './icon';
|
6
6
|
export { default as IconProvider } from './iconprovider';
|
package/dist/react/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
export { default as Avatar } from './avatar';
|
2
|
-
export { default as Bullet } from './bullet';
|
3
2
|
export { default as Badge } from './badge';
|
3
|
+
export { default as Bullet } from './bullet';
|
4
4
|
export { default as Button } from './button';
|
5
5
|
export { default as Icon } from './icon';
|
6
6
|
export { default as IconProvider } from './iconprovider';
|
package/package.json
CHANGED