allotment

repository·main·Indexed 22 days ago

https://github.com/johnwalley/allotment

A React-based split-pane component for creating customizable, resizable layouts similar to VS Code. It provides the Allotment component for the main container and Allotment.Pane for granular control over individual panes, including minimum/maximum sizes, visibility, and snapping behavior. The library supports both horizontal and vertical orientations, proportional layout resizing, and programmatic control via refs using the AllotmentHandle.

Tokens
5.9K
Snippets
17
Records
42
Agent score
78%

What's inside allotment

  1. Enable scrolling for content within a pane

    main

    If your content is larger than the Allotment pane, you can enable scrolling by wrapping your content in a div with the following CSS properties:

    • width: 100%
    • height: 100%
    • overflow: auto

    This ensures the wrapper matches the pane's dimensions and triggers browser scrolling when content overflows.

  2. Quick start with Allotment

    main

    To create a basic split-pane layout, wrap your panes in the Allotment component.

    Important: You must import the required CSS for the layout to render correctly: import "allotment/dist/style.css"

    import * as React from "react";
    import ReactDOM from "react-dom";
    import { Allotment } from "allotment";
    import "allotment/dist/style.css";
    
    function App() {
      return (
        <Allotment>
          <div>Pane 1</div>
          <div>Pane 2</div>
        </Allotment>
      );
    }
    
    ReactDOM.render(<App />, document.querySelector("#app"));
  3. Use Sizing strategies when adding or removing views

    main

    When adding or removing views, you can use Sizing strategies to control how the available space (the delta) is redistributed among other views. Use the Sizing namespace for convenience.

    Strategies:

    • Sizing.Distribute: Distributes the delta space equally among all other views.
    • Sizing.Split(index): Splits the delta space with a specific view at the provided index.
    • Sizing.Invisible(cachedVisibleSize): Treats the view as if it were invisible, using the provided cachedVisibleSize to maintain layout stability.