Skip to content

Commit

Permalink
New Search Modal UI (JuliaDocs#2202)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hetarth02 committed Aug 24, 2023
1 parent 06c5caf commit defe107
Show file tree
Hide file tree
Showing 10 changed files with 594 additions and 389 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Documenter now generates a `.documenter-siteinfo.json` file in the HTML build, that contains some metadata about the build. ([#2181])

* The client-side search engine has been changed from LunrJs to MinisearchJs. Additionally, the search results will now contain additional context and have an improved UI. ([#2141])
* The search UI has had a complete overhaul, with a fresh new modal UI with better context for search results and a filter mechanism to remove unwanted results. The client-side search engine has been changed from LunrJs to MinisearchJs. ([#1437], [#2141], [#2147], [#2202])

### Fixed

Expand Down Expand Up @@ -1411,6 +1411,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#1428]: https://github.com/JuliaDocs/Documenter.jl/issues/1428
[#1430]: https://github.com/JuliaDocs/Documenter.jl/issues/1430
[#1435]: https://github.com/JuliaDocs/Documenter.jl/issues/1435
[#1437]: https://github.com/JuliaDocs/Documenter.jl/issues/1437
[#1438]: https://github.com/JuliaDocs/Documenter.jl/issues/1438
[#1440]: https://github.com/JuliaDocs/Documenter.jl/issues/1440
[#1441]: https://github.com/JuliaDocs/Documenter.jl/issues/1441
Expand Down Expand Up @@ -1626,6 +1627,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2141]: https://github.com/JuliaDocs/Documenter.jl/issues/2141
[#2142]: https://github.com/JuliaDocs/Documenter.jl/issues/2142
[#2145]: https://github.com/JuliaDocs/Documenter.jl/issues/2145
[#2147]: https://github.com/JuliaDocs/Documenter.jl/issues/2147
[#2153]: https://github.com/JuliaDocs/Documenter.jl/issues/2153
[#2157]: https://github.com/JuliaDocs/Documenter.jl/issues/2157
[#2169]: https://github.com/JuliaDocs/Documenter.jl/issues/2169
Expand All @@ -1634,6 +1636,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2187]: https://github.com/JuliaDocs/Documenter.jl/issues/2187
[#2191]: https://github.com/JuliaDocs/Documenter.jl/issues/2191
[#2194]: https://github.com/JuliaDocs/Documenter.jl/issues/2194
[#2202]: https://github.com/JuliaDocs/Documenter.jl/issues/2202
[#2205]: https://github.com/JuliaDocs/Documenter.jl/issues/2205
[#2213]: https://github.com/JuliaDocs/Documenter.jl/issues/2213
[#2214]: https://github.com/JuliaDocs/Documenter.jl/issues/2214
Expand Down
106 changes: 94 additions & 12 deletions assets/html/js/shortcut.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,100 @@
let searchbox = document.querySelector("#documenter-search-query");
let sidebar = document.querySelector(".docs-sidebar");
// libraries: jquery
// arguments: $

let search_modal_header = `
<header class="modal-card-head gap-2 is-align-items-center is-justify-content-space-between w-100 px-3">
<div class="field mb-0 w-100">
<p class="control has-icons-right">
<input class="input documenter-search-input" type="text" placeholder="Search" />
<span class="icon is-small is-right has-text-primary-dark">
<i class="fas fa-magnifying-glass"></i>
</span>
</p>
</div>
<div class="icon is-size-4 is-clickable close-search-modal">
<i class="fas fa-times"></i>
</div>
</header>
`;

let initial_search_body = `
<div class="has-text-centered my-5 py-5">Type something to get started!</div>
`;

let search_modal_footer = `
<footer class="modal-card-foot">
<span>
<kbd class="search-modal-key-hints">Ctrl</kbd> +
<kbd class="search-modal-key-hints">/</kbd> to search
</span>
<span class="ml-3"> <kbd class="search-modal-key-hints">esc</kbd> to close </span>
</footer>
`;

$(document.body).append(
`
<div class="modal" id="search-modal">
<div class="modal-background"></div>
<div class="modal-card search-min-width-50 search-min-height-100 is-justify-content-center">
${search_modal_header}
<section class="modal-card-body is-flex is-flex-direction-column is-justify-content-center gap-4 search-modal-card-body">
${initial_search_body}
</section>
${search_modal_footer}
</div>
</div>
`
);

document.querySelector(".docs-search-query").addEventListener("click", () => {
openModal();
});

document.querySelector(".close-search-modal").addEventListener("click", () => {
closeModal();
});

$(document).on("click", ".search-result-link", function () {
closeModal();
});

document.addEventListener("keydown", (event) => {
if ((event.ctrlKey || event.metaKey) && event.key === "/") {
if (!sidebar.classList.contains("visible")) {
sidebar.classList.add("visible");
}
searchbox.focus();
return false;
openModal();
} else if (event.key === "Escape") {
if (sidebar.classList.contains("visible")) {
sidebar.classList.remove("visible");
}
searchbox.blur();
return false;
closeModal();
}

return false;
});

// Functions to open and close a modal
function openModal() {
let searchModal = document.querySelector("#search-modal");

searchModal.classList.add("is-active");
document.querySelector(".documenter-search-input").focus();
}

function closeModal() {
let searchModal = document.querySelector("#search-modal");
let initial_search_body = `
<div class="has-text-centered my-5 py-5">Type something to get started!</div>
`;

searchModal.classList.remove("is-active");
document.querySelector(".documenter-search-input").blur();

if (!$(".search-modal-card-body").hasClass("is-justify-content-center")) {
$(".search-modal-card-body").addClass("is-justify-content-center");
}

$(".documenter-search-input").val("");
$(".search-modal-card-body").html(initial_search_body);
}

document
.querySelector("#search-modal .modal-background")
.addEventListener("click", () => {
closeModal();
});
3 changes: 3 additions & 0 deletions assets/html/scss/documenter-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ $input-placeholder-color: rgba($input-color, 0.3);
$search-result-link-text-color: #333;
$search-result-link-text-background-color: #f1f5f9;
$search-result-title-text-color: whitesmoke;
$search-modal-kbd-color: rgba(245, 245, 245, 0.6);

$button-static-color: $grey-lighter;
$button-static-background-color: $background;
$button-static-border-color: $border;

$documenter-search-query-text-color: rgba(219, 222, 224, 0.3);

// All secondary themes have to be nested in a theme--$(themename) class. When Documenter
// switches themes, it applies this class to <html> and then disables the primary
// stylesheet.
Expand Down
10 changes: 9 additions & 1 deletion assets/html/scss/documenter/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,13 @@ $search-result-link-text-background-color: #333 !default;
$search-result-title-text-color: #333 !default;
$search-result-badge-color: whitesmoke !default;
$search-result-badge-background-color: #33415580 !default;

$search-modal-scrollbar-background-color: gray !default;
$search-modal-kbd-color: rgba(0, 0, 0, 0.6) !default;
$search-filter-color: #333 !default;
$search-filter-background-color: whitesmoke !default;
$search-modal-selected-filter-color: whitesmoke !default;
$search-modal-selected-filter-background-color: rgba(139, 0, 139, 0.5) !default;
$search-result-highlight: hsl(48, 100%, 67%) !default;

// Sidebar input box
$documenter-search-query-text-color: rgba(0, 0, 0, 0.3) !default;
198 changes: 131 additions & 67 deletions assets/html/scss/documenter/layout/_search.scss
Original file line number Diff line number Diff line change
@@ -1,69 +1,133 @@
// Additional styling for the search page
#documenter .docs-main {
#documenter-search-info {
margin-bottom: 1rem;
}

#documenter-search-results {
list-style-type: circle;
list-style-position: outside;

li {
margin-left: 2rem;
}

.search-result-link {
border-radius: 0.7em;
transition: all 300ms;
}

.search-result-link:hover, .search-result-link:focus {
background-color: $search-result-link-hover;
}

.search-result-link .property-search-result-badge {
transition: all 300ms;
}

.property-search-result-badge {
padding: 0.15em 0.5em;
font-size: 0.8em;
font-style: italic;
text-transform: none !important;
line-height: 1.5;
color: $search-result-badge-color;
background-color: $search-result-badge-background-color;
border-radius: 0.6rem;
}

.search-result-link:hover .property-search-result-badge, .search-result-link:focus .property-search-result-badge {
color: $search-result-link-text-color;
background-color: $search-result-link-text-background-color;
}

.search-result-highlight {
background-color: $search-result-highlight;
color: black;
}

.search-divider {
border-bottom: 1px solid $border;
}

.search-result-title {
color: $search-result-title-text-color;
}

.w-100 {
width: 100%;
}

.gap-2 {
gap: 0.5rem;
}

.gap-4 {
gap: 1rem;
}
}
/* Code from https://dylanatsmith.com/wrote/styling-the-kbd-element */
kbd.search-modal-key-hints {
border-radius: 0.25rem;
border: 1px solid $search-modal-kbd-color;
box-shadow: 0 2px 0 1px $search-modal-kbd-color;
cursor: default;
font-size: 0.9rem;
line-height: 1.5;
min-width: 0.75rem;
text-align: center;
padding: 0.1rem 0.3rem;
position: relative;
top: -1px;
}

.search-min-width-50 {
min-width: 50%;
}

.search-min-height-100 {
min-height: 100%;
}

.search-modal-card-body {
max-height: calc(100vh - 15rem);
}

.search-result-link {
border-radius: 0.7em;
transition: all 300ms;
}

.search-result-link:hover, .search-result-link:focus {
background-color: $search-result-link-hover;
}

.search-result-link .property-search-result-badge {
transition: all 300ms;
}

.property-search-result-badge {
padding: 0.15em 0.5em;
font-size: 0.8em;
font-style: italic;
text-transform: none !important;
line-height: 1.5;
color: $search-result-badge-color;
background-color: $search-result-badge-background-color;
border-radius: 0.6rem;
}

.search-result-link:hover .property-search-result-badge, .search-result-link:focus .property-search-result-badge {
color: $search-result-link-text-color;
background-color: $search-result-link-text-background-color;
}

.search-filter {
@extend .property-search-result-badge;

color: $search-filter-color;
background-color: $search-filter-background-color;
transition: all 300ms;
}

.search-filter:hover, .search-filter:focus {
color: $search-filter-color;
}

.search-filter-selected {
color: $search-modal-selected-filter-color;
background-color: $search-modal-selected-filter-background-color;
}

.search-filter-selected:hover, .search-filter-selected:focus {
color: $search-modal-selected-filter-color;
}

.search-result-highlight {
background-color: $search-result-highlight;
color: black;
}

.search-divider {
border-bottom: 1px solid $border;
}

.search-result-title {
width: 85%;
color: $search-result-title-text-color;
}

.search-result-code-title {
font-size: 0.875rem;
font-family: $family-monospace;
}

// Search modal custom scrollbar
#search-modal .modal-card-body::-webkit-scrollbar,
#search-modal .filter-tabs::-webkit-scrollbar {
height: 10px;
width: 10px;
background-color: transparent;
}

#search-modal .modal-card-body::-webkit-scrollbar-thumb,
#search-modal .filter-tabs::-webkit-scrollbar-thumb {
background-color: $search-modal-scrollbar-background-color;
border-radius: 1rem;
}

#search-modal .modal-card-body::-webkit-scrollbar-track,
#search-modal .filter-tabs::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.6);
background-color: transparent;
}

// Helpers for search modal
.w-100 {
width: 100%;
}

.gap-2 {
gap: 0.5rem;
}

.gap-4 {
gap: 1rem;
}

.gap-8 {
gap: 2rem;
}
6 changes: 6 additions & 0 deletions assets/html/scss/documenter/layout/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@
margin-bottom: 0.5rem;
}

#documenter-search-query {
color: $documenter-search-query-text-color;
width: 0.8 * $documenter-sidebar-width;
box-shadow: inset 0 1px 2px rgba(10,10,10,0.1);
}

/* Setting up a nicer theme style for the scrollbar */
@mixin sidebar-scroll {
overflow-y: auto;
Expand Down
Loading

0 comments on commit defe107

Please sign in to comment.