@momentum-design/components 0.18.2 → 0.18.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/browser/index.js +30 -25
- package/dist/browser/index.js.map +3 -3
- package/dist/components/icon/icon.component.d.ts +10 -12
- package/dist/components/icon/icon.component.js +17 -40
- package/dist/components/icon/icon.styles.js +7 -4
- package/dist/components/icon/icon.utils.js +2 -0
- package/dist/custom-elements.json +3 -29
- package/dist/react/icon/index.d.ts +9 -2
- package/dist/react/icon/index.js +9 -2
- package/dist/utils/styles/index.js +3 -0
- package/package.json +1 -1
@@ -19,7 +19,7 @@ import type { IconNames } from './icon.types';
|
|
19
19
|
* if `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be
|
20
20
|
* `width: 1em; height: 1em`.
|
21
21
|
*
|
22
|
-
* Regarding accessibility, there are
|
22
|
+
* Regarding accessibility, there are three types of icons: decorative, informative and informative standalone.
|
23
23
|
*
|
24
24
|
* ### Decorative Icons
|
25
25
|
* - Decorative icons do not convey any essential information to the content of a page.
|
@@ -30,10 +30,17 @@ import type { IconNames } from './icon.types';
|
|
30
30
|
* - Informative icons convey important information that is not adequately represented
|
31
31
|
* by surrounding text or components.
|
32
32
|
* - They provide valuable context and must be announced by assistive technologies.
|
33
|
-
* - For informative icons, an `aria-label` is required, and the `role` will be set to "img".
|
33
|
+
* - For informative icons, an `aria-label` is required, and the `role` will be set to "img" automatically.
|
34
34
|
* - If an `aria-label` is provided, the role will be set to 'img'; if it is absent,
|
35
35
|
* the role will be unset.
|
36
36
|
*
|
37
|
+
* ### Informative Standalone Icons
|
38
|
+
* - If an icon is informative (as mentioned above) and does not belong to a button (=standalone), it must
|
39
|
+
* have a Tooltip that describes what it means.
|
40
|
+
* - For informative standalone icons, an `aria-label` & `tabindex="0"` is required,
|
41
|
+
* and the `role` will be set to "img" automatically.
|
42
|
+
* - **Only use this when a Icon is standalone and is not part of a button or other interactive elements.**
|
43
|
+
*
|
37
44
|
* @tagname mdc-icon
|
38
45
|
*
|
39
46
|
* @cssproperty --mdc-icon-fill-color - Allows customization of the default fill color.
|
@@ -61,11 +68,6 @@ declare class Icon extends Component {
|
|
61
68
|
private readonly iconProviderContext;
|
62
69
|
private abortController;
|
63
70
|
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;
|
69
71
|
/**
|
70
72
|
* Get Icon Data function which will fetch the icon (currently only svg)
|
71
73
|
* and sets state and attributes once fetched successfully
|
@@ -76,8 +78,7 @@ declare class Icon extends Component {
|
|
76
78
|
*/
|
77
79
|
private getIconData;
|
78
80
|
/**
|
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
|
+
* Sets the iconData state to the fetched icon.
|
81
82
|
* Dispatches a 'load' event on the component once the icon has been successfully loaded.
|
82
83
|
* @param iconHtml - The icon html element which has been fetched from the icon provider.
|
83
84
|
*/
|
@@ -92,9 +93,6 @@ declare class Icon extends Component {
|
|
92
93
|
* Updates the size by setting the width and height
|
93
94
|
*/
|
94
95
|
private updateSize;
|
95
|
-
private setRoleOnIcon;
|
96
|
-
private setAriaHiddenOnIcon;
|
97
|
-
private setAriaLabelOnIcon;
|
98
96
|
private get computedIconSize();
|
99
97
|
updated(changedProperties: Map<string, any>): void;
|
100
98
|
render(): import("lit-html").TemplateResult<1>;
|
@@ -33,7 +33,7 @@ import { DEFAULTS } from './icon.constants';
|
|
33
33
|
* if `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be
|
34
34
|
* `width: 1em; height: 1em`.
|
35
35
|
*
|
36
|
-
* Regarding accessibility, there are
|
36
|
+
* Regarding accessibility, there are three types of icons: decorative, informative and informative standalone.
|
37
37
|
*
|
38
38
|
* ### Decorative Icons
|
39
39
|
* - Decorative icons do not convey any essential information to the content of a page.
|
@@ -44,10 +44,17 @@ import { DEFAULTS } from './icon.constants';
|
|
44
44
|
* - Informative icons convey important information that is not adequately represented
|
45
45
|
* by surrounding text or components.
|
46
46
|
* - They provide valuable context and must be announced by assistive technologies.
|
47
|
-
* - For informative icons, an `aria-label` is required, and the `role` will be set to "img".
|
47
|
+
* - For informative icons, an `aria-label` is required, and the `role` will be set to "img" automatically.
|
48
48
|
* - If an `aria-label` is provided, the role will be set to 'img'; if it is absent,
|
49
49
|
* the role will be unset.
|
50
50
|
*
|
51
|
+
* ### Informative Standalone Icons
|
52
|
+
* - If an icon is informative (as mentioned above) and does not belong to a button (=standalone), it must
|
53
|
+
* have a Tooltip that describes what it means.
|
54
|
+
* - For informative standalone icons, an `aria-label` & `tabindex="0"` is required,
|
55
|
+
* and the `role` will be set to "img" automatically.
|
56
|
+
* - **Only use this when a Icon is standalone and is not part of a button or other interactive elements.**
|
57
|
+
*
|
51
58
|
* @tagname mdc-icon
|
52
59
|
*
|
53
60
|
* @cssproperty --mdc-icon-fill-color - Allows customization of the default fill color.
|
@@ -66,17 +73,6 @@ class Icon extends Component {
|
|
66
73
|
this.iconProviderContext = providerUtils.consume({ host: this, context: IconProvider.Context });
|
67
74
|
this.abortController = new AbortController(); // Initialize AbortController
|
68
75
|
}
|
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
|
-
}
|
80
76
|
/**
|
81
77
|
* Get Icon Data function which will fetch the icon (currently only svg)
|
82
78
|
* and sets state and attributes once fetched successfully
|
@@ -102,19 +98,19 @@ class Icon extends Component {
|
|
102
98
|
}
|
103
99
|
}
|
104
100
|
/**
|
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.
|
101
|
+
* Sets the iconData state to the fetched icon.
|
107
102
|
* Dispatches a 'load' event on the component once the icon has been successfully loaded.
|
108
103
|
* @param iconHtml - The icon html element which has been fetched from the icon provider.
|
109
104
|
*/
|
110
105
|
handleIconLoadedSuccess(iconHtml) {
|
111
106
|
// update iconData state once fetched:
|
112
107
|
this.iconData = iconHtml;
|
113
|
-
// when icon is fetched successfully,
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
108
|
+
// when icon is fetched successfully, trigger icon load event.
|
109
|
+
const loadEvent = new Event('load', {
|
110
|
+
bubbles: true,
|
111
|
+
cancelable: true,
|
112
|
+
});
|
113
|
+
this.dispatchEvent(loadEvent);
|
118
114
|
}
|
119
115
|
/**
|
120
116
|
* Dispatches an 'error' event on the component when the icon fetching has failed.
|
@@ -140,24 +136,6 @@ class Icon extends Component {
|
|
140
136
|
this.style.setProperty('--computed-icon-size', value);
|
141
137
|
}
|
142
138
|
}
|
143
|
-
setRoleOnIcon() {
|
144
|
-
this.role = this.ariaLabel ? 'img' : null;
|
145
|
-
}
|
146
|
-
setAriaHiddenOnIcon() {
|
147
|
-
var _a;
|
148
|
-
// set aria-hidden=true for SVG to avoid screen readers
|
149
|
-
(_a = this.iconData) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-hidden', 'true');
|
150
|
-
}
|
151
|
-
setAriaLabelOnIcon() {
|
152
|
-
var _a, _b;
|
153
|
-
if (this.ariaLabel) {
|
154
|
-
// pass through aria-label attribute to svg if set on mdc-icon
|
155
|
-
(_a = this.iconData) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-label', this.ariaLabel);
|
156
|
-
}
|
157
|
-
else {
|
158
|
-
(_b = this.iconData) === null || _b === void 0 ? void 0 : _b.removeAttribute('aria-label');
|
159
|
-
}
|
160
|
-
}
|
161
139
|
get computedIconSize() {
|
162
140
|
var _a, _b;
|
163
141
|
return (_b = (_a = this.size) !== null && _a !== void 0 ? _a : this.sizeFromContext) !== null && _b !== void 0 ? _b : DEFAULTS.SIZE;
|
@@ -174,8 +152,7 @@ class Icon extends Component {
|
|
174
152
|
});
|
175
153
|
}
|
176
154
|
if (changedProperties.has('ariaLabel')) {
|
177
|
-
this.
|
178
|
-
this.setAriaLabelOnIcon();
|
155
|
+
this.role = this.ariaLabel ? 'img' : null;
|
179
156
|
}
|
180
157
|
if (changedProperties.has('size') || changedProperties.has('lengthUnit')) {
|
181
158
|
this.updateSize();
|
@@ -1,14 +1,16 @@
|
|
1
1
|
import { css } from 'lit';
|
2
|
-
import { hostFitContentStyles } from '../../utils/styles';
|
2
|
+
import { hostFitContentStyles, hostFocusRingStyles } from '../../utils/styles';
|
3
3
|
const styles = [
|
4
4
|
hostFitContentStyles,
|
5
5
|
css `
|
6
6
|
:host {
|
7
7
|
--mdc-icon-fill-color: currentColor;
|
8
|
-
--mdc-icon-
|
8
|
+
--mdc-icon-size: var(--computed-icon-size);
|
9
|
+
--mdc-icon-border-radius: 0.25rem;
|
9
10
|
|
10
|
-
height: var(--mdc-icon-
|
11
|
-
width: var(--mdc-icon-
|
11
|
+
height: var(--mdc-icon-size);
|
12
|
+
width: var(--mdc-icon-size);
|
13
|
+
border-radius: var(--mdc-icon-border-radius);
|
12
14
|
}
|
13
15
|
:host::part(icon) {
|
14
16
|
height: 100%;
|
@@ -16,5 +18,6 @@ const styles = [
|
|
16
18
|
fill: var(--mdc-icon-fill-color);
|
17
19
|
}
|
18
20
|
`,
|
21
|
+
...hostFocusRingStyles(),
|
19
22
|
];
|
20
23
|
export default styles;
|
@@ -20,6 +20,8 @@ const dynamicSVGImport = async (url, name, fileExtension, signal) => {
|
|
20
20
|
const returnValue = new DOMParser().parseFromString(iconResponse, 'text/html').body.children[0];
|
21
21
|
returnValue.setAttribute('data-name', name);
|
22
22
|
returnValue.setAttribute('part', 'icon');
|
23
|
+
// set aria-hidden=true for SVG to avoid screen readers
|
24
|
+
returnValue.setAttribute('aria-hidden', 'true');
|
23
25
|
return returnValue;
|
24
26
|
};
|
25
27
|
export { dynamicSVGImport };
|
@@ -2359,7 +2359,7 @@
|
|
2359
2359
|
"declarations": [
|
2360
2360
|
{
|
2361
2361
|
"kind": "class",
|
2362
|
-
"description": "Icon component that dynamically displays SVG icons based on a valid name.\n\nThis component must be mounted within an `IconProvider` component.\n\nThe `IconProvider` defines the source URL from which icons are consumed.\nThe `Icon` component accepts a `name` attribute, which corresponds to\nthe file name of the icon to be loaded from the specified URL.\n\nOnce fetched, the icon will be rendered. If the fetching process is unsuccessful,\nno icon will be displayed.\n\nThe `size` attribute allows for dynamic sizing of the icon based on the provided\n`length-unit` attribute. This unit can either come from the `IconProvider`\nor can be overridden for each individual icon. For example:\nif `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be\n`width: 1em; height: 1em`.\n\nRegarding accessibility, there are
|
2362
|
+
"description": "Icon component that dynamically displays SVG icons based on a valid name.\n\nThis component must be mounted within an `IconProvider` component.\n\nThe `IconProvider` defines the source URL from which icons are consumed.\nThe `Icon` component accepts a `name` attribute, which corresponds to\nthe file name of the icon to be loaded from the specified URL.\n\nOnce fetched, the icon will be rendered. If the fetching process is unsuccessful,\nno icon will be displayed.\n\nThe `size` attribute allows for dynamic sizing of the icon based on the provided\n`length-unit` attribute. This unit can either come from the `IconProvider`\nor can be overridden for each individual icon. For example:\nif `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be\n`width: 1em; height: 1em`.\n\nRegarding accessibility, there are three types of icons: decorative, informative and informative standalone.\n\n### Decorative Icons\n- Decorative icons do not convey any essential information to the content of a page.\n- They should be hidden from screen readers (SR) to prevent confusion for users.\n- For decorative icons, an `aria-label` is not required, and the `role` will be set to null.\n\n### Informative Icons\n- Informative icons convey important information that is not adequately represented\n by surrounding text or components.\n- They provide valuable context and must be announced by assistive technologies.\n- For informative icons, an `aria-label` is required, and the `role` will be set to \"img\" automatically.\n- If an `aria-label` is provided, the role will be set to 'img'; if it is absent,\n the role will be unset.\n\n### Informative Standalone Icons\n- If an icon is informative (as mentioned above) and does not belong to a button (=standalone), it must\nhave a Tooltip that describes what it means.\n- For informative standalone icons, an `aria-label` & `tabindex=\"0\"` is required,\nand the `role` will be set to \"img\" automatically.\n- **Only use this when a Icon is standalone and is not part of a button or other interactive elements.**",
|
2363
2363
|
"name": "Icon",
|
2364
2364
|
"cssProperties": [
|
2365
2365
|
{
|
@@ -2445,17 +2445,6 @@
|
|
2445
2445
|
"privacy": "private",
|
2446
2446
|
"default": "new AbortController()"
|
2447
2447
|
},
|
2448
|
-
{
|
2449
|
-
"kind": "method",
|
2450
|
-
"name": "triggerIconLoaded",
|
2451
|
-
"privacy": "private",
|
2452
|
-
"return": {
|
2453
|
-
"type": {
|
2454
|
-
"text": "void"
|
2455
|
-
}
|
2456
|
-
},
|
2457
|
-
"description": "Dispatches a 'load' event on the component once the icon has been successfully loaded.\nThis event bubbles and is cancelable."
|
2458
|
-
},
|
2459
2448
|
{
|
2460
2449
|
"kind": "method",
|
2461
2450
|
"name": "getIconData",
|
@@ -2475,7 +2464,7 @@
|
|
2475
2464
|
"description": "The icon html element which has been fetched from the icon provider."
|
2476
2465
|
}
|
2477
2466
|
],
|
2478
|
-
"description": "Sets the iconData state to the fetched icon
|
2467
|
+
"description": "Sets the iconData state to the fetched icon.\nDispatches a 'load' event on the component once the icon has been successfully loaded."
|
2479
2468
|
},
|
2480
2469
|
{
|
2481
2470
|
"kind": "method",
|
@@ -2497,21 +2486,6 @@
|
|
2497
2486
|
"privacy": "private",
|
2498
2487
|
"description": "Updates the size by setting the width and height"
|
2499
2488
|
},
|
2500
|
-
{
|
2501
|
-
"kind": "method",
|
2502
|
-
"name": "setRoleOnIcon",
|
2503
|
-
"privacy": "private"
|
2504
|
-
},
|
2505
|
-
{
|
2506
|
-
"kind": "method",
|
2507
|
-
"name": "setAriaHiddenOnIcon",
|
2508
|
-
"privacy": "private"
|
2509
|
-
},
|
2510
|
-
{
|
2511
|
-
"kind": "method",
|
2512
|
-
"name": "setAriaLabelOnIcon",
|
2513
|
-
"privacy": "private"
|
2514
|
-
},
|
2515
2489
|
{
|
2516
2490
|
"kind": "field",
|
2517
2491
|
"name": "computedIconSize",
|
@@ -2559,7 +2533,7 @@
|
|
2559
2533
|
"module": "/src/models"
|
2560
2534
|
},
|
2561
2535
|
"tagName": "mdc-icon",
|
2562
|
-
"jsDoc": "/**\n * Icon component that dynamically displays SVG icons based on a valid name.\n *\n * This component must be mounted within an `IconProvider` component.\n *\n * The `IconProvider` defines the source URL from which icons are consumed.\n * The `Icon` component accepts a `name` attribute, which corresponds to\n * the file name of the icon to be loaded from the specified URL.\n *\n * Once fetched, the icon will be rendered. If the fetching process is unsuccessful,\n * no icon will be displayed.\n *\n * The `size` attribute allows for dynamic sizing of the icon based on the provided\n * `length-unit` attribute. This unit can either come from the `IconProvider`\n * or can be overridden for each individual icon. For example:\n * if `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be\n * `width: 1em; height: 1em`.\n *\n * Regarding accessibility, there are
|
2536
|
+
"jsDoc": "/**\n * Icon component that dynamically displays SVG icons based on a valid name.\n *\n * This component must be mounted within an `IconProvider` component.\n *\n * The `IconProvider` defines the source URL from which icons are consumed.\n * The `Icon` component accepts a `name` attribute, which corresponds to\n * the file name of the icon to be loaded from the specified URL.\n *\n * Once fetched, the icon will be rendered. If the fetching process is unsuccessful,\n * no icon will be displayed.\n *\n * The `size` attribute allows for dynamic sizing of the icon based on the provided\n * `length-unit` attribute. This unit can either come from the `IconProvider`\n * or can be overridden for each individual icon. For example:\n * if `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be\n * `width: 1em; height: 1em`.\n *\n * Regarding accessibility, there are three types of icons: decorative, informative and informative standalone.\n *\n * ### Decorative Icons\n * - Decorative icons do not convey any essential information to the content of a page.\n * - They should be hidden from screen readers (SR) to prevent confusion for users.\n * - For decorative icons, an `aria-label` is not required, and the `role` will be set to null.\n *\n * ### Informative Icons\n * - Informative icons convey important information that is not adequately represented\n * by surrounding text or components.\n * - They provide valuable context and must be announced by assistive technologies.\n * - For informative icons, an `aria-label` is required, and the `role` will be set to \"img\" automatically.\n * - If an `aria-label` is provided, the role will be set to 'img'; if it is absent,\n * the role will be unset.\n *\n * ### Informative Standalone Icons\n * - If an icon is informative (as mentioned above) and does not belong to a button (=standalone), it must\n * have a Tooltip that describes what it means.\n * - For informative standalone icons, an `aria-label` & `tabindex=\"0\"` is required,\n * and the `role` will be set to \"img\" automatically.\n * - **Only use this when a Icon is standalone and is not part of a button or other interactive elements.**\n *\n * @tagname mdc-icon\n *\n * @cssproperty --mdc-icon-fill-color - Allows customization of the default fill color.\n */",
|
2563
2537
|
"customElement": true
|
2564
2538
|
}
|
2565
2539
|
],
|
@@ -17,7 +17,7 @@ import Component from '../../components/icon';
|
|
17
17
|
* if `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be
|
18
18
|
* `width: 1em; height: 1em`.
|
19
19
|
*
|
20
|
-
* Regarding accessibility, there are
|
20
|
+
* Regarding accessibility, there are three types of icons: decorative, informative and informative standalone.
|
21
21
|
*
|
22
22
|
* ### Decorative Icons
|
23
23
|
* - Decorative icons do not convey any essential information to the content of a page.
|
@@ -28,10 +28,17 @@ import Component from '../../components/icon';
|
|
28
28
|
* - Informative icons convey important information that is not adequately represented
|
29
29
|
* by surrounding text or components.
|
30
30
|
* - They provide valuable context and must be announced by assistive technologies.
|
31
|
-
* - For informative icons, an `aria-label` is required, and the `role` will be set to "img".
|
31
|
+
* - For informative icons, an `aria-label` is required, and the `role` will be set to "img" automatically.
|
32
32
|
* - If an `aria-label` is provided, the role will be set to 'img'; if it is absent,
|
33
33
|
* the role will be unset.
|
34
34
|
*
|
35
|
+
* ### Informative Standalone Icons
|
36
|
+
* - If an icon is informative (as mentioned above) and does not belong to a button (=standalone), it must
|
37
|
+
* have a Tooltip that describes what it means.
|
38
|
+
* - For informative standalone icons, an `aria-label` & `tabindex="0"` is required,
|
39
|
+
* and the `role` will be set to "img" automatically.
|
40
|
+
* - **Only use this when a Icon is standalone and is not part of a button or other interactive elements.**
|
41
|
+
*
|
35
42
|
* @tagname mdc-icon
|
36
43
|
*
|
37
44
|
* @cssproperty --mdc-icon-fill-color - Allows customization of the default fill color.
|
package/dist/react/icon/index.js
CHANGED
@@ -20,7 +20,7 @@ import { TAG_NAME } from '../../components/icon/icon.constants';
|
|
20
20
|
* if `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be
|
21
21
|
* `width: 1em; height: 1em`.
|
22
22
|
*
|
23
|
-
* Regarding accessibility, there are
|
23
|
+
* Regarding accessibility, there are three types of icons: decorative, informative and informative standalone.
|
24
24
|
*
|
25
25
|
* ### Decorative Icons
|
26
26
|
* - Decorative icons do not convey any essential information to the content of a page.
|
@@ -31,10 +31,17 @@ import { TAG_NAME } from '../../components/icon/icon.constants';
|
|
31
31
|
* - Informative icons convey important information that is not adequately represented
|
32
32
|
* by surrounding text or components.
|
33
33
|
* - They provide valuable context and must be announced by assistive technologies.
|
34
|
-
* - For informative icons, an `aria-label` is required, and the `role` will be set to "img".
|
34
|
+
* - For informative icons, an `aria-label` is required, and the `role` will be set to "img" automatically.
|
35
35
|
* - If an `aria-label` is provided, the role will be set to 'img'; if it is absent,
|
36
36
|
* the role will be unset.
|
37
37
|
*
|
38
|
+
* ### Informative Standalone Icons
|
39
|
+
* - If an icon is informative (as mentioned above) and does not belong to a button (=standalone), it must
|
40
|
+
* have a Tooltip that describes what it means.
|
41
|
+
* - For informative standalone icons, an `aria-label` & `tabindex="0"` is required,
|
42
|
+
* and the `role` will be set to "img" automatically.
|
43
|
+
* - **Only use this when a Icon is standalone and is not part of a button or other interactive elements.**
|
44
|
+
*
|
38
45
|
* @tagname mdc-icon
|
39
46
|
*
|
40
47
|
* @cssproperty --mdc-icon-fill-color - Allows customization of the default fill color.
|
package/package.json
CHANGED