Skip to content

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

UX: Refine typography and spacing in GitHub oneboxes (#45481)

Alan Guo Xiang Tan60e91171d240
diff --git a/app/assets/stylesheets/common/base/onebox.scss b/app/assets/stylesheets/common/base/onebox.scss
index fca07d8230a..32ee1f86c06 100644
--- a/app/assets/stylesheets/common/base/onebox.scss
+++ b/app/assets/stylesheets/common/base/onebox.scss
@@ -776,7 +776,7 @@ aside.onebox.github-onebox {
--github-onebox-header-background: var(--primary-very-low);
--onebox-border-color: light-dark(#d1d9e0, #3d444d);
--onebox-shadow-color: transparent;
- --onebox-shadow-width: 1px;
+ --onebox-shadow-width: var(--token-border-width);
container: github-onebox / inline-size;
padding: 0;
overflow: hidden;
@@ -839,7 +839,7 @@ aside.onebox.github-onebox {
> .source.github-onebox__header {
display: grid;
grid-template-columns: minmax(0, 3fr) minmax(max-content, 1fr);
- gap: 0.5em 1em;
+ column-gap: 1em;
margin: 0;
padding: 0.5em 1em;
background: var(--github-onebox-header-background);
@@ -857,7 +857,6 @@ aside.onebox.github-onebox {
align-items: center;
gap: 0.5em;
min-width: 0;
- overflow-wrap: anywhere;
}
.github-onebox__label {
@@ -878,33 +877,124 @@ aside.onebox.github-onebox {
}
> .onebox-body {
- padding: 0.8em 1em 1em;
+ padding: var(--space-3) var(--space-4);
+
+ h3,
+ h4 {
+ margin-block: 0 var(--space-2);
+ font-size: var(--font-0);
+ font-weight: var(--token-font-weight-semibold);
+ line-height: var(--line-height-large);
+ }
}
&:is(.githubpullrequest, .githubissue, .githubcommit) > .onebox-body {
grid-template-columns: minmax(0, 1fr);
grid-template-areas: "title" "branches" "info" "body";
+ gap: 0;
}
&.githubactions .github-row {
display: block;
}
+ .github-pull-request__title {
+ @include line-clamp(3);
+ overflow-wrap: anywhere;
+ }
+
+ .branches,
+ .labels {
+ margin-block-end: var(--space-1);
+ }
+
+ .branches {
+ display: flex;
+ align-items: baseline;
+ gap: var(--space-1);
+ font-size: var(--font-down-2);
+
+ code {
+ @include ellipsis;
+ font-size: inherit;
+ border-radius: var(--token-radius-small);
+ }
+
+ code:first-of-type {
+ flex: 0 0 auto;
+ max-width: 45%;
+ }
+ }
+
+ .github-info {
+ gap: var(--space-1);
+ font-size: var(--font-down-1);
+ line-height: var(--line-height-large);
+ color: var(--token-color-text-subtle);
+
+ > div + div {
+ display: inline-flex;
+ align-items: center;
+ gap: var(--space-1);
+
+ &::before {
+ content: "·";
+ }
+ }
+
+ .user a {
+ display: flex;
+ align-items: center;
+ gap: var(--space-1);
+ color: var(--primary);
+ }
+
+ .user a,
+ .discourse-local-date.cooked-date .relative-time {
+ text-decoration: underline dashed var(--primary-low-mid);
+ text-decoration-thickness: var(--token-border-width);
+ text-underline-offset: 0.2em;
+ }
+
+ .discourse-local-date.cooked-date {
+ border-bottom: 0;
+ }
+
+ .lines {
+ a {
+ display: flex;
+ gap: var(--space-1);
+ }
+ }
+ }
+
+ .onebox-avatar-inline {
+ width: var(--space-4);
+ height: var(--space-4);
+ }
+
+ .github-body-container {
+ margin: var(--space-3) 0 0;
+ max-width: 65ch;
+ font-family: inherit;
+ font-size: var(--font-down-1);
+ line-height: var(--cooked-line-height);
+ color: var(--token-color-text-default);
+ }
+
+ .github-repo-description,
+ .label1 {
+ font-size: var(--font-down-1);
+ line-height: var(--cooked-line-height);
+ }
+
@container github-onebox (width < 28rem) {
> .source.github-onebox__header {
grid-template-columns: minmax(0, 1fr) auto;
}
- .github-onebox__label {
- gap: 0;
-
- > span {
- position: absolute;
- width: 1px;
- height: 1px;
- overflow: hidden;
- clip-path: inset(50%);
- }
+ .github-onebox__label[aria-label] > span {
+ display: none;
}
}
}
@@ -973,9 +1063,6 @@ aside.onebox.github-onebox {
}
.github-info-container {
- width: 100%;
- overflow-x: hidden;
-
> span {
// TODO: remove in a few months
// replaced by .github-info in new commit oneboxes
@@ -988,7 +1075,6 @@ aside.onebox.github-onebox {
display: flex;
align-items: center;
flex-wrap: wrap;
- width: 100%;
gap: 0.15em 0.75em;
.lines {
@@ -1019,7 +1105,6 @@ aside.onebox.github-onebox {
font-family: var(--d-font-family--monospace);
font-size: 0.875em;
line-height: calc((13 + 4) / 13);
- box-sizing: border-box;
@include viewport.until(sm) {
max-height: 50vh;
@@ -1034,7 +1119,7 @@ aside.onebox.github-onebox {
}
.onebox-avatar-inline {
- border-radius: 2px;
+ border-radius: var(--token-radius-small);
vertical-align: text-bottom;
}
@@ -1047,7 +1132,7 @@ aside.onebox.github-onebox {
// !important required to override inline style attribute
background-color: var(--primary-medium) !important;
color: var(--secondary) !important;
- padding: 2px 4px !important;
+ padding: var(--space-half) var(--space-1) !important;
white-space: nowrap;
}
}
diff --git a/app/assets/stylesheets/embed.scss b/app/assets/stylesheets/embed.scss
index abd9da69b34..83da00ccaf1 100644
--- a/app/assets/stylesheets/embed.scss
+++ b/app/assets/stylesheets/embed.scss
@@ -1,5 +1,6 @@
@import "./vendor/normalize";
@import "./vendor/normalize-ext";
+@import "./common/tokens";
@import "./common/foundation/base";
@import "./color_definitions";
@import "./common/components/buttons";
diff --git a/lib/onebox/sanitize_config.rb b/lib/onebox/sanitize_config.rb
index c1e6875ce37..2a4a2c36d40 100644
--- a/lib/onebox/sanitize_config.rb
+++ b/lib/onebox/sanitize_config.rb
@@ -40,7 +40,7 @@ module Onebox
"path" => %w[d fill-rule],
"svg" => %w[aria-hidden width height viewbox],
"div" => [:data], # any data-* attributes,
- "span" => [:data], # any data-* attributes,
+ "span" => [:data, "role", "aria-label"], # any data-* attributes,
"use" => %w[href],
},
add_attributes: {
diff --git a/lib/onebox/templates/githubactions_header.mustache b/lib/onebox/templates/githubactions_header.mustache
index 3ebf965ddad..c5f179f674f 100644
--- a/lib/onebox/templates/githubactions_header.mustache
+++ b/lib/onebox/templates/githubactions_header.mustache
@@ -1,5 +1,5 @@
<header class="source github-onebox__header">
- <span class="github-onebox__label">
+ <span class="github-onebox__label" role="img" aria-label="{{#run_number}}{{#success}}{{i18n.header.success}}{{/success}}{{#failure}}{{i18n.header.failure}}{{/failure}}{{#pending}}{{i18n.header.pending}}{{/pending}}{{#unknown}}{{i18n.header.unknown}}{{/unknown}}{{/run_number}}{{^run_number}}{{i18n.header.check_run}}{{/run_number}}" title="{{#run_number}}{{#success}}{{i18n.header.success}}{{/success}}{{#failure}}{{i18n.header.failure}}{{/failure}}{{#pending}}{{i18n.header.pending}}{{/pending}}{{#unknown}}{{i18n.header.unknown}}{{/unknown}}{{/run_number}}{{^run_number}}{{i18n.header.check_run}}{{/run_number}}">
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
{{#success}}
<path fill-rule="evenodd" d="M8 16A8 8 0 1 1 8 0a8 8 0 0 1 0 16Zm3.78-9.72a.751.751 0 0 0-.018-1.042.751.751 0 0 0-1.042-.018L6.75 9.19 5.28 7.72a.751.751 0 0 0-1.042.018.751.751 0 0 0-.018 1.042l2 2a.75.75 0 0 0 1.06 0Z"></path>
diff --git a/lib/onebox/templates/githubblob_header.mustache b/lib/onebox/templates/githubblob_header.mustache
index 79735a9c1d5..17263bc9b60 100644
--- a/lib/onebox/templates/githubblob_header.mustache
+++ b/lib/onebox/templates/githubblob_header.mustache
@@ -1,5 +1,5 @@
<header class="source github-onebox__header">
- <span class="github-onebox__label">
+ <span class="github-onebox__label" role="img" aria-label="{{#binary}}{{i18n.header.binary_file}}{{/binary}}{{^binary}}{{i18n.header.file}}{{/binary}}" title="{{#binary}}{{i18n.header.binary_file}}{{/binary}}{{^binary}}{{i18n.header.file}}{{/binary}}">
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
{{#binary}}
<path fill-rule="evenodd" d="M4 1.75C4 .784 4.784 0 5.75 0h5.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v8.586A1.75 1.75 0 0 1 14.25 15h-9a.75.75 0 0 1 0-1.5h9a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 10 4.25V1.5H5.75a.25.25 0 0 0-.25.25v2a.75.75 0 0 1-1.5 0Zm-4 6C0 6.784.784 6 1.75 6h1.5C4.216 6 5 6.784 5 7.75v2.5A1.75 1.75 0 0 1 3.25 12h-1.5A1.75 1.75 0 0 1 0 10.25ZM6.75 6h1.5a.75.75 0 0 1 .75.75v3.75h.75a.75.75 0 0 1 0 1.5h-3a.75.75 0 0 1 0-1.5h.75v-3h-.75a.75.75 0 0 1 0-1.5Zm-5 1.5a.25.25 0 0 0-.25.25v2.5c0 .138.112.25.25.25h1.5a.25.25 0 0 0 .25-.25v-2.5a.25.25 0 0 0-.25-.25Zm9.75-5.938V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path>
diff --git a/lib/onebox/templates/githubcommit_header.mustache b/lib/onebox/templates/githubcommit_header.mustache
index 6f296d2bae3..c0a68b70acc 100644
--- a/lib/onebox/templates/githubcommit_header.mustache
+++ b/lib/onebox/templates/githubcommit_header.mustache
@@ -1,5 +1,5 @@
<header class="source github-onebox__header">
- <span class="github-onebox__label">
+ <span class="github-onebox__label" role="img" aria-label="{{i18n.header.commit}}" title="{{i18n.header.commit}}">
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M11.93 8.5a4.002 4.002 0 0 1-7.86 0H.75a.75.75 0 0 1 0-1.5h3.32a4.002 4.002 0 0 1 7.86 0h3.32a.75.75 0 0 1 0 1.5Zm-1.43-.75a2.5 2.5 0 1 0-5 0 2.5 2.5 0 0 0 5 0Z"></path></svg>
<span>{{i18n.header.commit}}</span>
</span>
diff --git a/lib/onebox/templates/githubfolder_header.mustache b/lib/onebox/templates/githubfolder_header.mustache
index e400f9c68b7..77286dbabdd 100644
--- a/lib/onebox/templates/githubfolder_header.mustache
+++ b/lib/onebox/templates/githubfolder_header.mustache
@@ -1,5 +1,5 @@
<header class="source github-onebox__header">
- <span class="github-onebox__label">
+ <span class="github-onebox__label" role="img" aria-label="{{i18n.header.folder}}" title="{{i18n.header.folder}}">
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M1.75 1A1.75 1.75 0 0 0 0 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0 0 16 13.25v-8.5A1.75 1.75 0 0 0 14.25 3H7.5a.25.25 0 0 1-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75Z"></path></svg>
<span>{{i18n.header.folder}}</span>
</span>
diff --git a/lib/onebox/templates/githubgist_header.mustache b/lib/onebox/templates/githubgist_header.mustache
index 4f6386e8f00..668e9fb91f1 100644
--- a/lib/onebox/templates/githubgist_header.mustache
+++ b/lib/onebox/templates/githubgist_header.mustache
@@ -1,5 +1,5 @@
<header class="source github-onebox__header">
- <span class="github-onebox__label">
+ <span class="github-onebox__label" role="img" aria-label="{{i18n.header.gist}}" title="{{i18n.header.gist}}">
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M5.97 5.72a.75.75 0 1 1 1.06 1.06L5.81 8l1.22 1.22a.75.75 0 1 1-1.06 1.06L4.22 8.53a.75.75 0 0 1 0-1.06zm3 0a.75.75 0 0 1 1.06 0l1.75 1.75a.75.75 0 0 1 0 1.06l-1.75 1.75a.75.75 0 1 1-1.06-1.06L10.19 8 8.97 6.78a.75.75 0 0 1 0-1.06 M13.25 1c.966 0 1.75.784 1.75 1.75v10.5A1.75 1.75 0 0 1 13.25 15H2.75A1.75 1.75 0 0 1 1 13.25V2.75C1 1.784 1.784 1 2.75 1zM2.75 2.5a.25.25 0 0 0-.25.25v10.5c0 .138.112.25.25.25h10.5a.25.25 0 0 0 .25-.25V2.75a.25.25 0 0 0-.25-.25z"></path></svg>
<span>{{i18n.header.gist}}</span>
</span>
diff --git a/lib/onebox/templates/githubissue_header.mustache b/lib/onebox/templates/githubissue_header.mustache
index 6afdded7c69..88a017ce937 100644
--- a/lib/onebox/templates/githubissue_header.mustache
+++ b/lib/onebox/templates/githubissue_header.mustache
@@ -1,5 +1,5 @@
<header class="source github-onebox__header">
- <span class="github-onebox__label">
+ <span class="github-onebox__label" role="img" aria-label="{{#closed_at}}{{i18n.header.closed_issue}}{{/closed_at}}{{^closed_at}}{{i18n.header.open_issue}}{{/closed_at}}" title="{{#closed_at}}{{i18n.header.closed_issue}}{{/closed_at}}{{^closed_at}}{{i18n.header.open_issue}}{{/closed_at}}">
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Z"></path></svg>
<span>{{#closed_at}}{{i18n.header.closed_issue}}{{/closed_at}}{{^closed_at}}{{i18n.header.open_issue}}{{/closed_at}}</span>
</span>
diff --git a/lib/onebox/templates/githubpullrequest.mustache b/lib/onebox/templates/githubpullrequest.mustache
index da83d3fdff9..107a0defc89 100644
--- a/lib/onebox/templates/githubpullrequest.mustache
+++ b/lib/onebox/templates/githubpullrequest.mustache
@@ -2,18 +2,12 @@
<div class="github-info-container">
{{#commit}}
<h4>
- <a href="{{link}}" target="_blank" rel="noopener">{{commit.message.lines.first}}</a>
+ {{i18n.commit_by}}
+ <a href="{{author.html_url}}" target="_blank" rel="noopener">
+ <img alt="" src="{{author.avatar_url}}" class="onebox-avatar-inline" width="20" height="20">
+ {{author.login}}
+ </a> - <a href="{{link}}" target="_blank" rel="noopener">{{commit.message.lines.first}}</a>
</h4>
-
- <div class="github-info">
- <span>
- {{i18n.commit_by}}
- <a href="{{author.html_url}}" target="_blank" rel="noopener">
- <img alt="" src="{{author.avatar_url}}" class="onebox-avatar-inline" width="20" height="20">
- {{author.login}}
- </a> - <a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>
- </span>
- </div>
{{/commit}}
{{#comment}}
@@ -38,12 +32,12 @@
{{#pr}}
<h4>
- <a href="{{link}}" target="_blank" rel="noopener">{{title}} (#{{number}})</a>
+ <a class="github-pull-request__title" href="{{link}}" title="{{title}} (#{{number}})" target="_blank" rel="noopener">{{title}} (#{{number}})</a>
</h4>
{{/pr}}
<div class="branches">
- <code>{{base.label}}</code> ← <code>{{head.label}}</code>
+ <code title="{{base.label}}">{{base.label}}</code> ← <code title="{{head.label}}">{{head.label}}</code>
</div>
{{#pr}}
diff --git a/lib/onebox/templates/githubpullrequest_header.mustache b/lib/onebox/templates/githubpullrequest_header.mustache
index 4034992d3c2..96a5192c3c2 100644
--- a/lib/onebox/templates/githubpullrequest_header.mustache
+++ b/lib/onebox/templates/githubpullrequest_header.mustache
@@ -1,5 +1,5 @@
<header class="source github-onebox__header">
- <span class="github-onebox__label">
+ <span class="github-onebox__label" role="img" aria-label="{{#comment}}{{i18n.header.comment}}{{/comment}}{{#discussion}}{{i18n.header.review}}{{/discussion}}{{#commit}}{{i18n.header.commit}}{{/commit}}{{#pr}}{{#pr_status_data}}{{label}}{{/pr_status_data}}{{^pr_status_data}}{{i18n.header.pull_request}}{{/pr_status_data}}{{/pr}}" title="{{#comment}}{{i18n.header.comment}}{{/comment}}{{#discussion}}{{i18n.header.review}}{{/discussion}}{{#commit}}{{i18n.header.commit}}{{/commit}}{{#pr}}{{#pr_status_data}}{{label}}{{/pr_status_data}}{{^pr_status_data}}{{i18n.header.pull_request}}{{/pr_status_data}}{{/pr}}">
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">
{{#comment}}
<path fill-rule="evenodd" d="M1.75 1h8.5c.966 0 1.75.784 1.75 1.75v5.5A1.75 1.75 0 0 1 10.25 10H7.061l-2.574 2.573A1.458 1.458 0 0 1 2 11.543V10h-.25A1.75 1.75 0 0 1 0 8.25v-5.5C0 1.784.784 1 1.75 1ZM1.5 2.75v5.5c0 .138.112.25.25.25h1a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h3.5a.25.25 0 0 0 .25-.25v-5.5a.25.25 0 0 0-.25-.25h-8.5a.25.25 0 0 0-.25.25Zm13 2a.25.25 0 0 0-.25-.25h-.5a.75.75 0 0 1 0-1.5h.5c.966 0 1.75.784 1.75 1.75v5.5A1.75 1.75 0 0 1 14.25 12H14v1.543a1.458 1.458 0 0 1-2.487 1.03L9.22 12.28a.749.749 0 0 1 .326-1.275.749.749 0 0 1 .734.215l2.22 2.22v-2.19a.75.75 0 0 1 .75-.75h1a.25.25 0 0 0 .25-.25Z"></path>
diff --git a/lib/onebox/templates/githubrepo_header.mustache b/lib/onebox/templates/githubrepo_header.mustache
index 05835e80ee3..66dc6a7c9fd 100644
--- a/lib/onebox/templates/githubrepo_header.mustache
+++ b/lib/onebox/templates/githubrepo_header.mustache
@@ -1,5 +1,5 @@
<header class="source github-onebox__header">
- <span class="github-onebox__label">
+ <span class="github-onebox__label" role="img" aria-label="{{i18n.header.repository}}" title="{{i18n.header.repository}}">
<svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path></svg>
<span>{{i18n.header.repository}}</span>
</span>
diff --git a/spec/lib/onebox/engine/github_pull_request_onebox_spec.rb b/spec/lib/onebox/engine/github_pull_request_onebox_spec.rb
index deeb60c1dd2..b32343bfccf 100644
--- a/spec/lib/onebox/engine/github_pull_request_onebox_spec.rb
+++ b/spec/lib/onebox/engine/github_pull_request_onebox_spec.rb
@@ -40,7 +40,9 @@ RSpec.describe Onebox::Engine::GithubPullRequestOnebox do
end
it "includes branch names" do
- expect(html).to include("<code>main</code> ← <code>jamesaanderson:add-audio-onebox</code>")
+ expect(html).to include(
+ '<code title="main">main</code> ← <code title="jamesaanderson:add-audio-onebox">jamesaanderson:add-audio-onebox</code>',
+ )
end
it "includes commit author gravatar" do
@@ -271,10 +273,10 @@ RSpec.describe Onebox::Engine::GithubPullRequestOnebox do
)
end
- it "includes commit name" do
+ it "includes the commit author and title" do
doc = Nokogiri.HTML5(html)
expect(doc.at_css(".github-onebox__label").text.strip).to eq("Commit")
- expect(doc.css("h4").text.strip).to eq("Add audio onebox")
+ expect(doc.css("h4").text.squish).to eq("Commit by jamesaanderson - Add audio onebox")
expect(doc.css(".github-body-container").text).to include(
"http://meta.discourse.org/t/audio-html5-tag/8168",
)