1
0
mirror of https://github.com/minio/docs.git synced 2025-07-28 19:42:10 +03:00

Search UX enhancements (#629)

- Fix the visibility of search popup on read-mode (Prakash's comment)
- Add keyboard shortcut indicator on the read-mode search icon
<img width="254" alt="Screenshot 2022-11-04 at 17 39 05"
src="https://user-images.githubusercontent.com/13393018/199986826-e5e4ffe7-218f-4850-a0bf-867c1beb08b7.png">
This commit is contained in:
Rushan
2022-11-07 21:00:28 +04:00
committed by GitHub
parent 46ef64ed2d
commit ceefee34fe
5 changed files with 101 additions and 60 deletions

View File

@ -30,6 +30,15 @@ window.addEventListener("DOMContentLoaded", () => {
</svg>`, </svg>`,
}; };
// Template for empty search results
function noResultTemplate(query) {
return `<div class="search__empty">
${icons.noResult}</br>
No results have been found for <span>${query}</span>.</br>
Please rephrase your query!
</div>`;
}
// Detect macOS // Detect macOS
function isMac() { function isMac() {
return navigator.platform.toUpperCase().indexOf("MAC") >= 0; return navigator.platform.toUpperCase().indexOf("MAC") >= 0;
@ -101,24 +110,25 @@ window.addEventListener("DOMContentLoaded", () => {
// Clear the filters and select the active platform // Clear the filters and select the active platform
setTimeout(() => { setTimeout(() => {
const activeFilterEl = document.querySelector(".search__filters__checkbox[value='" + activePlatform + "']"); const activeFilterEl = document.querySelector(
".search__filters__checkbox[value='" + activePlatform + "']"
);
if (activeFilterEl && !activeFilterEl.checked) { if (activeFilterEl && !activeFilterEl.checked) {
activeFilterEl.click(); activeFilterEl.click();
} }
}, 50); }, 50);
} else { } else {
// Make search modal inactive
searchModalEl.classList.remove("search--focused");
// Clear the filters // Clear the filters
clearRefinements(); clearRefinements();
} }
// Clear the filters on x click // Clear the filters on x click
document.querySelector(".search__reset").addEventListener("click", () => { document
clearRefinements(); .querySelector(".search__reset")
}); .addEventListener("click", () => {
clearRefinements("btn");
});
// Fire the search // Fire the search
search(query); search(query);
@ -157,11 +167,9 @@ window.addEventListener("DOMContentLoaded", () => {
item: "search__hits__item", item: "search__hits__item",
}, },
templates: { templates: {
empty: `<div> empty: function (data) {
${icons.noResult}</br> return data.query !== "" ? noResultTemplate(data.query) : "";
No results have been found for <span>{{ query }}</span>.</br> },
Please rephrase your query!
</div>`,
item: function (data) { item: function (data) {
var returnString; var returnString;
var docUrl; var docUrl;
@ -272,18 +280,30 @@ window.addEventListener("DOMContentLoaded", () => {
]); ]);
// Function to clear search field and filters // Function to clear search field and filters
function clearRefinements() { function clearRefinements(trigger) {
const filtersClearEl = document.querySelector("#search-clear .search-clear__btn"); const filtersClearEl = document.querySelector(
"#search-clear .search-clear__btn"
);
filtersClearEl?.click(); filtersClearEl?.click();
root.classList.remove("locked"); const removeClasses = function () {
searchModalEl.classList.remove("search--active", "search--focused"); root.classList.remove("locked");
searchModalEl.classList.remove("search--active", "search--focused");
};
if (trigger === "btn") {
removeClasses();
} else {
if (!root.classList.contains("read-mode")) {
removeClasses();
}
}
} }
// Function to close and reset the search modal // Function to close and reset the search modal
function closeSearchModal() { function closeSearchModal() {
const searchResetEl = document.querySelector(".search__reset"); const searchResetEl = document.querySelector(".search__reset");
setTimeout(() => { setTimeout(() => {
searchResetEl.click(); searchResetEl.click();
}); });
@ -338,19 +358,13 @@ window.addEventListener("DOMContentLoaded", () => {
// meta + k // meta + k
// -------------------------------------------------- // --------------------------------------------------
const searchEl = document.getElementById("search-box"); const searchEl = document.getElementById("search-box");
const searchToggleBtnEl = document.querySelector(".search-toggle--keyboard");
if (searchEl) { if (searchEl) {
const metaKeyEl = document.createElement("i"); var metaKey = isMac() ? "⌘K" : "Ctrl+K";
metaKeyEl.classList.add("search__meta-key");
if (isMac) { [searchEl, searchToggleBtnEl].forEach((item) => {
metaKeyEl.classList.add("macos"); item.insertAdjacentHTML("beforeend", `<i class="search-meta-key">${metaKey}</i>`);
metaKeyEl.innerHTML = "⌘K"; });
} else {
metaKeyEl.classList.add("non-macos");
metaKeyEl.innerHTML = "Ctrl K";
}
searchEl.appendChild(metaKeyEl);
} }
}); });

View File

@ -461,6 +461,7 @@
.search-toggle { .search-toggle {
margin-left: auto; margin-left: auto;
margin-right: -0.5rem;
position: relative; position: relative;
z-index: 2; z-index: 2;
@ -524,4 +525,31 @@
height: 100%; height: 100%;
pointer-events: none; pointer-events: none;
} }
} }
.search-toggle--keyboard {
height: 2.5rem;
width: 2.5rem;
padding: 0.2rem;
text-align: center;
line-height: 1;
.search-meta-key {
font-size: 0.6rem;
display: block;
border: 1px solid var(--is-meta-key-border-color);
border-radius: $border-radius-sm;
padding: 0.1rem 0.2rem;
margin: 0.15rem auto 0;
font-style: normal;
width: fit-content;
color: var(--text-muted-color);
transition: background-color 200ms;
}
&:hover {
.search-meta-key {
background-color: var(--is-search-bg);
}
}
}

View File

@ -42,15 +42,15 @@
&.search--active { &.search--active {
display: block; display: block;
} }
.search-meta-key {
display: none;
}
} }
.search__input { .search__input {
height: 3.1rem; height: 3.1rem;
} }
.search__meta-key {
display: none;
}
} }
} }
@ -59,6 +59,18 @@
display: flex; display: flex;
isolation: isolate; isolation: isolate;
position: relative; position: relative;
.search-meta-key {
font-style: normal;
position: absolute;
top: 1rem;
right: 0.9rem;
pointer-events: none;
transition: opacity 300ms;
line-height: 1;
font-size: $font-size-xs;
color: var(--text-muted-color);
}
} }
.search--active, .search--active,
@ -78,7 +90,7 @@
border-bottom-right-radius: 0; border-bottom-right-radius: 0;
} }
.search__meta-key { .search-meta-key {
opacity: 0; opacity: 0;
} }
} }
@ -96,9 +108,8 @@
z-index: 10; z-index: 10;
flex-direction: column; flex-direction: column;
border-radius: 0 0 $border-radius-lg $border-radius-lg; border-radius: 0 0 $border-radius-lg $border-radius-lg;
max-height: 23rem;
min-height: 15rem;
display: none; display: none;
max-height: 23rem;
} }
.search__input { .search__input {
@ -315,11 +326,6 @@
} }
.search__hits--empty { .search__hits--empty {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: grid; display: grid;
place-content: center; place-content: center;
text-align: center; text-align: center;
@ -338,14 +344,19 @@
} }
} }
.search__empty {
padding: 2rem 1rem;
}
.search__powered-by { .search__powered-by {
padding: 0.75rem 1rem; padding: 0.75rem 1rem;
display: flex; display: inline-flex;
align-items: center; align-items: center;
color: var(--text-muted-color); color: var(--text-muted-color);
font-size: $font-size-xs; font-size: 0.65rem;
justify-content: flex-end; justify-content: flex-end;
transition: color 300ms; transition: color 300ms;
float: right;
&:hover { &:hover {
color: var(--text-color); color: var(--text-color);
@ -360,7 +371,7 @@
} }
svg { svg {
margin-left: -3.5rem; margin-left: -3.2rem;
path { path {
fill: currentColor; fill: currentColor;
@ -379,19 +390,6 @@
pointer-events: none; pointer-events: none;
} }
.search__meta-key {
font-style: normal;
position: absolute;
top: 1rem;
right: 0.9rem;
pointer-events: none;
opacity: 100;
transition: opacity 300ms;
line-height: 1;
font-size: $font-size-xs;
color: var(--text-muted-color);
}
.search__loading { .search__loading {
position: absolute; position: absolute;
top: 0.75rem; top: 0.75rem;

View File

@ -122,6 +122,7 @@ $theme-properties: (
--is-refine-list-border-color: $light-400 $dark-300, --is-refine-list-border-color: $light-400 $dark-300,
--is-hit-platform-border-color: #c5cad0 $dark-300, --is-hit-platform-border-color: #c5cad0 $dark-300,
--is-loader-circle-stroke: #c2c8d1 $dark-300, --is-loader-circle-stroke: #c2c8d1 $dark-300,
--is-meta-key-border-color: #c5cad0 $dark-400,
); );
// Activate dark/light themes // Activate dark/light themes

View File

@ -31,7 +31,7 @@
Windows Windows
</a> </a>
<button type="button" class="icon search-toggle visible-rm"> <button type="button" class="icon search-toggle search-toggle--keyboard visible-rm">
{%- include "icons/search.html" %} {%- include "icons/search.html" %}
Search Search
</button> </button>