Skip to content
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

ENH: Add search button that looks like field #1233

Merged
merged 9 commits into from Jun 30, 2023
Merged
40 changes: 40 additions & 0 deletions src/pydata_sphinx_theme/assets/styles/components/_search.scss
Expand Up @@ -119,3 +119,43 @@
font-size: var(--pst-font-size-icon);
}
}

/**
* The search button component that looks like a field.
* Lives at components/search-button-field.html
*/
.search-button-field {
display: inline-flex;
align-items: center;
border: var(--pst-color-border) solid 1px;
border-radius: 1.5em;
color: var(--pst-color-text-muted);
padding: 0.5em;

&:hover,
&:focus {
background-color: var(--pst-color-surface);
border-color: var(--pst-color-primary);
}

// The keyboard shotcut text
.search-button__kbd-shortcut {
font-size: var(--bs-nav-link-font-size);
font-weight: var(--bs-nav-link-font-weight);
margin-right: 0.5em;
margin-left: 0.5em;
}

.kbd-shortcut__modifier {
font-size: 0.75em;
}

// Only the icon should be visible on narrow screens
:not(i) {
display: none;

@include media-breakpoint-up(lg) {
display: flex;
}
}
}
@@ -0,0 +1,13 @@
{# Behaves the same as `search-button.html` but looks more like a search field.
#
# As this function will only work when JavaScript is enabled, we add it through JavaScript.
#}
<script>
document.write(`
<button class="btn navbar-btn search-button-field search-button__button" title="{{ _('Search') }}" aria-label="{{ _('Search') }}" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass"></i>
<span class="search-button__kbd-shortcut">{{ _('Search') }}</span>
<span><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span>
</button>
`);
</script>
Expand Up @@ -40,7 +40,7 @@ logo =
navbar_start = navbar-logo.html
navbar_center = navbar-nav.html
navbar_end = theme-switcher.html, navbar-icon-links.html
navbar_persistent = search-button.html
navbar_persistent = search-button-field.html
article_header_start = breadcrumbs.html
article_header_end =
primary_sidebar_end = sidebar-ethical-ads.html
Expand Down