Skip to content

A platform for community discussion. Free, open, simple.

DEV: consolidate mobile and desktop modal styles into common (#34234)

Krisff57cadd69ed
diff --git a/app/assets/stylesheets/common/base/modal.scss b/app/assets/stylesheets/common/base/modal.scss
index 0e2395a348f..a5a5d90852b 100644
--- a/app/assets/stylesheets/common/base/modal.scss
+++ b/app/assets/stylesheets/common/base/modal.scss
@@ -1,3 +1,30 @@
+@use "lib/viewport";
+
+html.modal-open {
+ // prevents bg scrolling when modal is open
+ overflow: hidden;
+ scrollbar-gutter: stable;
+}
+
+html.keyboard-visible.mobile-view {
+ .d-modal {
+ max-height: calc(var(--composer-vh, 1dvh) * 100);
+ height: calc(var(--composer-vh, 1dvh) * 100);
+ bottom: 0;
+ }
+
+ .d-modal__container {
+ max-height: calc(var(--composer-vh, 1dvh) * 100);
+ height: calc(var(--composer-vh, 1dvh) * 100);
+ }
+}
+
+html:not(.keyboard-visible.mobile-view) {
+ .d-modal__container {
+ padding-bottom: env(safe-area-inset-bottom);
+ }
+}
+
// Modal wrappers
.d-modal {
pointer-events: none; // Allow clicks through wrappers so they hit the adjacent backdrop element
@@ -10,6 +37,16 @@
z-index: z("modal", "content");
overflow: auto;
+ @include viewport.until(sm) {
+ align-items: flex-end;
+ }
+
+ @include viewport.from(sm) {
+ --modal-max-width: 600px;
+ --modal-width: 30em; // set in ems to scale with user font-size
+ --modal-min-width: 400px;
+ }
+
&.-inline {
position: relative;
}
@@ -24,6 +61,28 @@
background-color: var(--secondary);
box-shadow: var(--shadow-modal);
max-height: var(--modal-max-height, 80vh); // unset, optional theme utility
+
+ @include viewport.until(sm) {
+ // this is a hack to prevent issues on safari with transforms
+ position: fixed;
+ width: 100%;
+ max-width: 100%;
+ max-height: calc(var(--composer-vh, 1dvh) * 85);
+ }
+
+ @include viewport.from(sm) {
+ max-width: var(--modal-max-width);
+ min-width: var(--modal-min-width);
+ min-height: var(--modal-min-height); // unset, optional theme utility
+
+ .d-modal.-large & {
+ max-width: 800px;
+ }
+
+ .d-modal.-max & {
+ max-width: 90vw;
+ }
+ }
}
&__header {
@@ -58,8 +117,12 @@
}
&__title-text {
- font-size: var(--font-up-3);
+ font-size: var(--font-up-1-rem);
line-height: var(--line-height-medium);
+
+ @include viewport.from(sm) {
+ font-size: var(--font-up-3);
+ }
}
&__title-text,
@@ -121,6 +184,17 @@
padding: 1rem 1.5rem;
border-top: 1px solid var(--content-border-color);
gap: 0.5rem;
+
+ @include viewport.until(sm) {
+ &__footer {
+ margin-top: auto;
+
+ .--stacked & {
+ flex-direction: column;
+ align-items: stretch;
+ }
+ }
+ }
}
&__backdrop {
@@ -142,6 +216,23 @@
#modal-alert {
padding-left: 1.5rem;
}
+
+ .ios-device & {
+ &__footer {
+ margin-top: auto;
+ }
+ }
+
+ // fixes modal placement on Android when keyboard is visible
+ html.keyboard-visible:not(.ios-device) & {
+ height: calc(100% - env(keyboard-inset-height));
+
+ .d-modal__container {
+ max-height: 100%;
+ min-height: 100%;
+ height: 100%;
+ }
+ }
}
// legacy
@@ -246,6 +337,26 @@
white-space: pre-wrap;
max-width: var(--modal-max-width);
}
+
+ .close {
+ font-size: var(--font-up-4);
+ text-decoration: none;
+ cursor: pointer;
+
+ @include viewport.from(sm) {
+ font-size: var(--font-up-3);
+
+ &:hover {
+ color: var(--primary);
+ }
+ }
+ }
+
+ @include viewport.from(sm) {
+ .category-chooser {
+ width: 50%;
+ }
+ }
}
.reply-where-modal {
@@ -538,3 +649,69 @@
max-width: 500px;
margin-bottom: 2em;
}
+
+@include viewport.from(sm) {
+ .flag-modal-body .flag-message {
+ height: 3em;
+ }
+
+ .choose-topic-modal {
+ #choosing-topic {
+ // prevents content from moving when user selects different move options 525px
+ width: 525px;
+
+ p {
+ margin-top: 0;
+ }
+
+ .radios {
+ margin-bottom: 10px;
+ display: flex;
+ flex-direction: row;
+
+ .radio-label {
+ display: inline-block;
+ padding-right: 15px;
+ }
+ }
+
+ button {
+ margin-top: 10px;
+ display: block;
+ }
+
+ form {
+ width: 95%;
+ margin-top: 20px;
+
+ .participant-selector {
+ width: 100%;
+ }
+
+ div.ac-wrap {
+ width: 100%;
+ margin-bottom: 9px;
+ }
+ }
+ }
+ }
+
+ .create-invite-modal,
+ .create-invite-bulk-modal,
+ .share-topic-modal {
+ .title {
+ align-items: center;
+ display: flex;
+
+ .subtitle {
+ margin-left: 0.5em;
+ }
+ }
+
+ .alert-error {
+ label {
+ display: inline-block;
+ }
+ }
+ }
+}
diff --git a/app/assets/stylesheets/desktop/_index.scss b/app/assets/stylesheets/desktop/_index.scss
index 19fd454168e..31c3f1a8fba 100644
--- a/app/assets/stylesheets/desktop/_index.scss
+++ b/app/assets/stylesheets/desktop/_index.scss
@@ -1,7 +1,6 @@
@import "category-list";
@import "latest-topic-list";
@import "login-signup-page";
-@import "modal";
@import "topic";
@import "topic-list";
@import "topic-post";
diff --git a/app/assets/stylesheets/desktop/modal.scss b/app/assets/stylesheets/desktop/modal.scss
deleted file mode 100644
index 56c112bea5b..00000000000
--- a/app/assets/stylesheets/desktop/modal.scss
+++ /dev/null
@@ -1,113 +0,0 @@
-html.modal-open {
- overflow: hidden;
- scrollbar-gutter: stable;
-}
-
-.d-modal {
- --modal-max-width: 600px;
- --modal-width: 30em; // set in ems to scale with user font-size
- --modal-min-width: 400px;
-
- &__container {
- max-width: var(--modal-max-width);
- min-width: var(--modal-min-width);
- min-height: var(--modal-min-height); // unset, optional theme utility
-
- .d-modal.-large & {
- max-width: 800px;
- }
-
- .d-modal.-max & {
- max-width: 90vw;
- }
- }
-}
-
-.modal.in {
- animation: fade 0.25s;
-
- @media (prefers-reduced-motion) {
- animation-duration: 0s;
- }
-}
-
-.close {
- font-size: var(--font-up-3);
- text-decoration: none;
- cursor: pointer;
-
- &:visited {
- color: var(--primary-high);
- }
-
- &:hover {
- color: var(--primary);
- }
-}
-
-.modal {
- .category-chooser {
- width: 50%;
- }
-}
-
-.choose-topic-modal {
- #choosing-topic {
- // prevents content from moving when user selects different move options 525px
- // is the same width we set on category edit modal
- width: 525px;
-
- p {
- margin-top: 0;
- }
-
- .radios {
- margin-bottom: 10px;
- display: flex;
- flex-direction: row;
-
- .radio-label {
- display: inline-block;
- padding-right: 15px;
- }
- }
-
- button {
- margin-top: 10px;
- display: block;
- }
-
- form {
- width: 95%;
- margin-top: 20px;
-
- .participant-selector {
- width: 100%;
- }
-
- div.ac-wrap {
- width: 100%;
- margin-bottom: 9px;
- }
- }
- }
-}
-
-.create-invite-modal,
-.create-invite-bulk-modal,
-.share-topic-modal {
- .title {
- align-items: center;
- display: flex;
-
- .subtitle {
- margin-left: 0.5em;
- }
- }
-
- .alert-error {
- label {
- display: inline-block;
- }
- }
-}
diff --git a/app/assets/stylesheets/mobile/_index.scss b/app/assets/stylesheets/mobile/_index.scss
index f14d733ac8e..6b33c1c0a6b 100644
--- a/app/assets/stylesheets/mobile/_index.scss
+++ b/app/assets/stylesheets/mobile/_index.scss
@@ -1,5 +1,4 @@
@import "login-signup-page";
-@import "modal";
@import "push-notifications-mobile";
@import "topic-list";
@import "topic-post";
diff --git a/app/assets/stylesheets/mobile/modal.scss b/app/assets/stylesheets/mobile/modal.scss
deleted file mode 100644
index 6126ec9198a..00000000000
--- a/app/assets/stylesheets/mobile/modal.scss
+++ /dev/null
@@ -1,91 +0,0 @@
-// base styles for every modal popup used in Discourse
-
-// prevents bg scrolling when modal is open
-html:has(.d-modal) {
- overflow: hidden;
-}
-
-html.keyboard-visible.mobile-view {
- .d-modal {
- max-height: calc(var(--composer-vh, 1dvh) * 100);
- height: calc(var(--composer-vh, 1dvh) * 100);
- bottom: 0;
- }
-
- .d-modal__container {
- max-height: calc(var(--composer-vh, 1dvh) * 100);
- height: calc(var(--composer-vh, 1dvh) * 100);
- }
-}
-
-html:not(.keyboard-visible.mobile-view) {
- .d-modal__container {
- padding-bottom: env(safe-area-inset-bottom);
- }
-}
-
-.d-modal {
- align-items: flex-end;
-
- &__container {
- // this is a hack to prevent issues on safari with transforms
- position: fixed;
- width: 100%;
- max-width: 100%;
- max-height: calc(var(--composer-vh, 1dvh) * 85);
- }
-
- &__footer {
- margin-top: auto;
-
- .--stacked & {
- flex-direction: column;
- align-items: stretch;
- }
- }
-
- .ios-device & {
- &__footer {
- margin-top: auto;
- }
- }
-
- &__title-text {
- font-size: var(--font-up-1-rem);
- }
-
- // fixes modal placement on Android when keyboard is visible
- html.keyboard-visible:not(.ios-device) & {
- height: calc(100% - env(keyboard-inset-height));
-
- .d-modal__container {
- max-height: 100%;
- min-height: 100%;
- height: 100%;
- }
- }
-}
-
-// legacy
-.modal {
- &.fade {
- transition:
- opacity 0.3s linear,
- top 0.3s ease-out;
- top: -25%;
- }
-
- &.fade.in {
- top: 50%;
- }
-}
-
-.close {
- font-size: var(--font-up-4);
-}
-
-@media only screen and (device-width <= 568px) {
- .flag-modal-body .flag-message {
- height: 3em;
- }
-}