@momentum-design/components 0.104.4 → 0.104.5

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.
@@ -54,10 +54,10 @@ export { default as Radio } from './radio';
54
54
  export { default as RadioGroup } from './radiogroup';
55
55
  export { default as ScreenreaderAnnouncer } from './screenreaderannouncer';
56
56
  export { default as Searchfield } from './searchfield';
57
- export { default as Select } from './select';
58
57
  export { default as Selectlistbox } from './selectlistbox';
59
- export { default as SideNavigation } from './sidenavigation';
58
+ export { default as Select } from './select';
60
59
  export { default as Skeleton } from './skeleton';
60
+ export { default as SideNavigation } from './sidenavigation';
61
61
  export { default as Spinner } from './spinner';
62
62
  export { default as StaticCheckbox } from './staticcheckbox';
63
63
  export { default as StaticRadio } from './staticradio';
@@ -54,10 +54,10 @@ export { default as Radio } from './radio';
54
54
  export { default as RadioGroup } from './radiogroup';
55
55
  export { default as ScreenreaderAnnouncer } from './screenreaderannouncer';
56
56
  export { default as Searchfield } from './searchfield';
57
- export { default as Select } from './select';
58
57
  export { default as Selectlistbox } from './selectlistbox';
59
- export { default as SideNavigation } from './sidenavigation';
58
+ export { default as Select } from './select';
60
59
  export { default as Skeleton } from './skeleton';
60
+ export { default as SideNavigation } from './sidenavigation';
61
61
  export { default as Spinner } from './spinner';
62
62
  export { default as StaticCheckbox } from './staticcheckbox';
63
63
  export { default as StaticRadio } from './staticradio';
@@ -0,0 +1,14 @@
1
+ import { LitElement } from 'lit';
2
+ import type { Component } from '../../models';
3
+ import type { Constructor } from './index.types';
4
+ export declare abstract class BackdropMixinInterface {
5
+ abstract zIndex: number;
6
+ protected backdropElement: HTMLElement | null;
7
+ protected isBackdropInvisible?: boolean;
8
+ protected backdropAppendTo?: string;
9
+ protected createBackdrop(classNamePrefix: string): void;
10
+ protected removeBackdrop(): void;
11
+ protected keepElementAboveBackdrop(element?: HTMLElement | null): void;
12
+ protected moveElementBackAfterBackdropRemoval(element?: HTMLElement | null): void;
13
+ }
14
+ export declare const BackdropMixin: <T extends Constructor<LitElement>>(superClass: T) => Constructor<Component & BackdropMixinInterface> & T;
@@ -0,0 +1,99 @@
1
+ export const BackdropMixin = (superClass) => {
2
+ class Backdrop extends superClass {
3
+ constructor() {
4
+ super(...arguments);
5
+ /**
6
+ * Set this property to true to make the backdrop invisible.
7
+ * This is useful for components that do want a backdrop which stops interaction,
8
+ * but do not want the backdrop to be visible.
9
+ * @internal
10
+ */
11
+ this.isBackdropInvisible = false;
12
+ /** @internal */
13
+ this.backdropElement = null;
14
+ }
15
+ /**
16
+ * Creates a backdrop element with the specified class name prefix.
17
+ *
18
+ * @param classNamePrefix - The prefix for the backdrop class name.
19
+ * @internal
20
+ */
21
+ createBackdrop(classNamePrefix) {
22
+ const backdrop = document.createElement('div');
23
+ backdrop.classList.add(`${classNamePrefix}-backdrop`);
24
+ const styleElement = document.createElement('style');
25
+ styleElement.textContent = `
26
+ .${classNamePrefix}-backdrop {
27
+ position: fixed;
28
+ top: 0;
29
+ left: 0;
30
+ width: 100%;
31
+ height: 100%;
32
+ background: ${this.isBackdropInvisible ? `transparent` : `var(--mds-color-theme-common-overlays-secondary-normal)`};
33
+ z-index: ${this.zIndex - 1};
34
+ }
35
+ `;
36
+ backdrop.appendChild(styleElement);
37
+ const backdropAppendToElement = document.getElementById(this.backdropAppendTo);
38
+ const elementToAppendTo = backdropAppendToElement || this.parentElement;
39
+ elementToAppendTo === null || elementToAppendTo === void 0 ? void 0 : elementToAppendTo.appendChild(backdrop);
40
+ this.backdropElement = backdrop;
41
+ }
42
+ /**
43
+ * Removes the backdrop element if it exists.
44
+ * @internal
45
+ */
46
+ removeBackdrop() {
47
+ if (this.backdropElement) {
48
+ this.backdropElement.remove();
49
+ this.backdropElement = null;
50
+ }
51
+ }
52
+ /**
53
+ * Keeps the specified element above the backdrop by adjusting its z-index and position.
54
+ *
55
+ * This method stores the original z-index and position of the element,
56
+ * and sets the z-index to the component's zIndex value.
57
+ * If the element's position is not already set to 'fixed' or 'absolute',
58
+ * it will be set to 'relative'.
59
+ * @param element - The element to keep above the backdrop.
60
+ * @internal
61
+ */
62
+ keepElementAboveBackdrop(element) {
63
+ if (!element) {
64
+ return;
65
+ }
66
+ // Store the original z-index and position of the element
67
+ this.elementOriginalStyle = {
68
+ zIndex: element.style.zIndex,
69
+ position: element.style.position,
70
+ };
71
+ // Set the z-index and position to ensure the element is above the backdrop
72
+ element.style.zIndex = `${this.zIndex}`;
73
+ // Only set the position to relative if it is not already set to fixed or absolute
74
+ if (!['fixed', 'absolute'].includes(window.getComputedStyle(element).position)) {
75
+ element.style.position = 'relative';
76
+ }
77
+ }
78
+ /**
79
+ * Moves the element back to its original z-index and position after the backdrop is removed.
80
+ *
81
+ * This method restores the original z-index and position of the element
82
+ * that was kept above the backdrop (by using `keepElementAboveBackdrop`).
83
+ *
84
+ * @param element - The element which styling should be restored.
85
+ * @internal
86
+ */
87
+ moveElementBackAfterBackdropRemoval(element) {
88
+ if (!element || !this.elementOriginalStyle) {
89
+ return;
90
+ }
91
+ // Restore the original z-index and position of the element
92
+ element.style.zIndex = this.elementOriginalStyle.zIndex;
93
+ element.style.position = this.elementOriginalStyle.position;
94
+ // Clear the stored original style
95
+ this.elementOriginalStyle = undefined;
96
+ }
97
+ }
98
+ return Backdrop;
99
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@momentum-design/components",
3
3
  "packageManager": "yarn@3.2.4",
4
- "version": "0.104.4",
4
+ "version": "0.104.5",
5
5
  "engines": {
6
6
  "node": ">=20.0.0",
7
7
  "npm": ">=8.0.0"