mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: prevent collapse to too narrow
This commit is contained in:
parent
087ed0e3e0
commit
b2150b9212
1 changed files with 7 additions and 1 deletions
|
|
@ -14,6 +14,7 @@ type Props = {
|
|||
}
|
||||
|
||||
const MINIMAL_CONTENT_VIEWPORT_WIDTH = 100
|
||||
const MINIMAL_WIDTH = 240
|
||||
|
||||
export function Resizable({ baseSize, className, children }: React.PropsWithChildren<Props>) {
|
||||
const [size, setSize] = React.useState(baseSize)
|
||||
|
|
@ -27,6 +28,7 @@ export function Resizable({ baseSize, className, children }: React.PropsWithChil
|
|||
React.useEffect(() => {
|
||||
if (size > width - MINIMAL_CONTENT_VIEWPORT_WIDTH)
|
||||
setSize(width - MINIMAL_CONTENT_VIEWPORT_WIDTH)
|
||||
else if (size < MINIMAL_WIDTH) setSize(MINIMAL_WIDTH)
|
||||
}, [width, size])
|
||||
|
||||
React.useEffect(() => {
|
||||
|
|
@ -39,7 +41,11 @@ export function Resizable({ baseSize, className, children }: React.PropsWithChil
|
|||
useDebounce(() => configContext.set({ sideBarWidth: size }), 100, [size])
|
||||
|
||||
const onResize = React.useCallback((size: number) => {
|
||||
if (size < window.innerWidth - MINIMAL_CONTENT_VIEWPORT_WIDTH) setSize(size)
|
||||
// do NOT merge this with the above similar effect, side bar will jump otherwise
|
||||
if (size > width - MINIMAL_CONTENT_VIEWPORT_WIDTH)
|
||||
setSize(width - MINIMAL_CONTENT_VIEWPORT_WIDTH)
|
||||
else if (size < MINIMAL_WIDTH) setSize(MINIMAL_WIDTH)
|
||||
else setSize(size)
|
||||
}, [])
|
||||
return (
|
||||
<div className={cx('gitako-position-wrapper', className)}>
|
||||
|
|
|
|||
Loading…
Reference in a new issue