Skip to content

Commit 0f3ae62

Browse files
committed
rustdoc: use checkbox instead of switch for settings toggles
The switch is designed to give the application a "physical" feel, but nothing else in here really followed through. They didn't support the "flick" gesture that real iOS switches support, and the radio buttons that were also used in Rustdoc Settings were a more "classic" form element anyway. Also, while "switches" are the exclusive toggle design on iOS (since [Apple HIG] reserves checkboxes for Mac only), the [Google Material] guidelines say that lists of switches are bad, and you should just use check boxes. [Apple HIG]: https://developer.apple.com/design/human-interface-guidelines/components/selection-and-input/toggles [Google Material]: https://m3.material.io/components/checkbox/guidelines#6902f23d-ceba-4b19-ae3b-b78b9b01d185
1 parent a3c0a02 commit 0f3ae62

File tree

7 files changed

+25
-78
lines changed

7 files changed

+25
-78
lines changed

src/librustdoc/html/static/css/settings.css

+19-38
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
flex-wrap: wrap;
99
}
1010

11-
.setting-line .radio-line input {
11+
.setting-line .radio-line input,
12+
.setting-line .toggle input {
1213
margin-right: 0.3em;
1314
height: 1.2rem;
1415
width: 1.2rem;
@@ -17,9 +18,18 @@
1718
outline: none;
1819
-webkit-appearance: none;
1920
cursor: pointer;
21+
}
22+
.setting-line .radio-line input {
2023
border-radius: 50%;
2124
}
22-
.setting-line .radio-line input + span {
25+
.setting-line .toggle input:checked {
26+
content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">\
27+
<path d="M7,25L17,32L33,12" fill="none" stroke="black" stroke-width="5"/>\
28+
<path d="M7,23L17,30L33,10" fill="none" stroke="white" stroke-width="5"/></svg>');
29+
}
30+
31+
.setting-line .radio-line input + span,
32+
.setting-line .toggle span {
2333
padding-bottom: 1px;
2434
}
2535

@@ -49,37 +59,6 @@
4959
cursor: pointer;
5060
}
5161

52-
.toggle input {
53-
opacity: 0;
54-
position: absolute;
55-
}
56-
57-
.slider {
58-
position: relative;
59-
width: 45px;
60-
min-width: 45px;
61-
display: block;
62-
height: 28px;
63-
margin-right: 20px;
64-
cursor: pointer;
65-
background-color: #ccc;
66-
transition: .3s;
67-
}
68-
69-
.slider:before {
70-
position: absolute;
71-
content: "";
72-
height: 19px;
73-
width: 19px;
74-
left: 4px;
75-
bottom: 4px;
76-
transition: .3s;
77-
}
78-
79-
input:checked + .slider:before {
80-
transform: translateX(19px);
81-
}
82-
8362
.setting-line > .sub-settings {
8463
padding-left: 42px;
8564
width: 100%;
@@ -94,17 +73,19 @@ input:checked + .slider:before {
9473
box-shadow: inset 0 0 0 3px var(--main-background-color);
9574
background-color: var(--settings-input-color);
9675
}
97-
.setting-line .radio-line input:focus {
76+
.setting-line .toggle input:checked {
77+
background-color: var(--settings-input-color);
78+
}
79+
.setting-line .radio-line input:focus,
80+
.setting-line .toggle input:focus {
9881
box-shadow: 0 0 1px 1px var(--settings-input-color);
9982
}
10083
/* In here we combine both `:focus` and `:checked` properties. */
10184
.setting-line .radio-line input:checked:focus {
10285
box-shadow: inset 0 0 0 3px var(--main-background-color),
10386
0 0 2px 2px var(--settings-input-color);
10487
}
105-
.setting-line .radio-line input:hover {
88+
.setting-line .radio-line input:hover,
89+
.setting-line .toggle input:hover {
10690
border-color: var(--settings-input-color) !important;
10791
}
108-
input:checked + .slider {
109-
background-color: var(--settings-input-color);
110-
}

src/librustdoc/html/static/css/themes/ayu.css

-10
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,6 @@ Original by Dempfi (https://github.com/dempfi/ayu)
7575
--crate-search-hover-border: #e0e0e0;
7676
}
7777

78-
.slider {
79-
background-color: #ccc;
80-
}
81-
.slider:before {
82-
background-color: white;
83-
}
84-
input:focus + .slider {
85-
box-shadow: 0 0 0 2px #0a84ff, 0 0 0 6px rgba(10, 132, 255, 0.3);
86-
}
87-
8878
h1, h2, h3, h4 {
8979
color: white;
9080
}

src/librustdoc/html/static/css/themes/dark.css

-10
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,6 @@
7070
--crate-search-hover-border: #2196f3;
7171
}
7272

73-
.slider {
74-
background-color: #ccc;
75-
}
76-
.slider:before {
77-
background-color: white;
78-
}
79-
input:focus + .slider {
80-
box-shadow: 0 0 0 2px #0a84ff, 0 0 0 6px rgba(10, 132, 255, 0.3);
81-
}
82-
8373
.content .item-info::before { color: #ccc; }
8474

8575
body.source .example-wrap pre.rust a {

src/librustdoc/html/static/css/themes/light.css

-9
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,6 @@
6767
--crate-search-hover-border: #717171;
6868
}
6969

70-
.slider {
71-
background-color: #ccc;
72-
}
73-
.slider:before {
74-
background-color: white;
75-
}
76-
input:focus + .slider {
77-
box-shadow: 0 0 0 2px #0a84ff, 0 0 0 6px rgba(10, 132, 255, 0.3);
78-
}
7970

8071
.content .item-info::before { color: #ccc; }
8172

src/librustdoc/html/static/js/settings.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666

6767
function setEvents(settingsElement) {
6868
updateLightAndDark();
69-
onEachLazy(settingsElement.getElementsByClassName("slider"), elem => {
70-
const toggle = elem.previousElementSibling;
69+
onEachLazy(settingsElement.querySelectorAll("input[type=\"checkbox\"]"), toggle => {
7170
const settingId = toggle.id;
7271
const settingValue = getSettingValue(settingId);
7372
if (settingValue !== null) {
@@ -139,7 +138,6 @@
139138
const checked = setting["default"] === true ? " checked" : "";
140139
output += `<label class="toggle">\
141140
<input type="checkbox" id="${js_data_name}"${checked}>\
142-
<span class="slider"></span>\
143141
<span class="label">${setting_name}</span>\
144142
</label>`;
145143
}

src/test/rustdoc-gui/docblock-code-block-line-number.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ wait-for: "#settings"
3030
assert-css: ("#settings", {"display": "block"})
3131

3232
// Then, click the toggle button.
33-
click: "input#line-numbers + .slider"
33+
click: "input#line-numbers"
3434
wait-for: 100 // wait-for-false does not exist
3535
assert-false: "pre.example-line-numbers"
3636

3737
// Finally, turn it on again.
38-
click: "input#line-numbers + .slider"
38+
click: "input#line-numbers"
3939
wait-for: "pre.example-line-numbers"

src/test/rustdoc-gui/settings.goml

+3-6
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ assert: ".setting-line.hidden #theme"
118118
assert-text: ("#preferred-dark-theme .setting-name", "Preferred dark theme")
119119
assert-text: ("#preferred-light-theme .setting-name", "Preferred light theme")
120120

121-
// We now check that clicking on the "sliders"' text is like clicking on the slider.
121+
// We now check that clicking on the toggles' text is like clicking on the checkbox.
122122
// To test it, we use the "Disable keyboard shortcuts".
123123
local-storage: {"rustdoc-disable-shortcuts": "false"}
124124
click: ".setting-line:last-child .toggle .label"
@@ -141,10 +141,7 @@ assert-css: ("#settings-menu .popover", {"display": "none"})
141141
// Now we go to the settings page to check that the CSS is loaded as expected.
142142
goto: "file://" + |DOC_PATH| + "/settings.html"
143143
wait-for: "#settings"
144-
assert-css: (
145-
".setting-line .toggle .slider",
146-
{"width": "45px", "margin-right": "20px", "border": "0px none rgb(0, 0, 0)"},
147-
)
144+
assert-css: (".setting-line", {"position": "relative"})
148145

149146
assert-attribute-false: ("#settings", {"class": "popover"}, CONTAINS)
150147
compare-elements-position: (".sub form", "#settings", ("x"))
@@ -162,4 +159,4 @@ reload:
162159
size: (300, 1000)
163160
click: "#settings-menu"
164161
wait-for: "#settings"
165-
assert-css: ("#settings .slider", {"width": "45px"}, ALL)
162+
assert-css: (".setting-line", {"position": "relative"})

0 commit comments

Comments
 (0)