Skip to content

Commit

Permalink
feat: enhance scrollbar style (#56)
Browse files Browse the repository at this point in the history
* feat: enhance scrollbar style

* chore: set `color-scheme` for document element
  • Loading branch information
imfing authored Sep 13, 2023
1 parent 84ac7fe commit e9ea978
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 4 deletions.
27 changes: 27 additions & 0 deletions assets/css/compiled/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2515,6 +2515,33 @@ nav .search-wrapper {
.hamburger-menu svg.open > g:nth-of-type(2) path {
transform: translate3d(0, -4px, 0);
}
.hextra-scrollbar {
scrollbar-width: thin; /* Firefox */
scrollbar-color: oklch(55.55% 0 0 / 40%) transparent; /* Firefox */

scrollbar-gutter: stable;
}
.hextra-scrollbar::-webkit-scrollbar {
height: 0.75rem;
width: 0.75rem;
}
.hextra-scrollbar::-webkit-scrollbar-track {
background-color: transparent;
}
.hextra-scrollbar::-webkit-scrollbar-thumb {
border-radius: 10px;
}
.hextra-scrollbar:hover::-webkit-scrollbar-thumb {
border: 3px solid transparent;
background-color: var(--tw-shadow-color);
background-clip: content-box;
--tw-shadow-color: rgb(115 115 115 / 0.2);
--tw-shadow: var(--tw-shadow-colored);
}
.hextra-scrollbar:hover::-webkit-scrollbar-thumb:hover {
--tw-shadow-color: rgb(115 115 115 / 0.4);
--tw-shadow: var(--tw-shadow-colored);
}
html {
font-size: 1rem;
-webkit-font-smoothing: antialiased;
Expand Down
21 changes: 21 additions & 0 deletions assets/css/components/scrollbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.hextra-scrollbar {
scrollbar-width: thin; /* Firefox */
scrollbar-color: oklch(55.55% 0 0 / 40%) transparent; /* Firefox */

scrollbar-gutter: stable;
&::-webkit-scrollbar {
@apply w-3 h-3;
}
&::-webkit-scrollbar-track {
@apply bg-transparent;
}
&::-webkit-scrollbar-thumb {
@apply rounded-[10px];
}
&:hover::-webkit-scrollbar-thumb {
border: 3px solid transparent;
background-color: var(--tw-shadow-color);
background-clip: content-box;
@apply shadow-neutral-500/20 hover:shadow-neutral-500/40;
}
}
1 change: 1 addition & 0 deletions assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import "components/search.css";
@import "components/sidebar.css";
@import "components/navbar.css";
@import "components/scrollbar.css";

html {
@apply text-base antialiased;
Expand Down
4 changes: 4 additions & 0 deletions assets/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ themeToggleButtons.forEach((el) => {
if (localStorage.getItem("color-theme")) {
if (localStorage.getItem("color-theme") === "light") {
document.documentElement.classList.add("dark");
document.documentElement.style.colorScheme = "dark";
localStorage.setItem("color-theme", "dark");
} else {
document.documentElement.classList.remove("dark");
document.documentElement.style.colorScheme = "light";
localStorage.setItem("color-theme", "light");
}
} else {
if (document.documentElement.classList.contains("dark")) {
document.documentElement.classList.remove("dark");
document.documentElement.style.colorScheme = "light";
localStorage.setItem("color-theme", "light");
} else {
document.documentElement.classList.add("dark");
document.documentElement.style.colorScheme = "dark";
localStorage.setItem("color-theme", "dark");
}
}
Expand Down
3 changes: 2 additions & 1 deletion exampleSite/hugo_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@
"hextra-filetree",
"hextra-filetree-folder",
"hextra-footer",
"hextra-scrollbar",
"hextra-sidebar-collapsible-button",
"hextra-toc",
"hidden",
Expand Down Expand Up @@ -580,4 +581,4 @@
],
"ids": null
}
}
}
2 changes: 2 additions & 0 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
/* Initialize light/dark mode */
if (localStorage.getItem("color-theme") === "dark" || (!("color-theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches)) {
document.documentElement.classList.add("dark");
document.documentElement.style.colorScheme = "dark";
} else {
document.documentElement.classList.remove("dark");
document.documentElement.style.colorScheme = "light";
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<div>
<ul
class="search-results hidden border border-gray-200 bg-white text-gray-100 dark:border-neutral-800 dark:bg-neutral-900 absolute top-full z-20 mt-2 overflow-auto overscroll-contain rounded-xl py-2.5 shadow-xl max-h-[min(calc(50vh-11rem-env(safe-area-inset-bottom)),400px)] md:max-h-[min(calc(100vh-5rem-env(safe-area-inset-bottom)),400px)] inset-x-0 ltr:md:left-auto rtl:md:right-auto contrast-more:border contrast-more:border-gray-900 contrast-more:dark:border-gray-50 w-screen min-h-[100px] max-w-[min(calc(100vw-2rem),calc(100%+20rem))]"
class="search-results hextra-scrollbar hidden border border-gray-200 bg-white text-gray-100 dark:border-neutral-800 dark:bg-neutral-900 absolute top-full z-20 mt-2 overflow-auto overscroll-contain rounded-xl py-2.5 shadow-xl max-h-[min(calc(50vh-11rem-env(safe-area-inset-bottom)),400px)] md:max-h-[min(calc(100vh-5rem-env(safe-area-inset-bottom)),400px)] inset-x-0 ltr:md:left-auto rtl:md:right-auto contrast-more:border contrast-more:border-gray-900 contrast-more:dark:border-gray-50 w-screen min-h-[100px] max-w-[min(calc(100vw-2rem),calc(100%+20rem))]"
style="transition: max-height 0.2s ease 0s;"
></ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="px-4 pt-4 md:hidden">
{{ partial "search.html" }}
</div>
<div class="overflow-y-auto overflow-x-hidden p-4 grow md:h-[calc(100vh-var(--navbar-height)-var(--menu-height))]">
<div class="hextra-scrollbar overflow-y-auto overflow-x-hidden p-4 grow md:h-[calc(100vh-var(--navbar-height)-var(--menu-height))]">
<ul class="flex flex-col gap-1 md:hidden">
<!-- Nav -->
{{ template "sidebar-main" (dict "context" site.Home "pageURL" $pageURL "page" $context "toc" true) -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<nav class="hextra-toc order-last hidden w-64 shrink-0 xl:block print:hidden px-4" aria-label="table of contents">
{{- if $toc }}
<div class="sticky top-16 overflow-y-auto pr-4 pt-6 text-sm [hyphens:auto] max-h-[calc(100vh-var(--navbar-height)-env(safe-area-inset-bottom))] ltr:-mr-4 rtl:-ml-4">
<div class="hextra-scrollbar sticky top-16 overflow-y-auto pr-4 pt-6 text-sm [hyphens:auto] max-h-[calc(100vh-var(--navbar-height)-env(safe-area-inset-bottom))] ltr:-mr-4 rtl:-ml-4">
{{- with .Fragments.Headings -}}
<p class="mb-4 font-semibold tracking-tight">{{ $onThisPage }}</p>
{{- range . -}}
Expand Down

0 comments on commit e9ea978

Please sign in to comment.