UX: moves from summary/details to a button to expand github body (#12698)

This commit is contained in:
Joffrey JAFFEUX 2021-04-15 08:52:04 +02:00 committed by GitHub
parent b5fba751a0
commit ae27717b61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 21 deletions

View File

@ -268,7 +268,7 @@ GEM
omniauth-twitter (1.4.0)
omniauth-oauth (~> 1.1)
rack
onebox (2.2.12)
onebox (2.2.13)
addressable (~> 2.7.0)
htmlentities (~> 4.3)
multi_json (~> 1.11)

View File

@ -0,0 +1,57 @@
import { withPluginApi } from "discourse/lib/plugin-api";
let _showMoreClickPostsElements = [];
function decorateGithubOneboxBody(element) {
const containers = element.querySelectorAll(
".onebox.githubpullrequest .show-more-container, .onebox.githubissue .show-more-container"
);
if (containers.length) {
_showMoreClickPostsElements.push(element);
element.addEventListener("click", _handleClick, false);
}
}
function _handleClick(event) {
if (!event.target.classList.contains("show-more")) {
return;
}
event.preventDefault();
const showMoreContainer = event.target.parentNode;
const bodyContainer = showMoreContainer.parentNode;
showMoreContainer.classList.add("hidden");
bodyContainer.querySelector(".excerpt.hidden").classList.remove("hidden");
return false;
}
function _cleanUp() {
(_showMoreClickPostsElements || []).forEach((element) => {
element.removeEventListener("click", _handleClick);
});
_showMoreClickPostsElements = [];
}
export default {
name: "onebox-decorators",
initialize() {
withPluginApi("0.8.42", (api) => {
api.decorateCookedElement(
(element) => {
decorateGithubOneboxBody(element);
},
{
id: "onebox-github-body",
}
);
api.cleanupStream(_cleanUp);
});
},
};

View File

@ -161,17 +161,26 @@ aside.onebox {
}
}
details.onebox-details {
summary.onebox-details-summary {
display: flex;
h4 {
display: inline-block;
}
}
p.onebox-details-body {
margin: 0 0 0.5em 0;
padding: 0.5em;
background-color: var(--blend-primary-secondary-5);
.github-info + .github-body-container {
margin-top: 1em;
}
.github-body-container {
margin: 0 0 0.5em 0;
padding: 0.5em;
color: var(--primary-very-high);
background: var(--hljs-bg);
max-height: 400px;
white-space: pre-wrap;
overflow-y: auto;
word-break: break-word;
font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono",
"DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace;
font-size: $font-down-1;
.show-more {
// padding on right for larger hitzone
padding: 0.5em 1.5em 0.5em 0.25em;
}
}
@ -495,11 +504,6 @@ pre.onebox code {
max-width: none;
}
.github-content {
margin: 5px 0 0 0;
word-break: break-word;
}
.labels span {
// !important required to override inline style attribute
background-color: var(--primary-medium) !important;
@ -541,10 +545,6 @@ pre.onebox code {
background-color: #bd2c00;
}
.onebox-body .github-content-right {
margin-left: 100px;
}
//Onebox - Twitter - Status
aside.onebox.twitterstatus .onebox-body {
h4 {