@momentum-design/components 0.107.1 → 0.108.1
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/dist/browser/index.js +169 -164
- package/dist/browser/index.js.map +4 -4
- package/dist/components/brandvisual/brandvisual.component.d.ts +9 -2
- package/dist/components/brandvisual/brandvisual.component.js +32 -14
- package/dist/components/brandvisual/brandvisual.constants.d.ts +1 -4
- package/dist/components/brandvisual/brandvisual.constants.js +1 -4
- package/dist/components/brandvisual/brandvisual.styles.js +5 -0
- package/dist/components/brandvisual/brandvisual.types.d.ts +4 -1
- package/dist/custom-elements.json +662 -590
- package/dist/react/brandvisual/index.d.ts +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +2 -2
- package/package.json +1 -1
@@ -1,4 +1,4 @@
|
|
1
|
-
import { CSSResult } from 'lit';
|
1
|
+
import { CSSResult, TemplateResult } from 'lit';
|
2
2
|
import { Component } from '../../models';
|
3
3
|
import type { BrandVisualNames } from './brandvisual.types';
|
4
4
|
/**
|
@@ -24,8 +24,15 @@ declare class Brandvisual extends Component {
|
|
24
24
|
* Name of the brandVisual (= filename)
|
25
25
|
*/
|
26
26
|
name?: BrandVisualNames;
|
27
|
+
/**
|
28
|
+
* Alt text for the brandvisual image for accessibility.
|
29
|
+
* This will only be set if the brandvisual is an image (png).
|
30
|
+
*/
|
31
|
+
altText?: string;
|
27
32
|
private getBrandVisualData;
|
28
33
|
updated(changedProperties: Map<string, any>): void;
|
34
|
+
private injectTemplateAttributes;
|
35
|
+
private injectHtmlAttributes;
|
29
36
|
/**
|
30
37
|
* Sets the brandVisualData state to the fetched brandvisual.
|
31
38
|
* Dispatches a 'load' event on the component once the brandvisual has been successfully loaded.
|
@@ -38,7 +45,7 @@ declare class Brandvisual extends Component {
|
|
38
45
|
* The error detail is set to the error object.
|
39
46
|
*/
|
40
47
|
private handleBrandVisualLoadedFailure;
|
41
|
-
render():
|
48
|
+
render(): TemplateResult<1>;
|
42
49
|
static styles: Array<CSSResult>;
|
43
50
|
}
|
44
51
|
export default Brandvisual;
|
@@ -11,7 +11,6 @@ import { html } from 'lit';
|
|
11
11
|
import { property, state } from 'lit/decorators.js';
|
12
12
|
import { Component } from '../../models';
|
13
13
|
import styles from './brandvisual.styles';
|
14
|
-
import { DEFAULTS } from './brandvisual.constants';
|
15
14
|
/**
|
16
15
|
* The `mdc-brandvisual` component is responsible for rendering logos dynamically & ensures they are
|
17
16
|
* displayed correctly within applications.
|
@@ -30,17 +29,10 @@ import { DEFAULTS } from './brandvisual.constants';
|
|
30
29
|
*
|
31
30
|
*/
|
32
31
|
class Brandvisual extends Component {
|
33
|
-
constructor() {
|
34
|
-
super(...arguments);
|
35
|
-
/**
|
36
|
-
* Name of the brandVisual (= filename)
|
37
|
-
*/
|
38
|
-
this.name = DEFAULTS.NAME;
|
39
|
-
}
|
40
32
|
async getBrandVisualData() {
|
41
33
|
if (this.name) {
|
42
34
|
// dynamic import of the lit template from the momentum brand-visuals package
|
43
|
-
return import(`@momentum-design/brand-visuals/dist/
|
35
|
+
return import(`@momentum-design/brand-visuals/dist/ts/${this.name}.ts`)
|
44
36
|
.then(module => {
|
45
37
|
this.handleBrandVisualLoadedSuccess(module.default());
|
46
38
|
})
|
@@ -48,8 +40,9 @@ class Brandvisual extends Component {
|
|
48
40
|
this.handleBrandVisualLoadedFailure(error);
|
49
41
|
});
|
50
42
|
}
|
51
|
-
|
52
|
-
|
43
|
+
const nameError = new Error('No brandvisual name provided.');
|
44
|
+
this.handleBrandVisualLoadedFailure(nameError);
|
45
|
+
return Promise.reject(nameError);
|
53
46
|
}
|
54
47
|
updated(changedProperties) {
|
55
48
|
super.updated(changedProperties);
|
@@ -61,6 +54,28 @@ class Brandvisual extends Component {
|
|
61
54
|
}
|
62
55
|
});
|
63
56
|
}
|
57
|
+
if (changedProperties.has('altText')) {
|
58
|
+
if (this.brandVisualData) {
|
59
|
+
this.brandVisualData = this.injectHtmlAttributes(this.brandVisualData, { alt: this.altText });
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
injectTemplateAttributes(litTemplate, tag, props) {
|
64
|
+
const parser = new DOMParser();
|
65
|
+
const doc = parser.parseFromString(litTemplate.strings[0], 'text/html');
|
66
|
+
const element = doc.querySelector(tag);
|
67
|
+
if (element) {
|
68
|
+
Object.entries(props).forEach(([key, value]) => {
|
69
|
+
element.setAttribute(key, value);
|
70
|
+
});
|
71
|
+
}
|
72
|
+
return element || litTemplate;
|
73
|
+
}
|
74
|
+
injectHtmlAttributes(html, props) {
|
75
|
+
Object.entries(props).forEach(([key, value]) => {
|
76
|
+
html.setAttribute(key, value);
|
77
|
+
});
|
78
|
+
return html;
|
64
79
|
}
|
65
80
|
/**
|
66
81
|
* Sets the brandVisualData state to the fetched brandvisual.
|
@@ -68,8 +83,7 @@ class Brandvisual extends Component {
|
|
68
83
|
* @param brandVisualHtml - The brandvisual html element which has been fetched from the brandvisual provider.
|
69
84
|
*/
|
70
85
|
handleBrandVisualLoadedSuccess(brandVisualHtml) {
|
71
|
-
|
72
|
-
this.brandVisualData = brandVisualHtml;
|
86
|
+
this.brandVisualData = this.injectTemplateAttributes(brandVisualHtml, 'img', { alt: this.altText });
|
73
87
|
// when brandvisual is imported successfully, trigger brandvisual load event.
|
74
88
|
const loadEvent = new Event('load', {
|
75
89
|
bubbles: true,
|
@@ -97,10 +111,14 @@ class Brandvisual extends Component {
|
|
97
111
|
Brandvisual.styles = [...Component.styles, ...styles];
|
98
112
|
__decorate([
|
99
113
|
state(),
|
100
|
-
__metadata("design:type",
|
114
|
+
__metadata("design:type", Object)
|
101
115
|
], Brandvisual.prototype, "brandVisualData", void 0);
|
102
116
|
__decorate([
|
103
117
|
property({ type: String, reflect: true }),
|
104
118
|
__metadata("design:type", String)
|
105
119
|
], Brandvisual.prototype, "name", void 0);
|
120
|
+
__decorate([
|
121
|
+
property({ type: String, reflect: true }),
|
122
|
+
__metadata("design:type", String)
|
123
|
+
], Brandvisual.prototype, "altText", void 0);
|
106
124
|
export default Brandvisual;
|