FIX: Make fullscreen code modal occupy as much of the screen as needed (#24403)

This commit makes it so the fullscreen code modal grows
to fit its content, and doesn't show horizontal scrollbars
unless the entire screen is filled by the modal already.

The code syntax highlighting and copy buttons were also
broken in fullscreen because of modal changes over time.
This commit is contained in:
Martin Brennan 2023-11-21 09:36:42 +10:00 committed by GitHub
parent a48c43dfae
commit 10b546d8c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 54 deletions

View File

@ -1,7 +1,8 @@
<DModal
@title={{i18n "copy_codeblock.view_code"}}
@closeModal={{this.closeModal}}
{{did-insert this.applyCodeblockButtons}}
class="fullscreen-code-modal"
class="fullscreen-code-modal -max"
>
<:body>
<pre>

View File

@ -16,7 +16,7 @@ export default class FullscreenCode extends Component {
@action
applyCodeblockButtons(element) {
const modalElement = element.querySelector(".modal-body");
const modalElement = element.querySelector(".d-modal__body");
highlightSyntax(modalElement, this.siteSettings, this.session);
this.codeBlockButtons = new CodeblockButtons({

View File

@ -1,4 +1,8 @@
<DModal @closeModal={{@closeModal}} class="fullscreen-table-modal">
<DModal
@title={{i18n "fullscreen_table.view_table"}}
@closeModal={{@closeModal}}
class="fullscreen-table-modal"
>
<:body>
{{@model.tableHtml}}
</:body>

View File

@ -119,11 +119,7 @@ export default class CodeblockButtons {
}px`;
}
if (
this.showFullscreen &&
!Mobile.isMobileDevice &&
codeBlock.scrollWidth > codeBlock.clientWidth
) {
if (this.showFullscreen && !Mobile.isMobileDevice) {
const fullscreenButton = document.createElement("button");
fullscreenButton.classList.add("btn", "nohighlight", "fullscreen-cmd");
fullscreenButton.ariaLabel = I18n.t("copy_codeblock.fullscreen");

View File

@ -1661,45 +1661,3 @@ iframe {
right: 0.5rem;
}
}
.fullscreen-table-modal .modal-inner-container,
.fullscreen-code-modal .modal-inner-container {
width: max-content;
max-width: 90%;
margin: 0 auto;
padding: 10px;
.modal-body {
padding-top: 0;
}
thead {
position: sticky;
top: 0;
z-index: 1;
background-color: var(--secondary);
}
tbody {
overflow-x: hidden;
}
td {
padding: 0.5rem;
}
}
.fullscreen-code-modal {
pre code {
max-width: none;
}
}
html.discourse-no-touch .fullscreen-table-wrapper:hover {
border-radius: 5px;
box-shadow: 0 2px 5px 0 rgba(var(--always-black-rgb), 0.1),
0 2px 10px 0 rgba(var(--always-black-rgb), 0.1);
.open-popup-link {
opacity: 100%;
}
}

View File

@ -307,14 +307,38 @@
}
}
.d-modal.fullscreen-table-modal,
.d-modal.fullscreen-code-modal {
.d-modal {
&__container {
max-height: 100vh;
}
}
.modal-close {
margin-left: auto;
}
}
.d-modal.fullscreen-table-modal {
.d-modal {
&__container {
max-width: $reply-area-max-width;
max-height: unset;
display: grid;
grid-template-rows: auto 1fr auto;
}
&__header {
justify-content: flex-end;
&__footer {
justify-content: space-between;
}
}
}
.d-modal.fullscreen-code-modal {
pre {
margin: 0;
code {
max-width: none;
max-height: none;
padding: 1rem;
white-space: pre;
}
}
}

View File

@ -377,6 +377,7 @@ en:
copied: "copied!"
copy: "copy code to clipboard"
fullscreen: "show code in full screen"
view_code: "View code"
drafts:
label: "Drafts"
@ -4454,6 +4455,7 @@ en:
sr_jump_bottom_button: "Jump to the last post"
fullscreen_table:
expand_btn: "Expand Table"
view_table: "View Table"
second_factor_auth:
redirect_after_success: "Second factor authentication is successful. Redirecting to the previous page…"