Skip to content

Commit 28af6ca

Browse files
authored
Rollup merge of #104267 - notriddle:notriddle/checkbox, r=GuillaumeGomez
rustdoc: use checkbox instead of switch for settings toggles Preview: http://notriddle.com/notriddle-rustdoc-demos/checkbox/test_dingus/index.html ## Before ![image](https://user-images.githubusercontent.com/1593513/201232887-dee27ef5-b091-49bb-be4a-103d2e7983f3.png) ## After ![image](https://user-images.githubusercontent.com/1593513/201232835-95b40b77-6535-4280-8719-44c992a07772.png) ## Description The switch ("slider") 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
2 parents 35816ff + 269dad2 commit 28af6ca

File tree

7 files changed

+104
-82
lines changed

7 files changed

+104
-82
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
@@ -77,16 +77,6 @@ Original by Dempfi (https://github.com/dempfi/ayu)
7777
--crate-search-hover-border: #e0e0e0;
7878
}
7979

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

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

-10
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,6 @@
7272
--crate-search-hover-border: #2196f3;
7373
}
7474

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

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

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

-9
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@
6969
--crate-search-hover-border: #717171;
7070
}
7171

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

8273
.content .item-info::before { color: #ccc; }
8374

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

+82-10
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ assert: ".setting-line.hidden #preferred-light-theme"
4848
assert-property: ("#theme .choices #theme-dark", {"checked": "true"})
4949

5050
// Some style checks...
51-
// First we check the "default" display.
51+
move-cursor-to: "#settings-menu > a"
52+
// First we check the "default" display for radio buttons.
5253
assert-css: (
5354
"#theme-dark",
5455
{
@@ -57,7 +58,7 @@ assert-css: (
5758
},
5859
)
5960
assert-css: ("#theme-light", {"border-color": "rgb(221, 221, 221)", "box-shadow": "none"})
60-
// Let's start with the hover.
61+
// Let's start with the hover for radio buttons.
6162
move-cursor-to: "#theme-dark"
6263
assert-css: (
6364
"#theme-dark",
@@ -69,7 +70,7 @@ assert-css: (
6970
move-cursor-to: "#theme-light"
7071
assert-css: ("#theme-light", {"border-color": "rgb(33, 150, 243)", "box-shadow": "none"})
7172
move-cursor-to: "#theme-ayu"
72-
// Let's now check with the focus.
73+
// Let's now check with the focus for radio buttons.
7374
focus: "#theme-dark"
7475
assert-css: (
7576
"#theme-dark",
@@ -86,7 +87,7 @@ assert-css: (
8687
"box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
8788
},
8889
)
89-
// Now we check we both focus and hover.
90+
// Now we check we both focus and hover for radio buttons.
9091
move-cursor-to: "#theme-dark"
9192
focus: "#theme-dark"
9293
assert-css: (
@@ -106,6 +107,80 @@ assert-css: (
106107
},
107108
)
108109

110+
// First we check the "default" display for toggles.
111+
assert-css: (
112+
"#auto-hide-large-items",
113+
{
114+
"background-color": "rgb(33, 150, 243)",
115+
"border-color": "rgb(221, 221, 221)",
116+
},
117+
)
118+
assert-css: (
119+
"#use-system-theme",
120+
{
121+
"background-color": "rgba(0, 0, 0, 0)",
122+
"border-color": "rgb(221, 221, 221)",
123+
}
124+
)
125+
// Let's start with the hover for toggles.
126+
move-cursor-to: "#auto-hide-large-items"
127+
assert-css: (
128+
"#auto-hide-large-items",
129+
{
130+
"background-color": "rgb(33, 150, 243)",
131+
"border-color": "rgb(33, 150, 243)",
132+
},
133+
)
134+
move-cursor-to: "#use-system-theme"
135+
assert-css: (
136+
"#use-system-theme",
137+
{
138+
"background-color": "rgba(0, 0, 0, 0)",
139+
"border-color": "rgb(33, 150, 243)",
140+
}
141+
)
142+
move-cursor-to: "#settings-menu > a"
143+
// Let's now check with the focus for toggles.
144+
focus: "#auto-hide-large-items"
145+
assert-css: (
146+
"#auto-hide-large-items",
147+
{
148+
"background-color": "rgb(33, 150, 243)",
149+
"border-color": "rgb(221, 221, 221)",
150+
"box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
151+
},
152+
)
153+
focus: "#use-system-theme"
154+
assert-css: (
155+
"#use-system-theme",
156+
{
157+
"background-color": "rgba(0, 0, 0, 0)",
158+
"border-color": "rgb(221, 221, 221)",
159+
"box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
160+
},
161+
)
162+
// Now we check we both focus and hover for toggles.
163+
move-cursor-to: "#auto-hide-large-items"
164+
focus: "#auto-hide-large-items"
165+
assert-css: (
166+
"#auto-hide-large-items",
167+
{
168+
"background-color": "rgb(33, 150, 243)",
169+
"border-color": "rgb(33, 150, 243)",
170+
"box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
171+
},
172+
)
173+
move-cursor-to: "#use-system-theme"
174+
focus: "#use-system-theme"
175+
assert-css: (
176+
"#use-system-theme",
177+
{
178+
"background-color": "rgba(0, 0, 0, 0)",
179+
"border-color": "rgb(33, 150, 243)",
180+
"box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
181+
},
182+
)
183+
109184
// We now switch the display.
110185
click: "#use-system-theme"
111186
// Wait for the hidden element to show up.
@@ -118,7 +193,7 @@ assert: ".setting-line.hidden #theme"
118193
assert-text: ("#preferred-dark-theme .setting-name", "Preferred dark theme")
119194
assert-text: ("#preferred-light-theme .setting-name", "Preferred light theme")
120195

121-
// We now check that clicking on the "sliders"' text is like clicking on the slider.
196+
// We now check that clicking on the toggles' text is like clicking on the checkbox.
122197
// To test it, we use the "Disable keyboard shortcuts".
123198
local-storage: {"rustdoc-disable-shortcuts": "false"}
124199
click: ".setting-line:last-child .toggle .label"
@@ -141,10 +216,7 @@ assert-css: ("#settings-menu .popover", {"display": "none"})
141216
// Now we go to the settings page to check that the CSS is loaded as expected.
142217
goto: "file://" + |DOC_PATH| + "/settings.html"
143218
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-
)
219+
assert-css: (".setting-line", {"position": "relative"})
148220

149221
assert-attribute-false: ("#settings", {"class": "popover"}, CONTAINS)
150222
compare-elements-position: (".sub form", "#settings", ("x"))
@@ -162,4 +234,4 @@ reload:
162234
size: (300, 1000)
163235
click: "#settings-menu"
164236
wait-for: "#settings"
165-
assert-css: ("#settings .slider", {"width": "45px"}, ALL)
237+
assert-css: (".setting-line", {"position": "relative"})

0 commit comments

Comments
 (0)