Skip to content

Commit

Permalink
Rollup merge of #104115 - GuillaumeGomez:migrate-crate-search-div, r=…
Browse files Browse the repository at this point in the history
…notriddle

Migrate crate-search element to CSS variables

There should no UI changes.

r? ```@notriddle```
  • Loading branch information
compiler-errors committed Nov 10, 2022
2 parents 7124590 + 0e804b4 commit 5499687
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 34 deletions.
10 changes: 9 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,9 @@ table,
line-height: 1.5;
font-weight: 500;
}
#crate-search:hover, #crate-search:focus {
border-color: var(--crate-search-hover-border);
}
/* cancel stylistic differences in padding in firefox
for "appearance: none"-style (or equivalent) <select>s */
@-moz-document url-prefix() {
Expand All @@ -853,8 +856,13 @@ so that we can apply CSS-filters to change the arrow color in themes */
background-repeat: no-repeat;
background-size: 20px;
background-position: calc(100% - 2px) 56%;
/* image is black color, themes should apply a "filter" property to change the color */
/* image is black color */
background-image: url("down-arrow-927217e04c7463ac.svg");
/* changes the arrow image color */
filter: var(--crate-search-div-filter);
}
#crate-search-div:hover::after, #crate-search-div:focus-within::after {
filter: var(--crate-search-div-hover-filter);
}
#crate-search > option {
font-size: 1rem;
Expand Down
17 changes: 6 additions & 11 deletions src/librustdoc/html/static/css/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ Original by Dempfi (https://github.com/dempfi/ayu)
drop-shadow(0 1px 0 #fff)
drop-shadow(-1px 0 0 #fff)
drop-shadow(0 -1px 0 #fff);
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
--crate-search-div-filter: invert(41%) sepia(12%) saturate(487%) hue-rotate(171deg)
brightness(94%) contrast(94%);
--crate-search-div-hover-filter: invert(98%) sepia(12%) saturate(81%) hue-rotate(343deg)
brightness(113%) contrast(76%);
--crate-search-hover-border: #e0e0e0;
}

.slider {
Expand Down Expand Up @@ -153,17 +159,6 @@ details.rustdoc-toggle > summary::before {
filter: invert(100%);
}

#crate-search-div::after {
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
filter: invert(41%) sepia(12%) saturate(487%) hue-rotate(171deg) brightness(94%) contrast(94%);
}
#crate-search:hover, #crate-search:focus {
border-color: #e0e0e0 !important;
}
#crate-search-div:hover::after, #crate-search-div:focus-within::after {
filter: invert(98%) sepia(12%) saturate(81%) hue-rotate(343deg) brightness(113%) contrast(76%);
}

.module-item .stab,
.import-item .stab {
color: #000;
Expand Down
17 changes: 6 additions & 11 deletions src/librustdoc/html/static/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
drop-shadow(0 1px 0 #fff)
drop-shadow(-1px 0 0 #fff)
drop-shadow(0 -1px 0 #fff);
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
--crate-search-div-filter: invert(94%) sepia(0%) saturate(721%) hue-rotate(255deg)
brightness(90%) contrast(90%);
--crate-search-div-hover-filter: invert(69%) sepia(60%) saturate(6613%) hue-rotate(184deg)
brightness(100%) contrast(91%);
--crate-search-hover-border: #2196f3;
}

.slider {
Expand All @@ -84,17 +90,6 @@ details.rustdoc-toggle > summary::before {
filter: invert(100%);
}

#crate-search-div::after {
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
filter: invert(94%) sepia(0%) saturate(721%) hue-rotate(255deg) brightness(90%) contrast(90%);
}
#crate-search:hover, #crate-search:focus {
border-color: #2196f3 !important;
}
#crate-search-div:hover::after, #crate-search-div:focus-within::after {
filter: invert(69%) sepia(60%) saturate(6613%) hue-rotate(184deg) brightness(100%) contrast(91%);
}

:target {
background-color: #494a3d;
border-right: 3px solid #bb7410;
Expand Down
17 changes: 6 additions & 11 deletions src/librustdoc/html/static/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
--test-arrow-hover-color: #f5f5f5;
--test-arrow-hover-background-color: #4e8bca;
--rust-logo-filter: initial;
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
--crate-search-div-filter: invert(100%) sepia(0%) saturate(4223%) hue-rotate(289deg)
brightness(114%) contrast(76%);
--crate-search-div-hover-filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg)
brightness(96%) contrast(93%);
--crate-search-hover-border: #717171;
}

.slider {
Expand All @@ -77,17 +83,6 @@ body.source .example-wrap pre.rust a {
background: #eee;
}

#crate-search-div::after {
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
filter: invert(100%) sepia(0%) saturate(4223%) hue-rotate(289deg) brightness(114%) contrast(76%);
}
#crate-search:hover, #crate-search:focus {
border-color: #717171 !important;
}
#crate-search-div:hover::after, #crate-search-div:focus-within::after {
filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg) brightness(96%) contrast(93%);
}

:target {
background: #FDFFD3;
border-right: 3px solid #AD7C37;
Expand Down
40 changes: 40 additions & 0 deletions src/test/rustdoc-gui/search-result-display.goml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,43 @@ assert-css: ("#crate-search", {"width": "527px"})
assert-css: (".search-results-title", {"height": "44px", "width": "640px"})
// And we check that the `<select>` isn't bigger than its container (".search-results-title").
assert-css: ("#search", {"width": "640px"})

// Now checking that the crate filter is working as expected too.
show-text: true
define-function: (
"check-filter",
(theme, border, filter, hover_border, hover_filter),
[
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
("reload"),
("wait-for", "#crate-search"),
("assert-css", ("#crate-search", {"border": "1px solid " + |border|})),
("assert-css", ("#crate-search-div::after", {"filter": |filter|})),
("move-cursor-to", "#crate-search"),
("assert-css", ("#crate-search", {"border": "1px solid " + |hover_border|})),
("assert-css", ("#crate-search-div::after", {"filter": |hover_filter|})),
("move-cursor-to", ".search-input"),
],
)

call-function: ("check-filter", {
"theme": "ayu",
"border": "rgb(92, 103, 115)",
"filter": "invert(0.41) sepia(0.12) saturate(4.87) hue-rotate(171deg) brightness(0.94) contrast(0.94)",
"hover_border": "rgb(224, 224, 224)",
"hover_filter": "invert(0.98) sepia(0.12) saturate(0.81) hue-rotate(343deg) brightness(1.13) contrast(0.76)",
})
call-function: ("check-filter", {
"theme": "dark",
"border": "rgb(224, 224, 224)",
"filter": "invert(0.94) sepia(0) saturate(7.21) hue-rotate(255deg) brightness(0.9) contrast(0.9)",
"hover_border": "rgb(33, 150, 243)",
"hover_filter": "invert(0.69) sepia(0.6) saturate(66.13) hue-rotate(184deg) brightness(1) contrast(0.91)",
})
call-function: ("check-filter", {
"theme": "light",
"border": "rgb(224, 224, 224)",
"filter": "invert(1) sepia(0) saturate(42.23) hue-rotate(289deg) brightness(1.14) contrast(0.76)",
"hover_border": "rgb(113, 113, 113)",
"hover_filter": "invert(0.44) sepia(0.18) saturate(0.23) hue-rotate(317deg) brightness(0.96) contrast(0.93)",
})

0 comments on commit 5499687

Please sign in to comment.