@momentum-design/components 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,24 +1,40 @@
1
1
  import { Component } from '../../models';
2
2
  /**
3
- * Icon component, which has to be mounted inside of a `IconProvider`
4
- * component.
3
+ * Icon component that dynamically displays SVG icons based on a valid name.
5
4
  *
6
- * The `IconProvider` component defines where icons should be consumed from (`url`).
7
- * This `Icon` component accepts the `name` attribute, which will be
8
- * the file name of the icon to be loaded from the given `url`.
5
+ * This component must be mounted within an `IconProvider` component.
9
6
  *
10
- * Once fetched, the icon will be mounted. If fetching wasn't successful,
11
- * nothing will be shown.
7
+ * The `IconProvider` defines the source URL from which icons are consumed.
8
+ * The `Icon` component accepts a `name` attribute, which corresponds to
9
+ * the file name of the icon to be loaded from the specified URL.
12
10
  *
13
- * The `size` attribute allows sizing the icon based on the provided
14
- * `length-unit` attribute (which will either come from the IconProvider or
15
- * could be overridden per icon). For example:
16
- * if `size = 1` and `length-unit = 'em'`, the size of the icon will be
11
+ * Once fetched, the icon will be rendered. If the fetching process is unsuccessful,
12
+ * no icon will be displayed.
13
+ *
14
+ * The `size` attribute allows for dynamic sizing of the icon based on the provided
15
+ * `length-unit` attribute. This unit can either come from the `IconProvider`
16
+ * or can be overridden for each individual icon. For example:
17
+ * if `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be
17
18
  * `width: 1em; height: 1em`.
18
19
  *
19
- * For accessibility the `role` and `aria-label` of the icon can be set.
20
+ * Regarding accessibility, there are two types of icons: decorative and informative.
21
+ *
22
+ * ### Decorative Icons
23
+ * - Decorative icons do not convey any essential information to the content of a page.
24
+ * - They should be hidden from screen readers (SR) to prevent confusion for users.
25
+ * - For decorative icons, an `aria-label` is not required, and the `role` will be set to null.
26
+ *
27
+ * ### Informative Icons
28
+ * - Informative icons convey important information that is not adequately represented
29
+ * by surrounding text or components.
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".
32
+ * - If an `aria-label` is provided, the role will be set to 'img'; if it is absent,
33
+ * the role will be unset.
20
34
  *
21
35
  * @tagname mdc-icon
36
+ *
37
+ * @cssproperty --mdc-icon-fill-color - Allows customization of the default fill color.
22
38
  */
23
39
  declare class Icon extends Component {
24
40
  private iconData?;
@@ -36,10 +52,6 @@ declare class Icon extends Component {
36
52
  * Length unit attribute for overriding length-unit from `IconProvider`
37
53
  */
38
54
  lengthUnit?: string;
39
- /**
40
- * Role attribute to be set for accessibility
41
- */
42
- role: string | null;
43
55
  /**
44
56
  * Aria-label attribute to be set for accessibility
45
57
  */
@@ -55,6 +67,7 @@ declare class Icon extends Component {
55
67
  */
56
68
  private updateSize;
57
69
  private setRoleOnIcon;
70
+ private setAriaHiddenOnIcon;
58
71
  private setAriaLabelOnIcon;
59
72
  private get computedIconSize();
60
73
  updated(changedProperties: Map<string, any>): void;
@@ -10,25 +10,41 @@ const iconprovider_component_1 = tslib_1.__importDefault(require("../iconprovide
10
10
  const icon_utils_1 = require("./icon.utils");
11
11
  const icon_constants_1 = require("./icon.constants");
12
12
  /**
13
- * Icon component, which has to be mounted inside of a `IconProvider`
14
- * component.
13
+ * Icon component that dynamically displays SVG icons based on a valid name.
15
14
  *
16
- * The `IconProvider` component defines where icons should be consumed from (`url`).
17
- * This `Icon` component accepts the `name` attribute, which will be
18
- * the file name of the icon to be loaded from the given `url`.
15
+ * This component must be mounted within an `IconProvider` component.
19
16
  *
20
- * Once fetched, the icon will be mounted. If fetching wasn't successful,
21
- * nothing will be shown.
17
+ * The `IconProvider` defines the source URL from which icons are consumed.
18
+ * The `Icon` component accepts a `name` attribute, which corresponds to
19
+ * the file name of the icon to be loaded from the specified URL.
22
20
  *
23
- * The `size` attribute allows sizing the icon based on the provided
24
- * `length-unit` attribute (which will either come from the IconProvider or
25
- * could be overridden per icon). For example:
26
- * if `size = 1` and `length-unit = 'em'`, the size of the icon will be
21
+ * Once fetched, the icon will be rendered. If the fetching process is unsuccessful,
22
+ * no icon will be displayed.
23
+ *
24
+ * The `size` attribute allows for dynamic sizing of the icon based on the provided
25
+ * `length-unit` attribute. This unit can either come from the `IconProvider`
26
+ * or can be overridden for each individual icon. For example:
27
+ * if `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be
27
28
  * `width: 1em; height: 1em`.
28
29
  *
29
- * For accessibility the `role` and `aria-label` of the icon can be set.
30
+ * Regarding accessibility, there are two types of icons: decorative and informative.
31
+ *
32
+ * ### Decorative Icons
33
+ * - Decorative icons do not convey any essential information to the content of a page.
34
+ * - They should be hidden from screen readers (SR) to prevent confusion for users.
35
+ * - For decorative icons, an `aria-label` is not required, and the `role` will be set to null.
36
+ *
37
+ * ### Informative Icons
38
+ * - Informative icons convey important information that is not adequately represented
39
+ * by surrounding text or components.
40
+ * - They provide valuable context and must be announced by assistive technologies.
41
+ * - For informative icons, an `aria-label` is required, and the `role` will be set to "img".
42
+ * - If an `aria-label` is provided, the role will be set to 'img'; if it is absent,
43
+ * the role will be unset.
30
44
  *
31
45
  * @tagname mdc-icon
46
+ *
47
+ * @cssproperty --mdc-icon-fill-color - Allows customization of the default fill color.
32
48
  */
33
49
  class Icon extends models_1.Component {
34
50
  constructor() {
@@ -37,10 +53,6 @@ class Icon extends models_1.Component {
37
53
  * Name of the icon (= filename)
38
54
  */
39
55
  this.name = icon_constants_1.DEFAULTS.NAME;
40
- /**
41
- * Role attribute to be set for accessibility
42
- */
43
- this.role = null;
44
56
  /**
45
57
  * Aria-label attribute to be set for accessibility
46
58
  */
@@ -61,6 +73,7 @@ class Icon extends models_1.Component {
61
73
  // when icon got fetched, set role and aria-label:
62
74
  this.setRoleOnIcon();
63
75
  this.setAriaLabelOnIcon();
76
+ this.setAriaHiddenOnIcon();
64
77
  }
65
78
  }
66
79
  }
@@ -76,14 +89,12 @@ class Icon extends models_1.Component {
76
89
  }
77
90
  }
78
91
  setRoleOnIcon() {
79
- var _a, _b;
80
- if (this.role) {
81
- // pass through role attribute to svg if set on mdc-icon
82
- (_a = this.iconData) === null || _a === void 0 ? void 0 : _a.setAttribute('role', this.role);
83
- }
84
- else {
85
- (_b = this.iconData) === null || _b === void 0 ? void 0 : _b.removeAttribute('role');
86
- }
92
+ this.role = this.ariaLabel ? 'img' : null;
93
+ }
94
+ setAriaHiddenOnIcon() {
95
+ var _a;
96
+ // set aria-hidden=true for SVG to avoid screen readers
97
+ (_a = this.iconData) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-hidden', 'true');
87
98
  }
88
99
  setAriaLabelOnIcon() {
89
100
  var _a, _b;
@@ -105,13 +116,12 @@ class Icon extends models_1.Component {
105
116
  if (changedProperties.has('name')) {
106
117
  // fetch icon data if name changes:
107
118
  this.getIconData().catch((err) => {
119
+ // eslint-disable-next-line no-console
108
120
  console.error(err);
109
121
  });
110
122
  }
111
- if (changedProperties.has('role')) {
112
- this.setRoleOnIcon();
113
- }
114
123
  if (changedProperties.has('ariaLabel')) {
124
+ this.setRoleOnIcon();
115
125
  this.setAriaLabelOnIcon();
116
126
  }
117
127
  if (changedProperties.has('size') || changedProperties.has('lengthUnit')) {
@@ -155,10 +165,6 @@ tslib_1.__decorate([
155
165
  (0, decorators_js_1.property)({ type: String, attribute: 'length-unit' }),
156
166
  tslib_1.__metadata("design:type", String)
157
167
  ], Icon.prototype, "lengthUnit", void 0);
158
- tslib_1.__decorate([
159
- (0, decorators_js_1.property)({ type: String }),
160
- tslib_1.__metadata("design:type", Object)
161
- ], Icon.prototype, "role", void 0);
162
168
  tslib_1.__decorate([
163
169
  (0, decorators_js_1.property)({ type: String, attribute: 'aria-label' }),
164
170
  tslib_1.__metadata("design:type", Object)
@@ -5,10 +5,13 @@ const styles_1 = require("../../utils/styles");
5
5
  const styles = [
6
6
  styles_1.hostFitContentStyles,
7
7
  (0, lit_1.css) `
8
+ :host {
9
+ --mdc-icon-fill-color: currentColor;
10
+ }
8
11
  svg {
9
12
  height: 100%;
10
13
  width: 100%;
11
- fill: currentColor;
14
+ fill: var(--mdc-icon-fill-color);
12
15
  }
13
16
  `,
14
17
  ];
@@ -1,2 +1,12 @@
1
+ /**
2
+ * Fetches a dynamic SVG icon based on the provided `url`, `name` and `fileExtension`.
3
+ * It will throw an error if the response is not ok.
4
+ *
5
+ * @param url - The base url of the icon
6
+ * @param name - The name of the icon
7
+ * @param fileExtension - The file extension of the icon
8
+ * @returns The valid icon element
9
+ * @throws Error if the response is not ok
10
+ */
1
11
  declare const dynamicSVGImport: (url: string, name: string, fileExtension: string) => Promise<Element>;
2
12
  export { dynamicSVGImport };
@@ -2,12 +2,22 @@
2
2
  /* eslint-disable implicit-arrow-linebreak */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.dynamicSVGImport = void 0;
5
- const dynamicSVGImport = async (url, name, fileExtension) => fetch(`${url}/${name}.${fileExtension}`)
6
- .then((response) => {
5
+ /**
6
+ * Fetches a dynamic SVG icon based on the provided `url`, `name` and `fileExtension`.
7
+ * It will throw an error if the response is not ok.
8
+ *
9
+ * @param url - The base url of the icon
10
+ * @param name - The name of the icon
11
+ * @param fileExtension - The file extension of the icon
12
+ * @returns The valid icon element
13
+ * @throws Error if the response is not ok
14
+ */
15
+ const dynamicSVGImport = async (url, name, fileExtension) => {
16
+ const response = await fetch(`${url}/${name}.${fileExtension}`);
7
17
  if (!response.ok) {
8
18
  throw new Error('There was a problem while fetching the icon!');
9
19
  }
10
- return response.text();
11
- })
12
- .then((iconResponse) => new DOMParser().parseFromString(iconResponse, 'text/html').body.children[0]);
20
+ const iconResponse = await response.text();
21
+ return new DOMParser().parseFromString(iconResponse, 'text/html').body.children[0];
22
+ };
13
23
  exports.dynamicSVGImport = dynamicSVGImport;
@@ -120,8 +120,14 @@
120
120
  "declarations": [
121
121
  {
122
122
  "kind": "class",
123
- "description": "Icon component, which has to be mounted inside of a `IconProvider`\ncomponent.\n\nThe `IconProvider` component defines where icons should be consumed from (`url`).\nThis `Icon` component accepts the `name` attribute, which will be\nthe file name of the icon to be loaded from the given `url`.\n\nOnce fetched, the icon will be mounted. If fetching wasn't successful,\nnothing will be shown.\n\nThe `size` attribute allows sizing the icon based on the provided\n`length-unit` attribute (which will either come from the IconProvider or\ncould be overridden per icon). For example:\nif `size = 1` and `length-unit = 'em'`, the size of the icon will be\n`width: 1em; height: 1em`.\n\nFor accessibility the `role` and `aria-label` of the icon can be set.",
123
+ "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 two types of icons: decorative and informative.\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\".\n- If an `aria-label` is provided, the role will be set to 'img'; if it is absent,\n the role will be unset.",
124
124
  "name": "Icon",
125
+ "cssProperties": [
126
+ {
127
+ "description": "Allows customization of the default fill color.",
128
+ "name": "--mdc-icon-fill-color"
129
+ }
130
+ ],
125
131
  "members": [
126
132
  {
127
133
  "kind": "field",
@@ -175,16 +181,6 @@
175
181
  "description": "Length unit attribute for overriding length-unit from `IconProvider`",
176
182
  "attribute": "length-unit"
177
183
  },
178
- {
179
- "kind": "field",
180
- "name": "role",
181
- "type": {
182
- "text": "string | null"
183
- },
184
- "default": "null",
185
- "description": "Role attribute to be set for accessibility",
186
- "attribute": "role"
187
- },
188
184
  {
189
185
  "kind": "field",
190
186
  "name": "ariaLabel",
@@ -218,6 +214,11 @@
218
214
  "name": "setRoleOnIcon",
219
215
  "privacy": "private"
220
216
  },
217
+ {
218
+ "kind": "method",
219
+ "name": "setAriaHiddenOnIcon",
220
+ "privacy": "private"
221
+ },
221
222
  {
222
223
  "kind": "method",
223
224
  "name": "setAriaLabelOnIcon",
@@ -255,15 +256,6 @@
255
256
  "description": "Length unit attribute for overriding length-unit from `IconProvider`",
256
257
  "fieldName": "lengthUnit"
257
258
  },
258
- {
259
- "name": "role",
260
- "type": {
261
- "text": "string | null"
262
- },
263
- "default": "null",
264
- "description": "Role attribute to be set for accessibility",
265
- "fieldName": "role"
266
- },
267
259
  {
268
260
  "name": "aria-label",
269
261
  "type": {
@@ -279,7 +271,7 @@
279
271
  "module": "/src/models"
280
272
  },
281
273
  "tagName": "mdc-icon",
282
- "jsDoc": "/**\n * Icon component, which has to be mounted inside of a `IconProvider`\n * component.\n *\n * The `IconProvider` component defines where icons should be consumed from (`url`).\n * This `Icon` component accepts the `name` attribute, which will be\n * the file name of the icon to be loaded from the given `url`.\n *\n * Once fetched, the icon will be mounted. If fetching wasn't successful,\n * nothing will be shown.\n *\n * The `size` attribute allows sizing the icon based on the provided\n * `length-unit` attribute (which will either come from the IconProvider or\n * could be overridden per icon). For example:\n * if `size = 1` and `length-unit = 'em'`, the size of the icon will be\n * `width: 1em; height: 1em`.\n *\n * For accessibility the `role` and `aria-label` of the icon can be set.\n *\n * @tagname mdc-icon\n */",
274
+ "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 two types of icons: decorative and informative.\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\".\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 * @tagname mdc-icon\n *\n * @cssproperty --mdc-icon-fill-color - Allows customization of the default fill color.\n */",
283
275
  "customElement": true
284
276
  }
285
277
  ],
@@ -1,24 +1,40 @@
1
1
  import Component from '../../components/icon';
2
2
  /**
3
- * Icon component, which has to be mounted inside of a `IconProvider`
4
- * component.
3
+ * Icon component that dynamically displays SVG icons based on a valid name.
5
4
  *
6
- * The `IconProvider` component defines where icons should be consumed from (`url`).
7
- * This `Icon` component accepts the `name` attribute, which will be
8
- * the file name of the icon to be loaded from the given `url`.
5
+ * This component must be mounted within an `IconProvider` component.
9
6
  *
10
- * Once fetched, the icon will be mounted. If fetching wasn't successful,
11
- * nothing will be shown.
7
+ * The `IconProvider` defines the source URL from which icons are consumed.
8
+ * The `Icon` component accepts a `name` attribute, which corresponds to
9
+ * the file name of the icon to be loaded from the specified URL.
12
10
  *
13
- * The `size` attribute allows sizing the icon based on the provided
14
- * `length-unit` attribute (which will either come from the IconProvider or
15
- * could be overridden per icon). For example:
16
- * if `size = 1` and `length-unit = 'em'`, the size of the icon will be
11
+ * Once fetched, the icon will be rendered. If the fetching process is unsuccessful,
12
+ * no icon will be displayed.
13
+ *
14
+ * The `size` attribute allows for dynamic sizing of the icon based on the provided
15
+ * `length-unit` attribute. This unit can either come from the `IconProvider`
16
+ * or can be overridden for each individual icon. For example:
17
+ * if `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be
17
18
  * `width: 1em; height: 1em`.
18
19
  *
19
- * For accessibility the `role` and `aria-label` of the icon can be set.
20
+ * Regarding accessibility, there are two types of icons: decorative and informative.
21
+ *
22
+ * ### Decorative Icons
23
+ * - Decorative icons do not convey any essential information to the content of a page.
24
+ * - They should be hidden from screen readers (SR) to prevent confusion for users.
25
+ * - For decorative icons, an `aria-label` is not required, and the `role` will be set to null.
26
+ *
27
+ * ### Informative Icons
28
+ * - Informative icons convey important information that is not adequately represented
29
+ * by surrounding text or components.
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".
32
+ * - If an `aria-label` is provided, the role will be set to 'img'; if it is absent,
33
+ * the role will be unset.
20
34
  *
21
35
  * @tagname mdc-icon
36
+ *
37
+ * @cssproperty --mdc-icon-fill-color - Allows customization of the default fill color.
22
38
  */
23
39
  declare const reactWrapper: import("@lit/react").ReactWebComponent<Component, {}>;
24
40
  export default reactWrapper;
@@ -6,25 +6,41 @@ const react_1 = require("@lit/react");
6
6
  const icon_1 = tslib_1.__importDefault(require("../../components/icon"));
7
7
  const icon_constants_1 = require("../../components/icon/icon.constants");
8
8
  /**
9
- * Icon component, which has to be mounted inside of a `IconProvider`
10
- * component.
9
+ * Icon component that dynamically displays SVG icons based on a valid name.
11
10
  *
12
- * The `IconProvider` component defines where icons should be consumed from (`url`).
13
- * This `Icon` component accepts the `name` attribute, which will be
14
- * the file name of the icon to be loaded from the given `url`.
11
+ * This component must be mounted within an `IconProvider` component.
15
12
  *
16
- * Once fetched, the icon will be mounted. If fetching wasn't successful,
17
- * nothing will be shown.
13
+ * The `IconProvider` defines the source URL from which icons are consumed.
14
+ * The `Icon` component accepts a `name` attribute, which corresponds to
15
+ * the file name of the icon to be loaded from the specified URL.
18
16
  *
19
- * The `size` attribute allows sizing the icon based on the provided
20
- * `length-unit` attribute (which will either come from the IconProvider or
21
- * could be overridden per icon). For example:
22
- * if `size = 1` and `length-unit = 'em'`, the size of the icon will be
17
+ * Once fetched, the icon will be rendered. If the fetching process is unsuccessful,
18
+ * no icon will be displayed.
19
+ *
20
+ * The `size` attribute allows for dynamic sizing of the icon based on the provided
21
+ * `length-unit` attribute. This unit can either come from the `IconProvider`
22
+ * or can be overridden for each individual icon. For example:
23
+ * if `size = 1` and `length-unit = 'em'`, the dimensions of the icon will be
23
24
  * `width: 1em; height: 1em`.
24
25
  *
25
- * For accessibility the `role` and `aria-label` of the icon can be set.
26
+ * Regarding accessibility, there are two types of icons: decorative and informative.
27
+ *
28
+ * ### Decorative Icons
29
+ * - Decorative icons do not convey any essential information to the content of a page.
30
+ * - They should be hidden from screen readers (SR) to prevent confusion for users.
31
+ * - For decorative icons, an `aria-label` is not required, and the `role` will be set to null.
32
+ *
33
+ * ### Informative Icons
34
+ * - Informative icons convey important information that is not adequately represented
35
+ * by surrounding text or components.
36
+ * - They provide valuable context and must be announced by assistive technologies.
37
+ * - For informative icons, an `aria-label` is required, and the `role` will be set to "img".
38
+ * - If an `aria-label` is provided, the role will be set to 'img'; if it is absent,
39
+ * the role will be unset.
26
40
  *
27
41
  * @tagname mdc-icon
42
+ *
43
+ * @cssproperty --mdc-icon-fill-color - Allows customization of the default fill color.
28
44
  */
29
45
  const reactWrapper = (0, react_1.createComponent)({
30
46
  tagName: icon_constants_1.TAG_NAME,
package/package.json CHANGED
@@ -37,5 +37,5 @@
37
37
  "@momentum-design/icons": "*",
38
38
  "@momentum-design/tokens": "*"
39
39
  },
40
- "version": "0.1.8"
40
+ "version": "0.1.9"
41
41
  }