Optimize HideScrollbar and sidebar

This commit is contained in:
2023-11-03 13:35:20 +08:00
parent 7d6cd3cb26
commit bc196d4ba9
2 changed files with 26 additions and 17 deletions

View File

@@ -202,6 +202,8 @@
font-size: 1.4em; font-size: 1.4em;
color: constants.$font-main-color; color: constants.$font-main-color;
user-select: text; user-select: text;
overflow: hidden;
text-overflow: ellipsis;
a{ a{
color: constants.$main-color; color: constants.$main-color;

View File

@@ -411,30 +411,37 @@ const HideScrollbar = forwardRef<HideScrollbarElement, HideScrollbarProps>((prop
setRefreshTime(Date.now()) setRefreshTime(Date.now())
} }
const reloadScrollbar = () => {
setVerticalScrollbarWidth(
(rootRef.current?.offsetWidth ?? 0) - (rootRef.current?.clientWidth ?? 0)
)
setHorizontalScrollbarWidth(
(rootRef.current?.offsetHeight ?? 0) - (rootRef.current?.clientHeight ?? 0)
)
rootRef.current &&
setVerticalScrollbarLength(
(rootRef.current.clientHeight / (contentRef.current?.clientHeight ?? 0)) * 100
)
rootRef.current &&
setHorizontalScrollbarLength(
(rootRef.current.clientWidth / (contentRef.current?.clientWidth ?? 0)) * 100
)
refreshLayout()
}
useEffect(() => { useEffect(() => {
const resizeObserver = new ResizeObserver(() => { const resizeObserver = new ResizeObserver(() => {
setVerticalScrollbarWidth( reloadScrollbar()
(rootRef.current?.offsetWidth ?? 0) - (rootRef.current?.clientWidth ?? 0)
)
setHorizontalScrollbarWidth(
(rootRef.current?.offsetHeight ?? 0) - (rootRef.current?.clientHeight ?? 0)
)
rootRef.current &&
setVerticalScrollbarLength(
(rootRef.current.clientHeight / (contentRef.current?.clientHeight ?? 0)) * 100
)
rootRef.current &&
setHorizontalScrollbarLength(
(rootRef.current.clientWidth / (contentRef.current?.clientWidth ?? 0)) * 100
)
refreshLayout()
}) })
maskRef.current && resizeObserver.observe(maskRef.current) maskRef.current && resizeObserver.observe(maskRef.current)
contentRef.current && resizeObserver.observe(contentRef.current)
return () => { return () => {
maskRef.current && resizeObserver.unobserve(maskRef.current) maskRef.current && resizeObserver.unobserve(maskRef.current)
contentRef.current && resizeObserver.unobserve(contentRef.current)
} }
}, []) }, [])