Add overlay scrollbars with custom styling

This commit is contained in:
Sebastian Martinez
2025-06-11 19:54:59 +02:00
parent 499a0983ea
commit e246a48b90
8 changed files with 119 additions and 88 deletions
+5 -1
View File
@@ -11,6 +11,7 @@
| "danger"
| "success"
| "outline";
innerElement?: HTMLElement;
hoverable?: boolean;
onclick?: (e: MouseEvent) => void;
stylePosition?: string;
@@ -33,10 +34,12 @@
styleJustifyContent?: string;
}
const {
/* eslint-disable prefer-const */
let {
children,
variant,
hoverable = false,
innerElement = $bindable(),
onclick,
stylePadding,
styleHeight,
@@ -257,6 +260,7 @@
<div class="p3-2"></div>
<div
class="p3-3"
bind:this={innerElement}
style:max-height={styleMaxHeight}
style:min-width={styleMinWidth}
style:display={styleDisplay}
+16
View File
@@ -4,6 +4,7 @@
import { getCurrentWindow } from "@tauri-apps/api/window";
import { onMount } from "svelte";
import { useOverlayScrollbars } from "overlayscrollbars-svelte";
import { dynamicInterval } from "@app/lib/interval";
import { invoke } from "@app/lib/invoke";
@@ -20,6 +21,7 @@
let { notificationCount }: Props = $props();
let borderComponent: HTMLElement | undefined = $state();
let notificationPopoverExpaneded: boolean = $state(false);
let buttonActive: boolean = $state(false);
@@ -29,6 +31,19 @@
}
});
$effect(() => {
if (borderComponent) {
const [initialize] = useOverlayScrollbars({
options: () => ({
scrollbars: { theme: "os-theme-radicle", autoHide: "scroll" },
}),
defer: true,
});
initialize({ target: borderComponent });
}
});
onMount(async () => {
await loadCounter();
});
@@ -128,6 +143,7 @@
{#snippet popover()}
<Border
bind:innerElement={borderComponent}
variant="ghost"
styleWidth="40rem"
stylePadding="1rem"
+1 -1
View File
@@ -111,7 +111,7 @@
{/if}
</div>
<div>
<div style:z-index="20">
<NakedButton
styleHeight="2.5rem"
variant="ghost"
+57 -54
View File
@@ -27,7 +27,7 @@
import type { Snippet } from "svelte";
import type { Config } from "@bindings/config/Config";
import { onMount } from "svelte";
import { OverlayScrollbarsComponent } from "overlayscrollbars-svelte";
import Header from "@app/components/Header.svelte";
@@ -57,43 +57,8 @@
breadcrumbs,
}: Props = $props();
let contentContainer: HTMLElement | undefined = $state();
let secondColumnContainer: HTMLElement | undefined = $state();
let loadingContent = false;
let loadingSecondColumn = false;
onMount(() => {
if (contentContainer && loadMoreContent) {
contentContainer.addEventListener("scroll", async () => {
if (
contentContainer &&
contentContainer.scrollTop + contentContainer.clientHeight >=
contentContainer.scrollHeight / 2 &&
loadingContent === false
) {
loadingContent = true;
void loadMoreContent().finally(() => (loadingContent = false));
}
});
}
if (secondColumnContainer && loadMoreSecondColumn) {
secondColumnContainer.addEventListener("scroll", async () => {
if (
secondColumnContainer &&
secondColumnContainer.scrollTop +
secondColumnContainer.clientHeight >=
secondColumnContainer.scrollHeight / 2 &&
loadingSecondColumn === false
) {
loadingSecondColumn = true;
void loadMoreSecondColumn().finally(
() => (loadingSecondColumn = false),
);
}
});
}
});
</script>
<style>
@@ -119,19 +84,13 @@
justify-content: space-between;
}
.secondColumn {
:global(.secondColumn) {
z-index: 10;
grid-column: 2 / 3;
max-width: 29rem;
min-width: 14rem;
padding: 1rem 1rem 1rem 0;
}
.content {
grid-column: 3 / 4;
width: 100%;
overflow: scroll;
overscroll-behavior: none;
}
</style>
<div class="layout">
@@ -148,18 +107,62 @@
</div>
{/if}
<div
<OverlayScrollbarsComponent
element="div"
class="secondColumn"
style:padding-left={hideSidebar ? "1rem" : "0"}
bind:this={secondColumnContainer}
style:display={oneColumnLayout && !hideSidebar ? "none" : undefined}
style:overflow={styleSecondColumnOverflow}>
style={`padding-left: ${hideSidebar ? "1rem" : "0"}; ${oneColumnLayout && !hideSidebar ? "display: none;" : ""}; overflow: ${styleSecondColumnOverflow}`}
events={{
scroll: instance => {
const secondColumnContainer = instance.elements().target;
if (
loadMoreSecondColumn &&
secondColumnContainer.scrollTop +
secondColumnContainer.clientHeight >=
secondColumnContainer.scrollHeight / 2 &&
loadingSecondColumn === false
) {
loadingSecondColumn = true;
void loadMoreSecondColumn().finally(
() => (loadingSecondColumn = false),
);
}
},
}}
options={{
overflow: { x: "visible" },
scrollbars: {
theme: "os-theme-radicle",
autoHide: "scroll",
},
}}
defer>
{@render secondColumn()}
</div>
</OverlayScrollbarsComponent>
<div
class="content global-reset-scroll-after-navigate"
bind:this={contentContainer}>
<OverlayScrollbarsComponent
element="div"
events={{
scroll: instance => {
const contentContainer = instance.elements().target;
if (
loadMoreContent &&
contentContainer.scrollTop + contentContainer.clientHeight >=
contentContainer.scrollHeight / 2 &&
loadingContent === false
) {
loadingContent = true;
void loadMoreContent().finally(() => (loadingContent = false));
}
},
}}
style="grid-column: 3/4; width: 100%;"
options={{
scrollbars: {
theme: "os-theme-radicle",
autoHide: "scroll",
},
}}
defer>
{@render children()}
</div>
</OverlayScrollbarsComponent>
</div>