Skip to content

Commit

Permalink
rustdoc: rename CSS rustdoc-toggle -> toggle and toggle -> settings-t…
Browse files Browse the repository at this point in the history
…oggle

This swaps things around so that the class that gets used more often has
the shorter name.
  • Loading branch information
notriddle committed Jan 13, 2023
1 parent 0b90256 commit 1d328de
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 117 deletions.
8 changes: 4 additions & 4 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ fn document_full_inner(
debug!("Doc block: =====\n{}\n=====", s);
if is_collapsible {
w.write_str(
"<details class=\"rustdoc-toggle top-doc\" open>\
"<details class=\"toggle top-doc\" open>\
<summary class=\"hideme\">\
<span>Expand description</span>\
</summary>",
Expand Down Expand Up @@ -1514,7 +1514,7 @@ fn render_impl(
let toggled = !doc_buffer.is_empty();
if toggled {
let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" };
write!(w, "<details class=\"rustdoc-toggle{}\" open><summary>", method_toggle_class);
write!(w, "<details class=\"toggle{}\" open><summary>", method_toggle_class);
}
match &*item.kind {
clean::MethodItem(..) | clean::TyMethodItem(_) => {
Expand Down Expand Up @@ -1730,7 +1730,7 @@ fn render_impl(
close_tags.insert_str(0, "</details>");
write!(
w,
"<details class=\"rustdoc-toggle implementors-toggle\"{}>",
"<details class=\"toggle implementors-toggle\"{}>",
if rendering_params.toggle_open_by_default { " open" } else { "" }
);
write!(w, "<summary>")
Expand Down Expand Up @@ -2999,7 +2999,7 @@ fn render_call_locations(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Ite
if it.peek().is_some() {
write!(
w,
"<details class=\"rustdoc-toggle more-examples-toggle\">\
"<details class=\"toggle more-examples-toggle\">\
<summary class=\"hideme\">\
<span>More examples</span>\
</summary>\
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn should_hide_fields(n_fields: usize) -> bool {
fn toggle_open(w: &mut Buffer, text: impl fmt::Display) {
write!(
w,
"<details class=\"rustdoc-toggle type-contents-toggle\">\
"<details class=\"toggle type-contents-toggle\">\
<summary class=\"hideme\">\
<span>Show {}</span>\
</summary>",
Expand Down Expand Up @@ -733,7 +733,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
let toggled = !content.is_empty();
if toggled {
let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" };
write!(w, "<details class=\"rustdoc-toggle{method_toggle_class}\" open><summary>");
write!(w, "<details class=\"toggle{method_toggle_class}\" open><summary>");
}
write!(w, "<section id=\"{}\" class=\"method has-srclink\">", id);
render_rightside(w, cx, m, t, RenderMode::Normal);
Expand Down Expand Up @@ -1840,7 +1840,7 @@ fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) {
if item.is_non_exhaustive() {
write!(
w,
"<details class=\"rustdoc-toggle non-exhaustive\">\
"<details class=\"toggle non-exhaustive\">\
<summary class=\"hideme\"><span>{}</span></summary>\
<div class=\"docblock\">",
{
Expand Down
72 changes: 36 additions & 36 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ main {
margin-right: auto;
}

details:not(.rustdoc-toggle) summary {
details:not(.toggle) summary {
margin-bottom: .6em;
}

Expand Down Expand Up @@ -1401,34 +1401,34 @@ details.dir-entry a {
Unfortunately we can't yet specify contain: content or contain: strict
because the [-]/[+] toggles extend past the boundaries of the <details>
https://developer.mozilla.org/en-US/docs/Web/CSS/contain */
details.rustdoc-toggle {
details.toggle {
contain: layout;
position: relative;
}

/* The hideme class is used on summary tags that contain a span with
placeholder text shown only when the toggle is closed. For instance,
"Expand description" or "Show methods". */
details.rustdoc-toggle > summary.hideme {
details.toggle > summary.hideme {
cursor: pointer;
font-size: 1rem;
}

details.rustdoc-toggle > summary {
details.toggle > summary {
list-style: none;
/* focus outline is shown on `::before` instead of this */
outline: none;
}
details.rustdoc-toggle > summary::-webkit-details-marker,
details.rustdoc-toggle > summary::marker {
details.toggle > summary::-webkit-details-marker,
details.toggle > summary::marker {
display: none;
}

details.rustdoc-toggle > summary.hideme > span {
details.toggle > summary.hideme > span {
margin-left: 9px;
}

details.rustdoc-toggle > summary::before {
details.toggle > summary::before {
background: url("toggle-plus-1092eb4930d581b0.svg") no-repeat top left;
content: "";
cursor: pointer;
Expand All @@ -1440,32 +1440,32 @@ details.rustdoc-toggle > summary::before {
filter: var(--toggle-filter);
}

details.rustdoc-toggle > summary.hideme > span,
details.toggle > summary.hideme > span,
.more-examples-toggle summary, .more-examples-toggle .hide-more {
color: var(--toggles-color);
}

/* Screen readers see the text version at the end the line.
Visual readers see the icon at the start of the line, but small and transparent. */
details.rustdoc-toggle > summary::after {
details.toggle > summary::after {
content: "Expand";
overflow: hidden;
width: 0;
height: 0;
position: absolute;
}

details.rustdoc-toggle > summary.hideme::after {
details.toggle > summary.hideme::after {
/* "hideme" toggles already have a description when they're contracted */
content: "";
}

details.rustdoc-toggle > summary:focus::before,
details.rustdoc-toggle > summary:hover::before {
details.toggle > summary:focus::before,
details.toggle > summary:hover::before {
opacity: 1;
}

details.rustdoc-toggle > summary:focus-visible::before {
details.toggle > summary:focus-visible::before {
/* The SVG is black, and gets turned white using a filter in the dark themes.
Do the same with the outline.
The dotted 1px style is copied from Firefox's focus ring style.
Expand All @@ -1478,17 +1478,17 @@ details.non-exhaustive {
margin-bottom: 8px;
}

details.rustdoc-toggle > summary.hideme::before {
details.toggle > summary.hideme::before {
position: relative;
}

details.rustdoc-toggle > summary:not(.hideme)::before {
details.toggle > summary:not(.hideme)::before {
position: absolute;
left: -24px;
top: 4px;
}

.impl-items > details.rustdoc-toggle > summary:not(.hideme)::before {
.impl-items > details.toggle > summary:not(.hideme)::before {
position: absolute;
left: -24px;
}
Expand All @@ -1498,19 +1498,19 @@ details.rustdoc-toggle > summary:not(.hideme)::before {
affect the layout of the items to its right. To do that, we use
absolute positioning. Note that we also set position: relative
on the parent <details> to make this work properly. */
details.rustdoc-toggle[open] > summary.hideme {
details.toggle[open] > summary.hideme {
position: absolute;
}

details.rustdoc-toggle[open] > summary.hideme > span {
details.toggle[open] > summary.hideme > span {
display: none;
}

details.rustdoc-toggle[open] > summary::before {
details.toggle[open] > summary::before {
background: url("toggle-minus-31bbd6e4c77f5c96.svg") no-repeat top left;
}

details.rustdoc-toggle[open] > summary::after {
details.toggle[open] > summary::after {
content: "Collapse";
}

Expand Down Expand Up @@ -1660,8 +1660,8 @@ in storage.js
display: block;
}

#main-content > details.rustdoc-toggle > summary::before,
#main-content > div > details.rustdoc-toggle > summary::before {
#main-content > details.toggle > summary::before,
#main-content > div > details.toggle > summary::before {
left: -11px;
}

Expand Down Expand Up @@ -1715,12 +1715,12 @@ in storage.js
}

/* Position of the "[-]" element. */
details.rustdoc-toggle:not(.top-doc) > summary {
details.toggle:not(.top-doc) > summary {
margin-left: 10px;
}
.impl-items > details.rustdoc-toggle > summary:not(.hideme)::before,
#main-content > details.rustdoc-toggle:not(.top-doc) > summary::before,
#main-content > div > details.rustdoc-toggle > summary::before {
.impl-items > details.toggle > summary:not(.hideme)::before,
#main-content > details.toggle:not(.top-doc) > summary::before,
#main-content > div > details.toggle > summary::before {
left: -11px;
}

Expand Down Expand Up @@ -1753,8 +1753,8 @@ in storage.js

@media print {
nav.sidebar, nav.sub, .out-of-band, a.srclink, #copy-path,
details.rustdoc-toggle[open] > summary::before, details.rustdoc-toggle > summary::before,
details.rustdoc-toggle.top-doc > summary {
details.toggle[open] > summary::before, details.toggle > summary::before,
details.toggle.top-doc > summary {
display: none;
}

Expand Down Expand Up @@ -1796,24 +1796,24 @@ in storage.js
.impl,
#implementors-list > .docblock,
.impl-items > section,
.impl-items > .rustdoc-toggle > summary,
.impl-items > .toggle > summary,
.methods > section,
.methods > .rustdoc-toggle > summary
.methods > .toggle > summary
{
margin-bottom: 0.75em;
}

.variants > .docblock,
.implementors-toggle > .docblock,
.impl-items > .rustdoc-toggle[open]:not(:last-child),
.methods > .rustdoc-toggle[open]:not(:last-child),
.impl-items > .toggle[open]:not(:last-child),
.methods > .toggle[open]:not(:last-child),
.implementors-toggle[open]:not(:last-child) {
margin-bottom: 2em;
}

#trait-implementations-list .impl-items > .rustdoc-toggle:not(:last-child),
#synthetic-implementations-list .impl-items > .rustdoc-toggle:not(:last-child),
#blanket-implementations-list .impl-items > .rustdoc-toggle:not(:last-child) {
#trait-implementations-list .impl-items > .toggle:not(:last-child),
#synthetic-implementations-list .impl-items > .toggle:not(:last-child),
#blanket-implementations-list .impl-items > .toggle:not(:last-child) {
margin-bottom: 1em;
}

Expand Down
14 changes: 7 additions & 7 deletions src/librustdoc/html/static/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}

.setting-line .radio-line input,
.setting-line .toggle input {
.setting-line .settings-toggle input {
margin-right: 0.3em;
height: 1.2rem;
width: 1.2rem;
Expand All @@ -22,14 +22,14 @@
.setting-line .radio-line input {
border-radius: 50%;
}
.setting-line .toggle input:checked {
.setting-line .settings-toggle input:checked {
content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">\
<path d="M7,25L17,32L33,12" fill="none" stroke="black" stroke-width="5"/>\
<path d="M7,23L17,30L33,10" fill="none" stroke="white" stroke-width="5"/></svg>');
}

.setting-line .radio-line input + span,
.setting-line .toggle span {
.setting-line .settings-toggle span {
padding-bottom: 1px;
}

Expand All @@ -50,7 +50,7 @@
margin-left: 0.5em;
}

.toggle {
.settings-toggle {
position: relative;
width: 100%;
margin-right: 20px;
Expand All @@ -67,11 +67,11 @@
box-shadow: inset 0 0 0 3px var(--main-background-color);
background-color: var(--settings-input-color);
}
.setting-line .toggle input:checked {
.setting-line .settings-toggle input:checked {
background-color: var(--settings-input-color);
}
.setting-line .radio-line input:focus,
.setting-line .toggle input:focus {
.setting-line .settings-toggle input:focus {
box-shadow: 0 0 1px 1px var(--settings-input-color);
}
/* In here we combine both `:focus` and `:checked` properties. */
Expand All @@ -80,6 +80,6 @@
0 0 2px 2px var(--settings-input-color);
}
.setting-line .radio-line input:hover,
.setting-line .toggle input:hover {
.setting-line .settings-toggle input:hover {
border-color: var(--settings-input-color) !important;
}
8 changes: 4 additions & 4 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ function loadCss(cssUrl) {
function expandAllDocs() {
const innerToggle = document.getElementById(toggleAllDocsId);
removeClass(innerToggle, "will-expand");
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
onEachLazy(document.getElementsByClassName("toggle"), e => {
if (!hasClass(e, "type-contents-toggle") && !hasClass(e, "more-examples-toggle")) {
e.open = true;
}
Expand All @@ -632,7 +632,7 @@ function loadCss(cssUrl) {
function collapseAllDocs() {
const innerToggle = document.getElementById(toggleAllDocsId);
addClass(innerToggle, "will-expand");
onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
onEachLazy(document.getElementsByClassName("toggle"), e => {
if (e.parentNode.id !== "implementations-list" ||
(!hasClass(e, "implementors-toggle") &&
!hasClass(e, "type-contents-toggle"))
Expand Down Expand Up @@ -680,7 +680,7 @@ function loadCss(cssUrl) {
setImplementorsTogglesOpen("blanket-implementations-list", false);
}

onEachLazy(document.getElementsByClassName("rustdoc-toggle"), e => {
onEachLazy(document.getElementsByClassName("toggle"), e => {
if (!hideLargeItemContents && hasClass(e, "type-contents-toggle")) {
e.open = true;
}
Expand Down Expand Up @@ -823,7 +823,7 @@ function loadCss(cssUrl) {
});
});

onEachLazy(document.querySelectorAll(".rustdoc-toggle > summary:not(.hideme)"), el => {
onEachLazy(document.querySelectorAll(".toggle > summary:not(.hideme)"), el => {
el.addEventListener("click", e => {
if (e.target.tagName !== "SUMMARY" && e.target.tagName !== "A") {
e.preventDefault();
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@
});
output += "</div></div>";
} else {
// This is a toggle.
// This is a checkbox toggle.
const checked = setting["default"] === true ? " checked" : "";
output += `\
<label class="toggle">\
<label class="settings-toggle">\
<input type="checkbox" id="${js_data_name}"${checked}>\
<span class="label">${setting_name}</span>\
</label>`;
Expand Down
10 changes: 5 additions & 5 deletions tests/rustdoc-gui/method-margins.goml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// This test ensures that the margins on methods are coherent inside an impl block.
goto: "file://" + |DOC_PATH| + "/test_docs/trait_members/struct.HasTrait.html#impl-TraitMembers-for-HasTrait"

assert-count: ("#trait-implementations-list > .rustdoc-toggle", 1)
assert-count: ("#trait-implementations-list > .toggle", 1)

compare-elements-css: (
// compare margin on type with margin on method
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(1) > summary",
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(2) > summary",
"#trait-implementations-list .impl-items > .toggle:nth-child(1) > summary",
"#trait-implementations-list .impl-items > .toggle:nth-child(2) > summary",
["margin"]
)

compare-elements-css: (
// compare margin on type with margin on method
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(1)",
"#trait-implementations-list .impl-items > .rustdoc-toggle:nth-child(2)",
"#trait-implementations-list .impl-items > .toggle:nth-child(1)",
"#trait-implementations-list .impl-items > .toggle:nth-child(2)",
["margin"]
)
Loading

0 comments on commit 1d328de

Please sign in to comment.