Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(ui): scroll bar height (#3255)

Fake-User78a3d62a05a7
diff --git a/js/app/packages/core/component/CustomScrollbar.tsx b/js/app/packages/core/component/CustomScrollbar.tsx
index d1cb829445..e1d805a159 100644
--- a/js/app/packages/core/component/CustomScrollbar.tsx
+++ b/js/app/packages/core/component/CustomScrollbar.tsx
@@ -14,7 +14,7 @@ interface CustomScrollbarProps {
horizontal?: boolean;
}
-const THUMB_SIZE = 200;
+const MIN_THUMB_SIZE = 24;
const GUTTER_SIZE = 8;
const THUMB_INSET = 3;
const THUMB_THICKNESS = 2;
@@ -64,6 +64,17 @@ function InnerCustomScrollbar(props: CustomScrollbarProps) {
const maxScroll = () => Math.max(0, scrollSize() - clientSize());
+ const trackSize = () => Math.max(0, clientSize() - THUMB_INSET * 2);
+
+ const thumbSize = () => {
+ const ts = trackSize();
+ const ss = scrollSize();
+ const ratio = ss > 0 ? clientSize() / ss : 1;
+ return Math.max(MIN_THUMB_SIZE, Math.min(ts, ts * ratio));
+ };
+
+ const maxTop = () => Math.max(0, trackSize() - thumbSize());
+
const scrollOffset = () => {
const max = maxScroll();
if (max <= 0) return 0;
@@ -74,11 +85,9 @@ function InnerCustomScrollbar(props: CustomScrollbarProps) {
};
const thumbOffset = () => {
- const cSize = clientSize();
const max = maxScroll();
if (max <= 0) return 0;
- const maxTop = Math.max(0, cSize - THUMB_SIZE - THUMB_INSET * 2);
- return THUMB_INSET + (scrollOffset() / max) * maxTop;
+ return THUMB_INSET + (scrollOffset() / max) * maxTop();
};
const isVisible = () => scrollSize() > clientSize();
@@ -114,13 +123,12 @@ function InnerCustomScrollbar(props: CustomScrollbarProps) {
if (!container) return;
const max = maxScroll();
if (max <= 0) return;
- const cSize = clientSize();
- const maxTop = Math.max(0, cSize - THUMB_SIZE - THUMB_INSET * 2);
- if (maxTop <= 0) return;
+ const mt = maxTop();
+ if (mt <= 0) return;
const start = horiz() ? gutterRect.left : gutterRect.top;
- const localPos = clientPos - start - THUMB_SIZE / 2;
- const clamped = Math.max(0, Math.min(maxTop, localPos - THUMB_INSET));
- let newPos = (clamped / maxTop) * max;
+ const localPos = clientPos - start - thumbSize() / 2;
+ const clamped = Math.max(0, Math.min(mt, localPos - THUMB_INSET));
+ let newPos = (clamped / mt) * max;
if (props.reverse && !horiz()) newPos = newPos - max;
if (horiz()) {
container.scrollLeft = newPos;
@@ -184,7 +192,7 @@ function InnerCustomScrollbar(props: CustomScrollbarProps) {
horiz()
? {
transform: `translateX(${thumbOffset()}px)`,
- width: `${THUMB_SIZE}px`,
+ width: `${thumbSize()}px`,
height: `${THUMB_THICKNESS}px`,
bottom: `${EDGE_INSET}px`,
left: '0',
@@ -196,7 +204,7 @@ function InnerCustomScrollbar(props: CustomScrollbarProps) {
}
: {
transform: `translateY(${thumbOffset()}px)`,
- height: `${THUMB_SIZE}px`,
+ height: `${thumbSize()}px`,
width: `${THUMB_THICKNESS}px`,
right: `${EDGE_INSET}px`,
top: '0',
@@ -215,7 +223,7 @@ function InnerCustomScrollbar(props: CustomScrollbarProps) {
props.labelClass
)}
style={{
- top: `${thumbOffset() + THUMB_SIZE / 2}px`,
+ top: `${thumbOffset() + thumbSize() * 0.5}px`,
opacity: scrollLabelVisible() ? 1 : 0,
}}
>
diff --git a/js/app/packages/ui/components/Scroll.tsx b/js/app/packages/ui/components/Scroll.tsx
index 9358eed2cf..475d048ba3 100644
--- a/js/app/packages/ui/components/Scroll.tsx
+++ b/js/app/packages/ui/components/Scroll.tsx
@@ -4,11 +4,12 @@ import type { JSX } from 'solid-js';
const THUMB_WIDTH = 2;
const HIDE_DELAY = 500;
const GUTTER_WIDTH = 8;
-const THUMB_HEIGHT = 200;
+const MIN_THUMB_HEIGHT = 24;
const THUMB_INSET = (GUTTER_WIDTH - THUMB_WIDTH) * 0.5;
export function Scroll(props: JSX.HTMLAttributes<HTMLDivElement>) {
const [translateY, setTranslateY] = createSignal(THUMB_INSET);
+ const [thumbHeight, setThumbHeight] = createSignal(MIN_THUMB_HEIGHT);
const [visible, setVisible] = createSignal(false);
let hideTimer: ReturnType<typeof setTimeout> | undefined;
@@ -31,8 +32,13 @@ export function Scroll(props: JSX.HTMLAttributes<HTMLDivElement>) {
function config() {
const ch = scrollRef.clientHeight;
- maxScroll = Math.max(0, scrollRef.scrollHeight - ch);
- maxTop = Math.max(0, ch - THUMB_HEIGHT - THUMB_INSET * 2);
+ const sh = scrollRef.scrollHeight;
+ const trackHeight = Math.max(0, ch - THUMB_INSET * 2);
+ const ratio = sh > 0 ? ch / sh : 1;
+ const th = Math.max(MIN_THUMB_HEIGHT, Math.min(trackHeight, trackHeight * ratio));
+ setThumbHeight(th);
+ maxScroll = Math.max(0, sh - ch);
+ maxTop = Math.max(0, trackHeight - th);
update();
}
@@ -43,7 +49,7 @@ export function Scroll(props: JSX.HTMLAttributes<HTMLDivElement>) {
function seek(localY: number) {
if (maxScroll <= 0 || maxTop <= 0) { return; }
- scrollRef.scrollTop = Math.max(0, Math.min(maxTop, localY - THUMB_HEIGHT / 2 - THUMB_INSET)) / maxTop * maxScroll;
+ scrollRef.scrollTop = Math.max(0, Math.min(maxTop, localY - thumbHeight() / 2 - THUMB_INSET)) / maxTop * maxScroll;
reveal();
}
@@ -112,7 +118,7 @@ export function Scroll(props: JSX.HTMLAttributes<HTMLDivElement>) {
'transition': 'opacity 150ms ease-in-out',
'border-radius': `${THUMB_WIDTH * 0.5}px`,
'background-color': 'var(--c4)',
- 'height': `${THUMB_HEIGHT}px`,
+ 'height': `${thumbHeight()}px`,
'opacity': visible() ? 1 : 0,
'right': `${THUMB_INSET}px`,
'width': `${THUMB_WIDTH}px`,