feat: Folder column size adjustment (#384)
This commit is contained in:
@@ -4,16 +4,22 @@ import { useState, useRef, useEffect, ReactNode } from 'react';
|
|||||||
type Props = {
|
type Props = {
|
||||||
leftPane: ReactNode;
|
leftPane: ReactNode;
|
||||||
rightPane: ReactNode;
|
rightPane: ReactNode;
|
||||||
|
minLeftWidth?: number;
|
||||||
|
minRightWidth?: number;
|
||||||
|
defaultLeftWidth?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ResizablePanes({ leftPane, rightPane }: Props) {
|
export default function ResizablePanes({
|
||||||
const [leftWidth, setLeftWidth] = useState(70); // default 70%
|
leftPane,
|
||||||
|
rightPane,
|
||||||
|
minLeftWidth = 40,
|
||||||
|
minRightWidth = 15,
|
||||||
|
defaultLeftWidth = 70,
|
||||||
|
}: Props) {
|
||||||
|
const [leftWidth, setLeftWidth] = useState(defaultLeftWidth); // default 70%
|
||||||
const [isDragging, setIsDragging] = useState(false);
|
const [isDragging, setIsDragging] = useState(false);
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const minLeftWidth = 40; // left panel min width 40%
|
|
||||||
const minRightWidth = 15; // right panel min width 15%
|
|
||||||
|
|
||||||
const handleMouseDown = () => {
|
const handleMouseDown = () => {
|
||||||
setIsDragging(true);
|
setIsDragging(true);
|
||||||
};
|
};
|
||||||
@@ -45,7 +51,7 @@ export default function ResizablePanes({ leftPane, rightPane }: Props) {
|
|||||||
document.removeEventListener('mousemove', handleMouseMove);
|
document.removeEventListener('mousemove', handleMouseMove);
|
||||||
document.removeEventListener('mouseup', handleMouseUp);
|
document.removeEventListener('mouseup', handleMouseUp);
|
||||||
};
|
};
|
||||||
}, [isDragging]);
|
}, [isDragging, minLeftWidth, minRightWidth]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={containerRef} className="flex h-full" style={{ userSelect: isDragging ? 'none' : 'auto' }}>
|
<div ref={containerRef} className="flex h-full" style={{ userSelect: isDragging ? 'none' : 'auto' }}>
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ export default function FoldersPane({ projectId, messages, locale }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="w-80 min-h-[calc(100vh-64px)] border-r-1 dark:border-neutral-700">
|
<div className="min-h-[calc(100vh-64px)] border-r-1 dark:border-neutral-700">
|
||||||
<Button
|
<Button
|
||||||
startContent={<Plus size={16} />}
|
startContent={<Plus size={16} />}
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import FoldersPane from './FoldersPane';
|
import FoldersPane from './FoldersPane';
|
||||||
|
import ResizablePanes from '@/components/ResizablePane';
|
||||||
|
|
||||||
export default function FoldersLayout({
|
export default function FoldersLayout({
|
||||||
children,
|
children,
|
||||||
@@ -25,9 +26,12 @@ export default function FoldersLayout({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex w-full">
|
<ResizablePanes
|
||||||
<FoldersPane projectId={params.projectId} messages={messages} locale={params.locale} />
|
minLeftWidth={15}
|
||||||
<div className="flex-grow w-full">{children}</div>
|
minRightWidth={40}
|
||||||
</div>
|
defaultLeftWidth={20}
|
||||||
|
leftPane={<FoldersPane projectId={params.projectId} messages={messages} locale={params.locale} />}
|
||||||
|
rightPane={children}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user