diff --git a/src/allotment.tsx b/src/allotment.tsx index d99c94d6..837a3f31 100644 --- a/src/allotment.tsx +++ b/src/allotment.tsx @@ -25,6 +25,8 @@ function isPane(item: React.ReactNode): item is typeof Pane { function isPaneProps(props: AllotmentProps | PaneProps): props is PaneProps { return ( + (props as PaneProps).minSize !== undefined || + (props as PaneProps).maxSize !== undefined || (props as PaneProps).preferredSize !== undefined || (props as PaneProps).visible !== undefined ); @@ -327,9 +329,34 @@ const Allotment = forwardRef( const index = keys.findIndex((key) => key === updateKey); if (props && isPaneProps(props)) { - if (props.preferredSize !== undefined) { + if ( + props.preferredSize !== undefined && + views.current[index].preferredSize !== props.preferredSize + ) { views.current[index].preferredSize = props.preferredSize; } + + let sizeChanged = false; + + if ( + props.minSize !== undefined && + views.current[index].minimumSize !== props.minSize + ) { + views.current[index].minimumSize = props.minSize; + sizeChanged = true; + } + + if ( + props.maxSize !== undefined && + views.current[index].maximumSize !== props.maxSize + ) { + views.current[index].maximumSize = props.maxSize; + sizeChanged = true; + } + + if (sizeChanged) { + splitViewRef.current?.layout(); + } } } diff --git a/src/split-view/split-view.ts b/src/split-view/split-view.ts index 0b3ff9a6..2d75f973 100644 --- a/src/split-view/split-view.ts +++ b/src/split-view/split-view.ts @@ -146,6 +146,39 @@ export interface View { setVisible?(visible: boolean): void; } +export interface PaneViewOptions { + element: HTMLElement; + minimumSize?: number; + maximumSize?: number; + snap?: boolean; +} + +export class PaneView implements View { + public minimumSize: number = 0; + public maximumSize: number = Number.POSITIVE_INFINITY; + + readonly element: HTMLElement; + readonly snap: boolean; + + constructor(options: PaneViewOptions) { + this.element = options.element; + + this.minimumSize = + typeof options.minimumSize === "number" ? options.minimumSize : 30; + + this.maximumSize = + typeof options.maximumSize === "number" + ? options.maximumSize + : Number.POSITIVE_INFINITY; + + this.snap = typeof options.snap === "boolean" ? options.snap : false; + } + + layout(size: number): void { + //console.log(size); + } +} + type ViewItemSize = number | { cachedVisibleSize: number }; abstract class ViewItem { @@ -537,7 +570,7 @@ export class SplitView extends EventEmitter implements Disposable { * * @param size The entire size of the {@link SplitView}. */ - public layout(size: number): void { + public layout(size: number = this.size): void { const previousSize = Math.max(this.size, this.contentSize); this.size = size;