Skip to content

Fix top navbar style #1719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 2 additions & 76 deletions templates/header/topbar_begin.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
The only piece of context it can take is `search_query`, which should
be a string and will populate the search field if it exists
#}

{%- import "macros.html" as macros -%}

<div class="nav-container">
<div class="container">
<div class="pure-menu pure-menu-horizontal" role="navigation" aria-label="Main navigation">
Expand All @@ -14,82 +11,11 @@
class="landing-search-form-nav {%
if is_latest_version is defined and not is_latest_version %}not-latest{% endif
%} {% if metadata.yanked %}yanked{% endif %}">
{# The search bar #}
<div id="search-input-nav" class="pure-menu-right">
<label for="nav-search">
{{ "search" | fas }}
</label>

{# If there is a search query, put it in the search bar #}
{# The tabindex="-1" is used to prevent it to be the first input focused on the page when using the browser shortcut #}
<input id="nav-search" name="query" type="text" aria-label="Find crate by search query" tabindex="-1"
placeholder="Find crate" {%- if search_query %} value="{{ search_query }}" {%- endif %}>
</div>

{# The top-left logo and name #}
<a href="/" class="pure-menu-heading pure-menu-link" aria-label="Docs.rs">
<a href="/" class="pure-menu-heading pure-menu-link docsrs-logo" aria-label="Docs.rs">
<span title="Docs.rs">{{ "cubes" | fas }}</span>
<span class="title">Docs.rs</span>
</a>{#

#}<ul class="pure-menu-list pure-menu-right">
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover pure-menu-opt-children">
<a href="/releases" class="pure-menu-link">
<span title="Releases">{{ "leaf" | fas }}</span>
<span class="title">Releases</span>
</a>

<ul class="pure-menu-children">
{{ macros::menu_link(href="/releases/stars", text="Releases by Stars") }}
{{ macros::menu_link(href="/releases/recent-failures", text="Recent Build Failures") }}
{{ macros::menu_link(href="/releases/failures", text="Build Failures by Stars") }}
{{ macros::menu_link(href="/releases/activity", text="Release Activity") }}
</ul>
</li>{#

The Rust dropdown menu
#}<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover pure-menu-opt">
<a href="https://www.rust-lang.org/" target="_blank" class="pure-menu-link">
Rust
</a>

<ul class="pure-menu-children">
{{ macros::menu_link(
href="https://doc.rust-lang.org/book/",
text="The Book",
target="_blank"
) }}

{{ macros::menu_link(
href="https://doc.rust-lang.org/std/",
text="Standard Library API Reference",
target="_blank"
) }}

{{ macros::menu_link(
href="https://doc.rust-lang.org/rust-by-example/",
text="Rust by Example",
target="_blank"
) }}

{{ macros::menu_link(
href="https://rust-lang-nursery.github.io/rust-cookbook/",
text="Rust Cookbook",
target="_blank",
extra_classes="menu-item-divided"
) }}

{{ macros::menu_link(
href="https://crates.io",
text="Crates.io",
target="_blank"
) }}

{{ macros::menu_link(
href="http://doc.crates.io/guide.html",
text="The Cargo Guide",
target="_blank"
) }}
</ul>
</li>
</ul>
#}
75 changes: 75 additions & 0 deletions templates/header/topbar_end.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,81 @@
{%- import "macros.html" as macros -%}

<div class="spacer"></div>
{# The global alert, if there is one #}
{% include "header/global_alert.html" -%}

<ul class="pure-menu-list">
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover pure-menu-opt-children">
<a href="/releases" class="pure-menu-link">
<span title="Releases">{{ "leaf" | fas }}</span>
<span class="title">Releases</span>
</a>

<ul class="pure-menu-children">
{{ macros::menu_link(href="/releases/stars", text="Releases by Stars") }}
{{ macros::menu_link(href="/releases/recent-failures", text="Recent Build Failures") }}
{{ macros::menu_link(href="/releases/failures", text="Build Failures by Stars") }}
{{ macros::menu_link(href="/releases/activity", text="Release Activity") }}
</ul>
</li>{#

The Rust dropdown menu
#}<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover pure-menu-opt">
<a href="https://www.rust-lang.org/" target="_blank" class="pure-menu-link">
Rust
</a>

<ul class="pure-menu-children">
{{ macros::menu_link(
href="https://doc.rust-lang.org/book/",
text="The Book",
target="_blank"
) }}

{{ macros::menu_link(
href="https://doc.rust-lang.org/std/",
text="Standard Library API Reference",
target="_blank"
) }}

{{ macros::menu_link(
href="https://doc.rust-lang.org/rust-by-example/",
text="Rust by Example",
target="_blank"
) }}

{{ macros::menu_link(
href="https://rust-lang-nursery.github.io/rust-cookbook/",
text="Rust Cookbook",
target="_blank",
extra_classes="menu-item-divided"
) }}

{{ macros::menu_link(
href="https://crates.io",
text="Crates.io",
target="_blank"
) }}

{{ macros::menu_link(
href="http://doc.crates.io/guide.html",
text="The Cargo Guide",
target="_blank"
) }}
</ul>
</li>
</ul>
{# The search bar #}
<div id="search-input-nav">
<label for="nav-search">
{{ "search" | fas }}
</label>

{# If there is a search query, put it in the search bar #}
{# The tabindex="-1" is used to prevent it to be the first input focused on the page when using the browser shortcut #}
<input id="nav-search" name="query" type="text" aria-label="Find crate by search query" tabindex="-1"
placeholder="Find crate" {%- if search_query %} value="{{ search_query }}" {%- endif %}>
</div>
</form>
</div>
</div>
Expand Down
45 changes: 25 additions & 20 deletions templates/style/_navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ div.nav-container {
/* The font size must be specified in pixels because the height is specified in pixels. */
font: 16px $font-family-sans;

.container, .pure-menu-horizontal {
position: relative;
height: 100%;
}

li {
border-left: 1px solid var(--color-border);
}
Expand All @@ -40,18 +45,18 @@ div.nav-container {
background-color: var(--color-background);
}
&:after {
font-size: 0.8em;
font-size: 12.8px;
content: "\25BC"
}
}

.pure-menu-link {
font-size: 0.8em;
font-size: 12.8px;
font-weight: 400;
color: var(--color-navbar-standard);

&.description {
font-size: 0.9em;
font-size: 14.4px;
}

// Improves menu link readability when inverting the colors on focus.
Expand All @@ -73,18 +78,17 @@ div.nav-container {
}
}

.pure-menu-right {
float: right;
}

form.landing-search-form-nav {
max-width: 1200px;
height: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can get rid of this height: 100%. That makes the search field vertically misaligned, but you can fix that by also removing the height: 100% on line 92.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the height: 100%:

Screenshot from 2022-04-13 16-56-07

display: flex;
flex-direction: row;

#search-input-nav {
float: right;
max-width: 150px;
display: none;
border-left: 1px solid var(--color-border);
height: 100%;

@media #{$media-sm} {
display: block;
Expand All @@ -98,32 +102,33 @@ div.nav-container {
color: var(--color-navbar-standard);
cursor: pointer;
padding-left: 0.5rem;
font-size: 0.8em;
font-size: 12.8px;
}

input {
border: none;
margin: 0 1em 0 0;
font-size: 0.8em;
font-size: 12.8px;
box-shadow: none;
background-color: var(--color-background);
height: 31px;
height: 100%;
}
}

input.search-input-nav:focus {
outline: unset;
}

.docsrs-logo, .pure-menu-item a {
padding: 6.4px 16px 6.4px 16px;
}

.docsrs-logo, .pure-menu-item, .pure-menu-item a {
height: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is also unnecessary.

}

/* In some unusual situations, like a locally installed copy of "Fira Sans," elements
of the navbar might overflow vertically and start interfering with the main body
content. To ensure that doesn't happen, hide any vertical overflow.
See https://github.com/rust-lang/docs.rs/issues/1669.
*/
.pure-menu-item a {
/* 0.5 em is the padding */
max-height: calc(#{$top-navbar-height} - 0.5em * 2);
.spacer {
flex-grow: 1;
}
}

Expand Down Expand Up @@ -271,7 +276,7 @@ div.nav-container {

p.description {
font-family: $font-family-sans;
font-size: 0.8em;
font-size: 12.8px;
color: var(--color-navbar-standard);
padding: 0.5em 1em;
margin: 0;
Expand Down