From 6c26337061268e0e23e8b9264297e2837ca74cce Mon Sep 17 00:00:00 2001 From: Adam Kudrna Date: Thu, 16 May 2024 18:29:17 +0200 Subject: [PATCH] BREAKING CHANGE(web): Enhance custom height and max height options of `ModalDialog` #DS-1134 1. Custom height and custom max height can be set individually on all breakpoints now. 2. The `--modal-preferred-height-mobile` and `--modal-preferred-height-tablet` custom properties were renamed. --- docs/migrations/web/MIGRATION-v2.md | 11 + .../web/src/scss/components/Modal/README.md | 27 ++- .../scss/components/Modal/_ModalDialog.scss | 5 + .../web/src/scss/components/Modal/_theme.scss | 29 ++- .../web/src/scss/components/Modal/index.html | 224 +++++++++++++++++- 5 files changed, 273 insertions(+), 23 deletions(-) diff --git a/docs/migrations/web/MIGRATION-v2.md b/docs/migrations/web/MIGRATION-v2.md index 21bee550cc..98275d91e0 100644 --- a/docs/migrations/web/MIGRATION-v2.md +++ b/docs/migrations/web/MIGRATION-v2.md @@ -125,6 +125,17 @@ to the `.ModalDialog` element. - `.ModalDialog` → `.ModalDialog .ModalDialog--scrollable` +### Modal: Custom Height + +The `--modal-preferred-height-mobile` and `--modal-preferred-height-tablet` custom properties were renamed. + +#### Migration Guide + +Update the custom properties in your project to use the new names: + +- `--modal-preferred-height-mobile` → `--modal-height` +- `--modal-preferred-height-tablet` → `--modal-height-tablet` + ### Modal: Uniform Variant Feature Flag The feature flag enabling the uniform variant of modal was removed and the diff --git a/packages/web/src/scss/components/Modal/README.md b/packages/web/src/scss/components/Modal/README.md index 1f30328f83..e262df5d29 100644 --- a/packages/web/src/scss/components/Modal/README.md +++ b/packages/web/src/scss/components/Modal/README.md @@ -274,15 +274,20 @@ limit. You can set a custom preferred height of ModalDialog using a custom property: -- `--modal-preferred-height-mobile` for mobile screens, and -- `--modal-preferred-height-tablet` for tablet screens and up. +- `--modal-height` for mobile screens and up, +- `--modal-height-tablet` for tablet screens and up. +- `--modal-height-desktop` for desktop screens and up. + +The custom properties fall back to the previous breakpoint using the mobile-first approach. For example, if you set +`--modal-height-tablet` while leaving `--modal-height-desktop` unset, the value will be used for +both tablet and desktop screens. This is useful for Modals with dynamic content, e.g. a list of items that can be added or removed, or a multistep wizard. ```html
@@ -300,11 +305,21 @@ The default maximum height of a scrollable ModalDialog is **600 px**, as long as If the viewport is smaller, scrollable ModalDialog will shrink to fit the viewport. In such case, the ModalDialog height will calculate as "viewport height (`100dvh`) minus 1100 spacing". -You can use the custom property `--modal-max-height-tablet` to override the default maximum height limit on tablet -screens and up: +You can set a custom preferred height of ModalDialog using a custom property: + +- `--modal-max-height` for mobile screens and up, +- `--modal-max-height-tablet` for tablet screens and up. +- `--modal-max-height-desktop` for desktop screens and up. + +The custom properties fall back to the previous breakpoint using the mobile-first approach. For example, if you set +`--modal-max-height-tablet` while leaving `--modal-max-height-desktop` unset, the value will be used for both tablet and +desktop screens. ```html -
+
``` diff --git a/packages/web/src/scss/components/Modal/_ModalDialog.scss b/packages/web/src/scss/components/Modal/_ModalDialog.scss index e0876e5288..ddbdbbabe8 100644 --- a/packages/web/src/scss/components/Modal/_ModalDialog.scss +++ b/packages/web/src/scss/components/Modal/_ModalDialog.scss @@ -55,6 +55,11 @@ height: theme.$dialog-scrollable-height-tablet; max-height: theme.$dialog-scrollable-max-height-tablet; } + + @include breakpoint.up(map.get(theme.$breakpoints, desktop)) { + height: theme.$dialog-scrollable-height-desktop; + max-height: theme.$dialog-scrollable-max-height-desktop; + } } .ModalDialog--dockOnMobile { diff --git a/packages/web/src/scss/components/Modal/_theme.scss b/packages/web/src/scss/components/Modal/_theme.scss index 653068d556..e62cf6ea33 100644 --- a/packages/web/src/scss/components/Modal/_theme.scss +++ b/packages/web/src/scss/components/Modal/_theme.scss @@ -25,14 +25,31 @@ $dialog-border-radius: tokens.$radius-200; $dialog-background-color: tokens.$background-basic; $dialog-shadow: tokens.$shadow-300; -$dialog-scrollable-height: var(--modal-preferred-height-mobile, min-content); +$_dialog-scrollable-default-height: min-content; +$_dialog-scrollable-default-max-height: 600px; + +$dialog-scrollable-height: var(--modal-height, #{$_dialog-scrollable-default-height}); $dialog-scrollable-height-tablet: var( - --modal-preferred-height-tablet, - var(--modal-preferred-height-mobile, min-content) + --modal-height-tablet, + var(--modal-height, #{$_dialog-scrollable-default-height}) +); +$dialog-scrollable-height-desktop: var( + --modal-height-desktop, + var(--modal-height-tablet, var(--modal-height, #{$_dialog-scrollable-default-height})) +); +$dialog-scrollable-max-height: min( + var(--modal-max-height, #{$_dialog-scrollable-default-max-height}), + calc(100dvh - #{2 * $padding-y}) ); -$dialog-scrollable-max-height: min(var(--modal-max-height-mobile, 600px), calc(100dvh - #{2 * $padding-y})); $dialog-scrollable-max-height-tablet: min( - var(--modal-max-height-tablet, var(--modal-max-height-mobile, 600px)), + var(--modal-max-height-tablet, var(--modal-max-height, #{$_dialog-scrollable-default-max-height})), + calc(100dvh - #{2 * $padding-y}) +); +$dialog-scrollable-max-height-desktop: min( + var( + --modal-max-height-desktop, + var(--modal-max-height-tablet, var(--modal-max-height, #{$_dialog-scrollable-default-max-height})) + ), calc(100dvh - #{2 * $padding-y}) ); @@ -41,7 +58,7 @@ $dialog-docked-margin-top: tokens.$space-1100; $dialog-docked-expanded-min-height: calc(100dvh - #{$dialog-docked-margin-top}); -$dialog-docked-scrollable-height: var(--modal-preferred-height-mobile, min-content); +$dialog-docked-scrollable-height: var(--modal-height, #{$_dialog-scrollable-default-height}); $dialog-docked-scrollable-max-height: $dialog-docked-expanded-min-height; // ModalHeader diff --git a/packages/web/src/scss/components/Modal/index.html b/packages/web/src/scss/components/Modal/index.html index 76cca445e2..b3ca52c1e3 100644 --- a/packages/web/src/scss/components/Modal/index.html +++ b/packages/web/src/scss/components/Modal/index.html @@ -694,7 +694,7 @@

@@ -719,16 +719,218 @@

Modal with Custo
-

- This modal has a custom height of 400px set via the --modal-preferred-height-mobile CSS - custom property. -

-

- This modal has a custom height of 500px set via the --modal-preferred-height-tablet CSS - custom property. -

- - + + +
+
+ + +
+ + + 400 px + + +
+
+ + + 600 px + + +
+
+
+ + +
+ + + 500 px + + +
+
+ + + 600 px + + +
+
+
+ + +
+ + + 600 px + + +
+
+ + + 600 px + + +
+
+
+