fix: prevent collapse to too narrow

This commit is contained in:
EnixCoda 2020-11-04 21:43:01 +08:00
parent 087ed0e3e0
commit b2150b9212
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD

View file

@ -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)}>