mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 00:01:22 +02:00
Fix split layout not always working
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import useSize from '@react-hook/size';
|
||||
import classNames from 'classnames';
|
||||
import type { CSSProperties, MouseEvent as ReactMouseEvent, ReactNode } from 'react';
|
||||
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
||||
import { useLocalStorage } from 'react-use';
|
||||
import { useActiveWorkspace } from '../../hooks/useActiveWorkspace';
|
||||
import { useContainerSize } from '../../hooks/useContainerQuery';
|
||||
import { clamp } from '../../lib/clamp';
|
||||
import { ResizeHandle } from '../ResizeHandle';
|
||||
|
||||
@@ -61,7 +61,8 @@ export function SplitLayout({
|
||||
minHeightPx = 0;
|
||||
}
|
||||
|
||||
const verticalBasedOnSize = useSize(containerRef.current)[0] < STACK_VERTICAL_WIDTH;
|
||||
const size = useContainerSize(containerRef);
|
||||
const verticalBasedOnSize = size.width < STACK_VERTICAL_WIDTH;
|
||||
const vertical = layout !== 'horizontal' && (layout === 'vertical' || verticalBasedOnSize);
|
||||
|
||||
const styles = useMemo<CSSProperties>(() => {
|
||||
|
||||
30
src-web/hooks/useContainerQuery.ts
Normal file
30
src-web/hooks/useContainerQuery.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { MutableRefObject } from 'react';
|
||||
import { useLayoutEffect, useState } from 'react';
|
||||
|
||||
export function useContainerSize(ref: MutableRefObject<HTMLElement | null>) {
|
||||
const [size, setSize] = useState<{ width: number; height: number }>({ width: 0, height: 0 });
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const el = ref.current;
|
||||
if (el) {
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
entries.forEach((entry) => {
|
||||
if (entry.target === el) {
|
||||
setSize({ width: entry.contentRect.width, height: entry.contentRect.height });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
observer.observe(el);
|
||||
|
||||
return () => {
|
||||
observer.unobserve(el);
|
||||
observer.disconnect();
|
||||
};
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}, [ref]);
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
"@gilbarbara/deep-equal": "^0.3.1",
|
||||
"@lezer/highlight": "^1.1.3",
|
||||
"@lezer/lr": "^1.3.3",
|
||||
"@react-hook/size": "^2.1.2",
|
||||
"@tailwindcss/container-queries": "^0.1.1",
|
||||
"@tanstack/react-query": "^5.62.16",
|
||||
"@tanstack/react-router": "^1.95.1",
|
||||
|
||||
Reference in New Issue
Block a user