@maggioli-design-system/mds-modal 5.3.0 → 5.5.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.
Files changed (92) hide show
  1. package/dist/cjs/{index-6f236cfa.js → index-a263ff04.js} +139 -101
  2. package/dist/cjs/loader.cjs.js +2 -2
  3. package/dist/cjs/mds-modal.cjs.entry.js +35 -4
  4. package/dist/cjs/mds-modal.cjs.js +3 -3
  5. package/dist/collection/collection-manifest.json +1 -1
  6. package/dist/collection/common/floating-controller.js +3 -3
  7. package/dist/collection/common/slot.js +10 -1
  8. package/dist/collection/common/string.js +30 -0
  9. package/dist/collection/components/mds-modal/mds-modal.css +171 -73
  10. package/dist/collection/components/mds-modal/mds-modal.js +59 -2
  11. package/dist/collection/components/mds-modal/meta/dictionary.js +5 -1
  12. package/dist/collection/components/mds-modal/test/mds-modal.stories.js +20 -2
  13. package/dist/collection/dictionary/keyboard.js +84 -0
  14. package/dist/collection/type/keyboard.js +1 -0
  15. package/dist/components/mds-modal.js +36 -4
  16. package/dist/documentation.json +47 -2
  17. package/dist/esm/{index-f8d2dee4.js → index-efd0657a.js} +139 -101
  18. package/dist/esm/loader.js +3 -3
  19. package/dist/esm/mds-modal.entry.js +35 -4
  20. package/dist/esm/mds-modal.js +4 -4
  21. package/dist/esm-es5/index-efd0657a.js +1 -0
  22. package/dist/esm-es5/loader.js +1 -1
  23. package/dist/esm-es5/mds-modal.entry.js +1 -1
  24. package/dist/esm-es5/mds-modal.js +1 -1
  25. package/dist/mds-modal/mds-modal.esm.js +1 -1
  26. package/dist/mds-modal/mds-modal.js +1 -1
  27. package/dist/mds-modal/p-26971abb.js +2 -0
  28. package/dist/mds-modal/p-52bb21e4.system.entry.js +1 -0
  29. package/dist/mds-modal/p-785b3b47.system.js +2 -0
  30. package/dist/mds-modal/p-96b782c7.system.js +1 -0
  31. package/dist/mds-modal/p-df986a83.entry.js +1 -0
  32. package/dist/stats.json +100 -33
  33. package/dist/types/common/slot.d.ts +2 -1
  34. package/dist/types/common/string.d.ts +4 -0
  35. package/dist/types/components/mds-modal/mds-modal.d.ts +8 -1
  36. package/dist/types/components/mds-modal/meta/dictionary.d.ts +2 -1
  37. package/dist/types/components/mds-modal/meta/types.d.ts +1 -0
  38. package/dist/types/components/mds-modal/test/mds-modal.stories.d.ts +11 -0
  39. package/dist/types/components.d.ts +10 -2
  40. package/dist/types/dictionary/keyboard.d.ts +2 -0
  41. package/dist/types/type/keyboard.d.ts +12 -0
  42. package/documentation.json +62 -2
  43. package/package.json +4 -4
  44. package/readme.md +18 -16
  45. package/src/common/floating-controller.ts +6 -6
  46. package/src/common/slot.ts +11 -0
  47. package/src/common/string.ts +42 -0
  48. package/src/components/mds-modal/css/mds-modal-animate-bottom-left.css +2 -2
  49. package/src/components/mds-modal/css/mds-modal-animate-bottom-right.css +2 -2
  50. package/src/components/mds-modal/css/mds-modal-animate-bottom.css +2 -2
  51. package/src/components/mds-modal/css/mds-modal-animate-center.css +2 -2
  52. package/src/components/mds-modal/css/mds-modal-animate-left.css +2 -2
  53. package/src/components/mds-modal/css/mds-modal-animate-right.css +2 -2
  54. package/src/components/mds-modal/css/mds-modal-animate-top-left.css +2 -2
  55. package/src/components/mds-modal/css/mds-modal-animate-top-right.css +2 -2
  56. package/src/components/mds-modal/css/mds-modal-animate-top.css +2 -2
  57. package/src/components/mds-modal/css/mds-modal-animate.css +4 -4
  58. package/src/components/mds-modal/css/mds-modal-pref-animation.css +14 -23
  59. package/src/components/mds-modal/css/mds-modal-pref-contrast.css +5 -13
  60. package/src/components/mds-modal/css/mds-modal-pref-theme.css +6 -15
  61. package/src/components/mds-modal/mds-modal.css +9 -6
  62. package/src/components/mds-modal/mds-modal.tsx +36 -1
  63. package/src/components/mds-modal/meta/dictionary.ts +6 -0
  64. package/src/components/mds-modal/meta/types.ts +4 -0
  65. package/src/components/mds-modal/readme.md +18 -16
  66. package/src/components/mds-modal/test/mds-modal.stories.tsx +57 -3
  67. package/src/components.d.ts +10 -2
  68. package/src/dictionary/keyboard.ts +87 -0
  69. package/src/fixtures/icons.json +18 -1
  70. package/src/meta/keyboard/keys.json +83 -0
  71. package/src/tailwind/components.css +11 -46
  72. package/src/tailwind/fouc.css +118 -0
  73. package/src/tailwind/index.css +4 -0
  74. package/src/type/keyboard.ts +93 -0
  75. package/www/build/mds-modal.esm.js +1 -1
  76. package/www/build/mds-modal.js +1 -1
  77. package/www/build/p-26971abb.js +2 -0
  78. package/www/build/p-52bb21e4.system.entry.js +1 -0
  79. package/www/build/p-785b3b47.system.js +2 -0
  80. package/www/build/p-96b782c7.system.js +1 -0
  81. package/www/build/p-df986a83.entry.js +1 -0
  82. package/dist/esm-es5/index-f8d2dee4.js +0 -1
  83. package/dist/mds-modal/p-413a00c5.entry.js +0 -1
  84. package/dist/mds-modal/p-96958acc.system.entry.js +0 -1
  85. package/dist/mds-modal/p-bc1fa4e4.system.js +0 -2
  86. package/dist/mds-modal/p-c6899cb0.system.js +0 -1
  87. package/dist/mds-modal/p-ee90f86a.js +0 -2
  88. package/www/build/p-413a00c5.entry.js +0 -1
  89. package/www/build/p-96958acc.system.entry.js +0 -1
  90. package/www/build/p-bc1fa4e4.system.js +0 -2
  91. package/www/build/p-c6899cb0.system.js +0 -1
  92. package/www/build/p-ee90f86a.js +0 -2
package/readme.md CHANGED
@@ -9,11 +9,12 @@ This is a web-component from Maggioli Design System [Magma](https://magma.maggio
9
9
 
10
10
  ## Properties
11
11
 
12
- | Property | Attribute | Description | Type | Default |
13
- | ----------- | ----------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ---------- |
14
- | `animating` | `animating` | Specifies if the component is animating itself or not | `"intro" \| "none" \| "outro" \| undefined` | `'none'` |
15
- | `opened` | `opened` | Specifies if the modal is opened or not | `boolean` | `false` |
16
- | `position` | `position` | Specifies the animation position of the modal window | `"bottom" \| "bottom-left" \| "bottom-right" \| "center" \| "left" \| "right" \| "top" \| "top-left" \| "top-right" \| undefined` | `'center'` |
12
+ | Property | Attribute | Description | Type | Default |
13
+ | ----------- | ----------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ---------- |
14
+ | `animating` | `animating` | Specifies if the component is animating itself or not | `"intro" \| "none" \| "outro" \| undefined` | `'none'` |
15
+ | `opened` | `opened` | Specifies if the modal is opened or not | `boolean` | `false` |
16
+ | `overflow` | `overflow` | Specifies if the component prevents the body from scrolling when modal window is opened | `"auto" \| "manual"` | `'auto'` |
17
+ | `position` | `position` | Specifies the animation position of the modal window | `"bottom" \| "bottom-left" \| "bottom-right" \| "center" \| "left" \| "right" \| "top" \| "top-left" \| "top-right" \| undefined` | `'center'` |
17
18
 
18
19
 
19
20
  ## Events
@@ -43,17 +44,18 @@ This is a web-component from Maggioli Design System [Magma](https://magma.maggio
43
44
 
44
45
  ## CSS Custom Properties
45
46
 
46
- | Name | Description |
47
- | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
48
- | `--mds-modal-close-icon-color` | Set the color of the close icon button to the top left. |
49
- | `--mds-modal-overlay-color` | Set the overlay color of the background when the component is opened, this property can be inherited from `globals.css` in `styles^8.0.0`. |
50
- | `--mds-modal-overlay-opacity` | Set the overlay color opacity of the background when the component is opened, this property can be inherited from `globals.css` in `styles^8.0.0`. |
51
- | `--mds-modal-window-background` | Set the background color of the window |
52
- | `--mds-modal-window-distance` | Set the distance between the modal window and the screen bounds |
53
- | `--mds-modal-window-overflow` | Set the overflow of the window |
54
- | `--mds-modal-window-radius` | Set the border radius of the window |
55
- | `--mds-modal-window-shadow` | Set the box shadow of the window |
56
- | `--mds-modal-z-index` | Set the z-index of the window when the component is opened |
47
+ | Name | Description |
48
+ | ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
49
+ | `--mds-modal-close-icon-color` | Set the color of the close icon button to the top left. |
50
+ | `--mds-modal-custom-window-distance` | Set the distance between the slotted modal window and the screen bounds |
51
+ | `--mds-modal-overlay-color` | Set the overlay color of the background when the component is opened, this property can be inherited from `globals.css` in `styles^8.0.0`. |
52
+ | `--mds-modal-overlay-opacity` | Set the overlay color opacity of the background when the component is opened, this property can be inherited from `globals.css` in `styles^8.0.0`. |
53
+ | `--mds-modal-window-background` | Set the background color of the window |
54
+ | `--mds-modal-window-distance` | Set the distance between the modal window and the screen bounds |
55
+ | `--mds-modal-window-overflow` | Set the overflow of the window |
56
+ | `--mds-modal-window-radius` | Set the border radius of the window |
57
+ | `--mds-modal-window-shadow` | Set the box shadow of the window |
58
+ | `--mds-modal-z-index` | Set the z-index of the window when the component is opened |
57
59
 
58
60
 
59
61
  ## Dependencies
@@ -214,21 +214,21 @@ export class FloatingController {
214
214
  }
215
215
 
216
216
  export class Backdrop {
217
- private readonly defaultBackdropId = 'mds-backdrop'
217
+ private readonly defaultBackdropId = 'magma-backdrop'
218
218
  private readonly backdropBackgroundVisible = 'rgba(var(--magma-backdrop-color, 0 0 0) / var(--magma-backdrop-opacity, 0.1))'
219
219
  private readonly backdropBackgroundHidden = 'rgba(var(--magma-backdrop-color, 0 0 0) / 0)'
220
220
 
221
- private readonly backdropId
222
- private readonly cssBackdropZIndex
223
- private readonly cssBackdropDuration
221
+ private readonly backdropId: string
222
+ private readonly cssBackdropZIndex: string
223
+ private readonly cssBackdropDuration: string
224
224
 
225
225
  private backdropEl: HTMLElement
226
226
  private backdropTimer: NodeJS.Timeout
227
227
 
228
228
  constructor (backdropId?: string) {
229
229
  this.backdropId = backdropId ?? this.defaultBackdropId
230
- this.cssBackdropZIndex = `var(--${this.backdropId}-z-index)`
231
- this.cssBackdropDuration = `var(--${this.backdropId}-duration)`
230
+ this.cssBackdropZIndex = `var(--${this.backdropId}-z-index, 4000)`
231
+ this.cssBackdropDuration = `var(--${this.backdropId}-animation-duration, 300ms)`
232
232
  }
233
233
 
234
234
  attachBackdrop (): void {
@@ -18,7 +18,18 @@ const hasSlottedNodes = (el: HTMLElement, name?: string): boolean => {
18
18
  return false
19
19
  }
20
20
 
21
+ const hasSlotted = (el: HTMLElement, name?: string): boolean => {
22
+ const query = name ? `slot[name="${name}"]` : 'slot:not([name])'
23
+
24
+ const slot: HTMLSlotElement = el.shadowRoot?.querySelector(query) as HTMLSlotElement
25
+ if (slot) {
26
+ return slot.assignedNodes().length > 0 || slot.assignedElements().length > 0
27
+ }
28
+ return false
29
+ }
30
+
21
31
  export {
22
32
  hasSlottedElements,
23
33
  hasSlottedNodes,
34
+ hasSlotted,
24
35
  }
@@ -0,0 +1,42 @@
1
+ const levenshteinDistance = (a: string, b: string): number => {
2
+ const dp: number[][] = Array.from({ length: a.length + 1 }, (_, i) =>
3
+ // eslint-disable-next-line no-nested-ternary
4
+ Array.from({ length: b.length + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)),
5
+ )
6
+
7
+ for (let i = 1; i <= a.length; i++) {
8
+ for (let j = 1; j <= b.length; j++) {
9
+ if (a[i - 1] === b[j - 1]) {
10
+ dp[i][j] = dp[i - 1][j - 1]
11
+ } else {
12
+ dp[i][j] = 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1])
13
+ }
14
+ }
15
+ }
16
+
17
+ return dp[a.length][b.length]
18
+ }
19
+
20
+
21
+ const closest = (input: string, validCodes: string[]): string => {
22
+ let [closest] = validCodes
23
+ let minDistance = levenshteinDistance(input, closest)
24
+
25
+ for (const code of validCodes) {
26
+ const distance = levenshteinDistance(input, code)
27
+ if (distance < minDistance) {
28
+ minDistance = distance
29
+ closest = code
30
+ }
31
+ }
32
+
33
+ return closest
34
+ }
35
+
36
+ const firstLetterUppercase = (str: string): string => str.charAt(0).toUpperCase() + str.slice(1)
37
+
38
+ export {
39
+ closest,
40
+ firstLetterUppercase,
41
+ levenshteinDistance,
42
+ }
@@ -8,8 +8,8 @@
8
8
  width: 100vw;
9
9
  }
10
10
 
11
- :host([position="bottom-left"][opened="false"]) > ::slotted( [slot="window"] ),
12
- :host([position="bottom-left"]:not([opened])) > ::slotted( [slot="window"] ) {
11
+ :host([position="bottom-left"][opened="false"]) > ::slotted([slot="window"]),
12
+ :host([position="bottom-left"]:not([opened])) > ::slotted([slot="window"]) {
13
13
  transform: rotateX(22deg) rotateY(22deg) scale(0.5) translate(-80%, 80%);
14
14
  }
15
15
 
@@ -8,8 +8,8 @@
8
8
  width: 100vw;
9
9
  }
10
10
 
11
- :host([position="bottom-right"][opened="false"]) > ::slotted( [slot="window"] ),
12
- :host([position="bottom-right"]:not([opened])) > ::slotted( [slot="window"] ) {
11
+ :host([position="bottom-right"][opened="false"]) > ::slotted([slot="window"]),
12
+ :host([position="bottom-right"]:not([opened])) > ::slotted([slot="window"]) {
13
13
  transform: rotateX(-22deg) rotateY(-22deg) scale(0.5) translate(80%, 80%);
14
14
  }
15
15
 
@@ -8,8 +8,8 @@
8
8
  width: 100vw;
9
9
  }
10
10
 
11
- :host([position="bottom"][opened="false"]) > ::slotted( [slot="window"] ),
12
- :host([position="bottom"]:not([opened])) > ::slotted( [slot="window"] ) {
11
+ :host([position="bottom"][opened="false"]) > ::slotted([slot="window"]),
12
+ :host([position="bottom"]:not([opened])) > ::slotted([slot="window"]) {
13
13
  transform: rotateX(22deg) rotateY(0) scale(0.5) translate(0, 80%);
14
14
  }
15
15
 
@@ -7,8 +7,8 @@
7
7
  transition-delay: 0s;
8
8
  }
9
9
 
10
- :host([position="center"][opened="false"]) > ::slotted( [slot="window"] ),
11
- :host([position="center"]:not([opened])) > ::slotted( [slot="window"] ) {
10
+ :host([position="center"][opened="false"]) > ::slotted([slot="window"]),
11
+ :host([position="center"]:not([opened])) > ::slotted([slot="window"]) {
12
12
  transform: rotateX(0) rotateY(22deg) scale(0.5) translate(0, 40%);
13
13
  }
14
14
 
@@ -9,8 +9,8 @@
9
9
  max-width: calc(100vw - 80px);
10
10
  }
11
11
 
12
- :host([position="left"][opened="false"]) > ::slotted( [slot="window"] ),
13
- :host([position="left"]:not([opened])) > ::slotted( [slot="window"] ) {
12
+ :host([position="left"][opened="false"]) > ::slotted([slot="window"]),
13
+ :host([position="left"]:not([opened])) > ::slotted([slot="window"]) {
14
14
  transform: rotateX(0) rotateY(22deg) rotateZ(0) scale(0.5) translate(-100%, 0%);
15
15
  }
16
16
 
@@ -9,8 +9,8 @@
9
9
  max-width: calc(100vw - 80px);
10
10
  }
11
11
 
12
- :host([position="right"][opened="false"]) > ::slotted( [slot="window"] ),
13
- :host([position="right"]:not([opened])) > ::slotted( [slot="window"] ) {
12
+ :host([position="right"][opened="false"]) > ::slotted([slot="window"]),
13
+ :host([position="right"]:not([opened])) > ::slotted([slot="window"]) {
14
14
  transform: rotateX(0) rotateY(-22deg) rotateZ(0) scale(0.5) translate(100%, 0%);
15
15
  }
16
16
 
@@ -8,8 +8,8 @@
8
8
  width: 100vw;
9
9
  }
10
10
 
11
- :host([position="top-left"][opened="false"]) > ::slotted( [slot="window"] ),
12
- :host([position="top-left"]:not([opened])) > ::slotted( [slot="window"] ) {
11
+ :host([position="top-left"][opened="false"]) > ::slotted([slot="window"]),
12
+ :host([position="top-left"]:not([opened])) > ::slotted([slot="window"]) {
13
13
  transform: rotateX(22deg) rotateY(22deg) scale(0.5) translate(-80%, 80%);
14
14
  }
15
15
 
@@ -8,8 +8,8 @@
8
8
  width: 100vw;
9
9
  }
10
10
 
11
- :host([position="top-right"][opened="false"]) > ::slotted( [slot="window"] ),
12
- :host([position="top-right"]:not([opened])) > ::slotted( [slot="window"] ) {
11
+ :host([position="top-right"][opened="false"]) > ::slotted([slot="window"]),
12
+ :host([position="top-right"]:not([opened])) > ::slotted([slot="window"]) {
13
13
  transform: rotateX(-22deg) rotateY(-22deg) scale(0.5) translate(80%, 80%);
14
14
  }
15
15
 
@@ -8,8 +8,8 @@
8
8
  width: 100vw;
9
9
  }
10
10
 
11
- :host([position="top"][opened="false"]) > ::slotted( [slot="window"] ),
12
- :host([position="top"]:not([opened])) > ::slotted( [slot="window"] ) {
11
+ :host([position="top"][opened="false"]) > ::slotted( [slot="window"]),
12
+ :host([position="top"]:not([opened])) > ::slotted( [slot="window"]) {
13
13
  transform: rotateX(-22deg) rotateY(0) scale(0.5) translate(0, -80%);
14
14
  }
15
15
 
@@ -3,21 +3,21 @@
3
3
  }
4
4
 
5
5
 
6
- :host([opened]:not([opened="false"]) ) {
6
+ :host([opened]:not([opened="false"])) {
7
7
  background-color: rgba(var(--mds-modal-overlay-color) / var(--mds-modal-overlay-opacity));
8
8
  pointer-events: auto;
9
9
  }
10
10
 
11
11
  :host .window,
12
- :host > ::slotted( [slot="window"] ) {
12
+ :host > ::slotted([slot="window"]) {
13
13
  opacity: 0;
14
14
  transition-duration: var(--mds-modal-transition-duration);
15
15
  transition-property: transform, opacity;
16
16
  transition-timing-function: var(--mds-modal-transition-outro-ease);
17
17
  }
18
18
 
19
- :host([opened]:not([opened="false"]) ) .window,
20
- :host([opened]:not([opened="false"]) ) > ::slotted( [slot="window"] ) {
19
+ :host([opened]:not([opened="false"])) .window,
20
+ :host([opened]:not([opened="false"])) > ::slotted( [slot="window"]) {
21
21
  opacity: 1;
22
22
  transform: rotate(0) scale(1) translateY(0);
23
23
  transition-delay: 0s;
@@ -1,30 +1,21 @@
1
- @tailwind utilities;
2
-
3
- @container style(--magma-pref-animation: reduce) {
4
- :host,
5
- .action-close,
6
- .window {
7
- transition-duration: 0s !important;
8
- }
1
+ :host-context(.pref-animation-reduce) {
2
+ --mds-modal-transition-duration: 0s;
3
+ }
9
4
 
10
- :host {
5
+ :host-context(.pref-animation-reduce),
6
+ :host-context(.pref-animation-reduce) .action-close,
7
+ :host-context(.pref-animation-reduce) .window {
8
+ transition-duration: 0s !important;
9
+ }
11
10
 
11
+ @media (prefers-reduced-motion) {
12
+ :host-context(.pref-animation-system) {
12
13
  --mds-modal-transition-duration: 0s;
13
14
  }
14
- }
15
-
16
- @container style(--magma-pref-animation: system) {
17
-
18
- @media (prefers-reduced-motion) {
19
- :host,
20
- .action-close,
21
- .window {
22
- transition-duration: 0s !important;
23
- }
24
15
 
25
- :host {
26
-
27
- --mds-modal-transition-duration: 0s;
28
- }
16
+ :host-context(.pref-animation-system),
17
+ :host-context(.pref-animation-system) .action-close,
18
+ :host-context(.pref-animation-system) .window {
19
+ transition-duration: 0s !important;
29
20
  }
30
21
  }
@@ -1,18 +1,10 @@
1
- @tailwind utilities;
2
-
3
- @container style(--magma-pref-contrast: more) {
4
- :host {
5
-
6
- --mds-modal-window-shadow: theme('boxShadow.outline-strong-50'), theme('boxShadow.2xl');
7
- }
1
+ :host-context(.pref-contrast-more) {
2
+ --mds-modal-window-shadow: theme('boxShadow.outline-strong-50'), theme('boxShadow.2xl');
8
3
  }
9
4
 
10
- @container style(--magma-pref-contrast: system) {
11
-
12
- @media (prefers-contrast: more) {
13
- :host {
14
5
 
15
- --mds-modal-window-shadow: theme('boxShadow.outline-strong-50'), theme('boxShadow.2xl');
16
- }
6
+ @media (prefers-contrast: more) {
7
+ :host-context(.pref-contrast-system) {
8
+ --mds-modal-window-shadow: theme('boxShadow.outline-strong-50'), theme('boxShadow.2xl');
17
9
  }
18
10
  }
@@ -1,20 +1,11 @@
1
- @tailwind utilities;
2
-
3
- @container style(--magma-pref-theme: dark) {
4
- :host {
1
+ :host-context(.pref-theme-dark) {
2
+ --mds-modal-window-background: theme('colors.tone-neutral-09');
3
+ --mds-modal-window-shadow: theme('boxShadow.outline'), theme('boxShadow.xl');
4
+ }
5
5
 
6
+ @media (prefers-color-scheme: dark) {
7
+ :host-context(.pref-theme-system) {
6
8
  --mds-modal-window-background: theme('colors.tone-neutral-09');
7
9
  --mds-modal-window-shadow: theme('boxShadow.outline'), theme('boxShadow.xl');
8
10
  }
9
11
  }
10
-
11
- @container style(--magma-pref-theme: system) {
12
-
13
- @media (prefers-color-scheme: dark) {
14
- :host {
15
-
16
- --mds-modal-window-background: theme('colors.tone-neutral-09');
17
- --mds-modal-window-shadow: theme('boxShadow.outline'), theme('boxShadow.xl');
18
- }
19
- }
20
- }
@@ -1,8 +1,6 @@
1
1
  @import '~@maggioli-design-system/styles/dist/css/animations.css'; /* included for focus effect */
2
2
  @import '../../tailwind/components.css';
3
-
4
3
  @tailwind components;
5
- @tailwind utilities;
6
4
 
7
5
  /**
8
6
  * @prop --mds-modal-close-icon-color: Set the color of the close icon button to the top left.
@@ -12,12 +10,12 @@
12
10
  * @prop --mds-modal-window-overflow: Set the overflow of the window
13
11
  * @prop --mds-modal-window-radius: Set the border radius of the window
14
12
  * @prop --mds-modal-window-distance: Set the distance between the modal window and the screen bounds
13
+ * @prop --mds-modal-custom-window-distance: Set the distance between the slotted modal window and the screen bounds
15
14
  * @prop --mds-modal-window-shadow: Set the box shadow of the window
16
15
  * @prop --mds-modal-z-index: Set the z-index of the window when the component is opened
17
16
  */
18
17
 
19
18
  :host {
20
-
21
19
  --mds-modal-overlay-color: var(--magma-overlay-color, 0 0 0);
22
20
  --mds-modal-overlay-opacity: var(--magma-overlay-opacity, 0.5);
23
21
  --mds-modal-transition-duration: 500ms;
@@ -28,6 +26,7 @@
28
26
  --mds-modal-window-radius: 0;
29
27
  --mds-modal-window-shadow: theme('boxShadow.2xl');
30
28
  --mds-modal-window-distance: 0;
29
+ --mds-modal-custom-window-distance: theme('spacing.600');
31
30
  --mds-modal-z-index: var(--magma-modal-z-index);
32
31
 
33
32
  @apply ease-in-out-expo;
@@ -46,12 +45,16 @@
46
45
  z-index: var(--mds-modal-z-index, 1000);
47
46
  }
48
47
 
49
- :host( [position="top"] ) {
48
+ :host ::slotted([slot="window"]) {
49
+ margin: var(--mds-modal-custom-window-distance);
50
+ }
51
+
52
+ :host([position="top"]) {
50
53
  align-items: flex-start;
51
54
  justify-content: center;
52
55
  }
53
56
 
54
- :host( [position="bottom"] ) {
57
+ :host([position="bottom"]) {
55
58
  align-items: flex-end;
56
59
  justify-content: center;
57
60
  }
@@ -113,4 +116,4 @@
113
116
  @import './css/mds-modal-pref-animation.css';
114
117
  @import './css/mds-modal-pref-contrast.css';
115
118
  @import './css/mds-modal-pref-theme.css';
116
-
119
+ @import '../../tailwind/fouc.css';
@@ -1,6 +1,6 @@
1
1
  import clsx from 'clsx'
2
2
  import { Component, Element, Event, EventEmitter, Host, h, Listen, Prop, Watch } from '@stencil/core'
3
- import { ModalPositionType, ModalAnimationStateType } from './meta/types'
3
+ import { ModalPositionType, ModalAnimationStateType, ModalOverflowType } from './meta/types'
4
4
  import { cssDurationToMilliseconds } from '@common/unit'
5
5
 
6
6
  /**
@@ -20,6 +20,7 @@ export class MdsModal {
20
20
  private animationDelayTimeout: NodeJS.Timeout
21
21
  private window = false
22
22
  private top = false
23
+ private bodyOverflow: string
23
24
  private bottom = false
24
25
  private cssTransitionDuration: string
25
26
 
@@ -40,6 +41,11 @@ export class MdsModal {
40
41
  */
41
42
  @Prop({ reflect: true, mutable: true }) animating?: ModalAnimationStateType = 'none'
42
43
 
44
+ /**
45
+ * Specifies if the component prevents the body from scrolling when modal window is opened
46
+ */
47
+ @Prop({ reflect: true }) readonly overflow: ModalOverflowType = 'auto'
48
+
43
49
  /**
44
50
  * Emits when a modal is closed
45
51
  */
@@ -69,6 +75,25 @@ export class MdsModal {
69
75
  clearTimeout(this.animationDelayTimeout)
70
76
  }
71
77
 
78
+ private disableOverflow = (): void => {
79
+ if (document) {
80
+ if (document.body.style.overflow) {
81
+ this.bodyOverflow = document.body.style.overflow
82
+ }
83
+ document.body.style.overflow = 'hidden'
84
+ }
85
+ }
86
+
87
+ private enableOverflow = (): void => {
88
+ if (document) {
89
+ if (this.bodyOverflow) {
90
+ document.body.style.overflow = this.bodyOverflow
91
+ } else {
92
+ document.body.style.removeProperty('overflow')
93
+ }
94
+ }
95
+ }
96
+
72
97
  private animateOpenWindow = (): void => {
73
98
  this.animating = 'intro'
74
99
  clearTimeout(this.animationDelayTimeout)
@@ -86,6 +111,10 @@ export class MdsModal {
86
111
  this.top = this.host.querySelector('[slot="top"]') !== null
87
112
  this.window = this.host.querySelector('[slot="window"]') !== null
88
113
 
114
+ if (this.overflow === 'auto' && this.opened) {
115
+ this.disableOverflow()
116
+ }
117
+
89
118
  if (this.window) {
90
119
  this.host.querySelector('[slot="window"]')?.setAttribute('role', 'dialog')
91
120
  }
@@ -112,9 +141,15 @@ export class MdsModal {
112
141
  @Watch('opened')
113
142
  handleOpenProp (newValue: boolean): void {
114
143
  if (newValue) {
144
+ if (this.overflow === 'auto') {
145
+ this.disableOverflow()
146
+ }
115
147
  this.animateOpenWindow()
116
148
  return
117
149
  }
150
+ if (this.overflow === 'auto') {
151
+ this.enableOverflow()
152
+ }
118
153
  this.animateCloseWindow()
119
154
  }
120
155
 
@@ -10,6 +10,12 @@ const modalPositionDictionary = [
10
10
  'top-right',
11
11
  ]
12
12
 
13
+ const modalOverflowDictionary = [
14
+ 'auto',
15
+ 'manual',
16
+ ]
17
+
13
18
  export {
19
+ modalOverflowDictionary,
14
20
  modalPositionDictionary,
15
21
  }
@@ -13,3 +13,7 @@ export type ModalAnimationStateType =
13
13
  | 'intro'
14
14
  | 'none'
15
15
  | 'outro'
16
+
17
+ export type ModalOverflowType =
18
+ | 'auto'
19
+ | 'manual'
@@ -7,11 +7,12 @@
7
7
 
8
8
  ## Properties
9
9
 
10
- | Property | Attribute | Description | Type | Default |
11
- | ----------- | ----------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ---------- |
12
- | `animating` | `animating` | Specifies if the component is animating itself or not | `"intro" \| "none" \| "outro" \| undefined` | `'none'` |
13
- | `opened` | `opened` | Specifies if the modal is opened or not | `boolean` | `false` |
14
- | `position` | `position` | Specifies the animation position of the modal window | `"bottom" \| "bottom-left" \| "bottom-right" \| "center" \| "left" \| "right" \| "top" \| "top-left" \| "top-right" \| undefined` | `'center'` |
10
+ | Property | Attribute | Description | Type | Default |
11
+ | ----------- | ----------- | --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ---------- |
12
+ | `animating` | `animating` | Specifies if the component is animating itself or not | `"intro" \| "none" \| "outro" \| undefined` | `'none'` |
13
+ | `opened` | `opened` | Specifies if the modal is opened or not | `boolean` | `false` |
14
+ | `overflow` | `overflow` | Specifies if the component prevents the body from scrolling when modal window is opened | `"auto" \| "manual"` | `'auto'` |
15
+ | `position` | `position` | Specifies the animation position of the modal window | `"bottom" \| "bottom-left" \| "bottom-right" \| "center" \| "left" \| "right" \| "top" \| "top-left" \| "top-right" \| undefined` | `'center'` |
15
16
 
16
17
 
17
18
  ## Events
@@ -41,17 +42,18 @@
41
42
 
42
43
  ## CSS Custom Properties
43
44
 
44
- | Name | Description |
45
- | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
46
- | `--mds-modal-close-icon-color` | Set the color of the close icon button to the top left. |
47
- | `--mds-modal-overlay-color` | Set the overlay color of the background when the component is opened, this property can be inherited from `globals.css` in `styles^8.0.0`. |
48
- | `--mds-modal-overlay-opacity` | Set the overlay color opacity of the background when the component is opened, this property can be inherited from `globals.css` in `styles^8.0.0`. |
49
- | `--mds-modal-window-background` | Set the background color of the window |
50
- | `--mds-modal-window-distance` | Set the distance between the modal window and the screen bounds |
51
- | `--mds-modal-window-overflow` | Set the overflow of the window |
52
- | `--mds-modal-window-radius` | Set the border radius of the window |
53
- | `--mds-modal-window-shadow` | Set the box shadow of the window |
54
- | `--mds-modal-z-index` | Set the z-index of the window when the component is opened |
45
+ | Name | Description |
46
+ | ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |
47
+ | `--mds-modal-close-icon-color` | Set the color of the close icon button to the top left. |
48
+ | `--mds-modal-custom-window-distance` | Set the distance between the slotted modal window and the screen bounds |
49
+ | `--mds-modal-overlay-color` | Set the overlay color of the background when the component is opened, this property can be inherited from `globals.css` in `styles^8.0.0`. |
50
+ | `--mds-modal-overlay-opacity` | Set the overlay color opacity of the background when the component is opened, this property can be inherited from `globals.css` in `styles^8.0.0`. |
51
+ | `--mds-modal-window-background` | Set the background color of the window |
52
+ | `--mds-modal-window-distance` | Set the distance between the modal window and the screen bounds |
53
+ | `--mds-modal-window-overflow` | Set the overflow of the window |
54
+ | `--mds-modal-window-radius` | Set the border radius of the window |
55
+ | `--mds-modal-window-shadow` | Set the box shadow of the window |
56
+ | `--mds-modal-z-index` | Set the z-index of the window when the component is opened |
55
57
 
56
58
 
57
59
  ----------------------------------------------