@momentum-design/components 0.41.6 → 0.42.0

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.
@@ -0,0 +1,44 @@
1
+ import { CSSResult } from 'lit';
2
+ import { Component } from '../../models';
3
+ import type { BrandVisualNames } from './brandvisual.types';
4
+ /**
5
+ * The `mdc-brandvisual` component is responsible for rendering logos dynamically & ensures they are
6
+ * displayed correctly within applications.
7
+ *
8
+ * Features:
9
+ * - Dynamically loads brandvisuals based on the `name` attribute.
10
+ * - Emits a `load` event when the brandvisual is successfully fetched.
11
+ * - Emits an `error` event when the brandvisual import fails.
12
+ * - Supports accessibility best practices.
13
+ * - Used for brand representation within the design system.
14
+ *
15
+ * @tagname mdc-brandvisual
16
+ *
17
+ * @event load - (React: onLoad) This event is dispatched when the brandvisual has been successfully loaded.
18
+ * @event error - (React: onError) This event is dispatched when the brandvisual fetching has failed.
19
+ *
20
+ */
21
+ declare class Brandvisual extends Component {
22
+ private brandVisualData?;
23
+ /**
24
+ * Name of the brandVisual (= filename)
25
+ */
26
+ name?: BrandVisualNames;
27
+ private getBrandVisualData;
28
+ updated(changedProperties: Map<string, any>): void;
29
+ /**
30
+ * Sets the brandVisualData state to the fetched brandvisual.
31
+ * Dispatches a 'load' event on the component once the brandvisual has been successfully loaded.
32
+ * @param brandVisualHtml - The brandvisual html element which has been fetched from the brandvisual provider.
33
+ */
34
+ private handleBrandVisualLoadedSuccess;
35
+ /**
36
+ * Dispatches an 'error' event on the component when the brandvisual import has failed.
37
+ * This event bubbles and is cancelable.
38
+ * The error detail is set to the error object.
39
+ */
40
+ private handleBrandVisualLoadedFailure;
41
+ render(): import("lit-html").TemplateResult<1>;
42
+ static styles: Array<CSSResult>;
43
+ }
44
+ export default Brandvisual;
@@ -0,0 +1,106 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { html } from 'lit';
11
+ import { property, state } from 'lit/decorators.js';
12
+ import styles from './brandvisual.styles';
13
+ import { Component } from '../../models';
14
+ import { DEFAULTS } from './brandvisual.constants';
15
+ /**
16
+ * The `mdc-brandvisual` component is responsible for rendering logos dynamically & ensures they are
17
+ * displayed correctly within applications.
18
+ *
19
+ * Features:
20
+ * - Dynamically loads brandvisuals based on the `name` attribute.
21
+ * - Emits a `load` event when the brandvisual is successfully fetched.
22
+ * - Emits an `error` event when the brandvisual import fails.
23
+ * - Supports accessibility best practices.
24
+ * - Used for brand representation within the design system.
25
+ *
26
+ * @tagname mdc-brandvisual
27
+ *
28
+ * @event load - (React: onLoad) This event is dispatched when the brandvisual has been successfully loaded.
29
+ * @event error - (React: onError) This event is dispatched when the brandvisual fetching has failed.
30
+ *
31
+ */
32
+ class Brandvisual extends Component {
33
+ constructor() {
34
+ super(...arguments);
35
+ /**
36
+ * Name of the brandVisual (= filename)
37
+ */
38
+ this.name = DEFAULTS.NAME;
39
+ }
40
+ async getBrandVisualData() {
41
+ if (this.name) {
42
+ // dynamic import of the lit template from the momentum brand-visuals package
43
+ return import(`@momentum-design/brand-visuals/dist/logos/ts/${this.name}.ts`)
44
+ .then((module) => {
45
+ this.handleBrandVisualLoadedSuccess(module.default());
46
+ })
47
+ .catch((error) => {
48
+ this.handleBrandVisualLoadedFailure(error);
49
+ });
50
+ }
51
+ this.handleBrandVisualLoadedFailure(new Error('No brandvisual name provided.'));
52
+ return Promise.reject(new Error('No brandvisual name provided.'));
53
+ }
54
+ updated(changedProperties) {
55
+ super.updated(changedProperties);
56
+ if (changedProperties.has('name')) {
57
+ // import brandVisual data if name changes:
58
+ this.getBrandVisualData().catch((err) => {
59
+ if (this.onerror) {
60
+ this.onerror(err);
61
+ }
62
+ });
63
+ }
64
+ }
65
+ /**
66
+ * Sets the brandVisualData state to the fetched brandvisual.
67
+ * Dispatches a 'load' event on the component once the brandvisual has been successfully loaded.
68
+ * @param brandVisualHtml - The brandvisual html element which has been fetched from the brandvisual provider.
69
+ */
70
+ handleBrandVisualLoadedSuccess(brandVisualHtml) {
71
+ // update brandVisualData state once fetched:
72
+ this.brandVisualData = brandVisualHtml;
73
+ // when brandvisual is imported successfully, trigger brandvisual load event.
74
+ const loadEvent = new Event('load', {
75
+ bubbles: true,
76
+ cancelable: true,
77
+ });
78
+ this.dispatchEvent(loadEvent);
79
+ }
80
+ /**
81
+ * Dispatches an 'error' event on the component when the brandvisual import has failed.
82
+ * This event bubbles and is cancelable.
83
+ * The error detail is set to the error object.
84
+ */
85
+ handleBrandVisualLoadedFailure(error) {
86
+ const errorEvent = new CustomEvent('error', {
87
+ bubbles: true,
88
+ cancelable: true,
89
+ detail: { error },
90
+ });
91
+ this.dispatchEvent(errorEvent);
92
+ }
93
+ render() {
94
+ return html ` ${this.brandVisualData} `;
95
+ }
96
+ }
97
+ Brandvisual.styles = [...Component.styles, ...styles];
98
+ __decorate([
99
+ state(),
100
+ __metadata("design:type", HTMLElement)
101
+ ], Brandvisual.prototype, "brandVisualData", void 0);
102
+ __decorate([
103
+ property({ type: String, reflect: true }),
104
+ __metadata("design:type", String)
105
+ ], Brandvisual.prototype, "name", void 0);
106
+ export default Brandvisual;
@@ -0,0 +1,5 @@
1
+ declare const TAG_NAME: "mdc-brandvisual";
2
+ declare const DEFAULTS: {
3
+ readonly NAME: undefined;
4
+ };
5
+ export { TAG_NAME, DEFAULTS };
@@ -0,0 +1,6 @@
1
+ import utils from '../../utils/tag-name';
2
+ const TAG_NAME = utils.constructTagName('brandvisual');
3
+ const DEFAULTS = {
4
+ NAME: undefined,
5
+ };
6
+ export { TAG_NAME, DEFAULTS };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("lit").CSSResult[];
2
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import { css } from 'lit';
2
+ const styles = css `
3
+ :host {
4
+ display: block;
5
+ }
6
+ :host::part(brandvisual) {
7
+ height: 100%;
8
+ width: 100%;
9
+ }
10
+ `;
11
+ export default [styles];
@@ -0,0 +1,2 @@
1
+ import type BrandVisualNames from '@momentum-design/brand-visuals/dist/types/types';
2
+ export type { BrandVisualNames };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import Brandvisual from './brandvisual.component';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ ['mdc-brandvisual']: Brandvisual;
5
+ }
6
+ }
7
+ export default Brandvisual;
@@ -0,0 +1,4 @@
1
+ import Brandvisual from './brandvisual.component';
2
+ import { TAG_NAME } from './brandvisual.constants';
3
+ Brandvisual.register(TAG_NAME);
4
+ export default Brandvisual;