All Projects β†’ johnwalley β†’ allotment

johnwalley / allotment

Licence: MIT license
A React component for resizable split views

Programming Languages

typescript
32286 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to allotment

Pdfsam
PDFsam, a desktop application to extract pages, split, merge, mix and rotate PDF files
Stars: ✭ 1,829 (+409.47%)
Mutual labels:  split, splitter
react-collapse-pane
The splittable, draggable, collapsible panel layout library πŸŽ‰
Stars: ✭ 156 (-56.55%)
Mutual labels:  split, splitter
UnityGUI
UGUI Panel Systems for navigation, animation and more
Stars: ✭ 80 (-77.72%)
Mutual labels:  panel
thinkeys
Split ortholinear custom replacement keyboard with TrackPoint for ThinkPad laptops.
Stars: ✭ 167 (-53.48%)
Mutual labels:  split
log-master
split the log
Stars: ✭ 28 (-92.2%)
Mutual labels:  split
php-client
PHP SDK client for Split Software
Stars: ✭ 14 (-96.1%)
Mutual labels:  split
vue-modal
A customizable, stackable, and lightweight modal component for Vue.
Stars: ✭ 96 (-73.26%)
Mutual labels:  panel
git-split-diffs
GitHub style split diffs in your terminal
Stars: ✭ 2,423 (+574.93%)
Mutual labels:  split
board
A complete admin board template with a large variety of elements and components, based on blexar CSS framework.
Stars: ✭ 55 (-84.68%)
Mutual labels:  panel
KubePi
KubePi ζ˜―δΈ€δΈͺηŽ°δ»£εŒ–ηš„ K8s 青板。
Stars: ✭ 1,513 (+321.45%)
Mutual labels:  panel
BetterDiscordPanel
πŸ’¬ Discord Messaging Panel that allows you to message inside of a bot!
Stars: ✭ 512 (+42.62%)
Mutual labels:  panel
react-native-color-panel
React Native Color Panel Component for iOS and Android πŸ³οΈβ€πŸŒˆ
Stars: ✭ 21 (-94.15%)
Mutual labels:  panel
SpicyTaco.AutoGrid
A magical replacement for the built in WPF Grid and StackPanel
Stars: ✭ 67 (-81.34%)
Mutual labels:  panel
open-files
Atom package to show the open files in the tree-view panel, mirroring the functionality in Sublime Text
Stars: ✭ 15 (-95.82%)
Mutual labels:  pane
linux-mdss-dsi-panel-driver-generator
Generate Linux DRM panel kernel driver based on QCOM MDSS DSI device tree
Stars: ✭ 41 (-88.58%)
Mutual labels:  panel
kirby-previewfiles
πŸ’ͺ A Kirby field to enable file thumbnail preview in the panel sidebar
Stars: ✭ 35 (-90.25%)
Mutual labels:  panel
electron-panel
Manipulate panels in window for Electron.
Stars: ✭ 14 (-96.1%)
Mutual labels:  panel
aiopanel
An asyncio text-based panel
Stars: ✭ 20 (-94.43%)
Mutual labels:  panel
react-native-component-splitter
VS Code Extension allows splitting React Native Component into Sub-Component
Stars: ✭ 33 (-90.81%)
Mutual labels:  split
panel-chemistry
πŸ§ͺπŸ“ˆ 🐍. The purpose of the panel-chemistry project is to make it really easy for you to do DATA ANALYSIS and build powerful DATA AND VIZ APPLICATIONS within the domain of Chemistry using using Python and HoloViz Panel.
Stars: ✭ 94 (-73.82%)
Mutual labels:  panel

CI status GitHub license NPM Netlify Status

Logo

Allotment

React split-pane component.

  • React-based: Integrate effortlessly into your existing React-based application.
  • Industry standard look and feel: Like VS Code's split view implementation? You're in luck! This component is derived from the same codebase.
  • Dynamic: Want to declaratively add and remove panes? We've got you covered.

Examples

You can find examples of using the library here.

Getting Started

Allotment is available from npm.

Prerequisites

Allotment has react and react-dom as peer dependencies.

yarn add react react-dom

Installation

yarn add allotment

Usage

import React from "react";
import { Allotment } from "allotment";
import "allotment/dist/style.css";

export const App = () => (
  <Allotment>
    <ComponentA>
    <ComponentB>
  </Allotment>
);

If you want more control over the behaviour of the individual panes you can use the Allotment.Pane component. This includes setting the minimum and maximum size of a pane, as well as whether to enable snapping behaviour.

<Allotment>
  <Allotment.Pane minSize={200}>
    <ComponentA>
  </Allotment.Pane>
  <Allotment.Pane snap>
    <ComponentB>
  </Allotment.Pane>
</Allotment>

Allotment props

All properties are optional.

defaultSizes

An array of initial sizes of the panes. If the sum of the sizes differs from the size of the container then the panes' sizes will be scaled proportionally.

<Allotment defaultSizes={[100, 200]}>
  <div />
  <div />
</Allotment>

maxSize (default: Infinity)

Maximum size of any pane.

minSize (default: 30)

Minimum size of any pane.

proportionalLayout (default: true)

Resize each view proportionally when resizing container.

separator (default: true)

Whether to render a separator between panes.

snap (default: false)

Enable snap to zero for all panes.

vertical (default: false)

Direction to split. If true then the panes will be stacked vertically, otherwise they will be stacked horizontally.

onChange

Callback that is fired when the pane sizes change (usually on drag). Recommended to add a debounce function to rate limit the callback. Passed an array of numbers.

onReset

Callback that is fired whenever the user double clicks a sash.

onVisibleChange

Callback that is fired whenever the user changes the visibility of a pane by snapping. Note that this will only be called if the new value is different from the current visible prop on the Pane.

Allotment.Pane props

maxSize

Maximum size of this pane. Overrides maxSize set on parent component.

minSize

Minimum size of this pane. Overrides minSize set on parent component.

priority

The priority of the pane when the layout algorithm runs. Panes with higher priority will be resized first.

Only used when proportionalLayout is false.

preferredSize

Preferred size of this pane. Allotment will attempt to use this size when adding this pane (including on initial mount) as well as when a user double clicks a sash, or the reset method is called on the Allotment instance.

The size can either be a number or a string. If it is a number it will be interpreted as a number of pixels. If it is a string it should end in either "px" or "%". If it ends in "px" it will be interpreted as a number of pixels, e.g. "120px". If it ends in "%" it will be interpreted as a percentage of the size of the Allotment component, e.g. "50%".

snap

Enable snap to zero for this pane. Overrides snap set on parent component.

visible

Whether the pane should be visible.

Styling

Allotment uses CSS variables for styling. You can customize the following default variables.

:root {
  --focus-border: #007fd4;
  --separator-border: #838383;
}

To control the feedback area size of the dragging area between panes you can call the exported setSashSize function with desired size in pixels. Set it to a larger value if you feel it's hard to resize the panes using the mouse. On touch devices the feedback area is always set to 20 pixels

Programmatic control

You can use a ref to get access to the Allotment component instance and call its reset and resize methods manually:

const ref = React.useRef(ref);

return (
  <div>
    <button
      onClick={() => {
        ref.current.reset();
      }}
    >
      Reset
    </button>
    <button
      onClick={() => {
        ref.current.resize([100, 200]);
      }}
    >
      Resize
    </button>
    <Allotment ref={ref}>
      <div />
      <div />
    </Allotment>
  </div>
);

Frequently asked questions

It's not working/I don't see anything

The Allotment component takes its width and height from the element which contains it. It does not come with an explicit width or height out of the box. It's easy to end up with a div of height zero by accident. For example, adding allotment to a brand new Create React App project without setting a height on a containing div won't work because the default root div itself has no height.

You should also check that the css has been imported/included, for example at the root of your application:

import "allotment/dist/style.css";

My content is larger than the containing pane. How can I let the user scroll?

The simplest approach is to place your content inside a new div with width and height 100% and overflow auto. This div will have the same dimensions as the pane it's inside and if its content overflows the browser will provide scrolling behaviour.

Next.js

If you get an error when importing allotment in a Next.js project consider not including the module server-side. Allotment currently only works in a browser. It might be possible to produce sensible results server-side in the future so create an issue requesting this if interested.

How do I prevent a pane from being resized?

Set minSize and maxSize props to the same value.

How do I style the component?

Some common style changes can be made by setting CSS variables.

These include:

Name Default Description
--focus-border #007fd4 Color of the sash when hovered
--separator-border rgba(128, 128, 128, 0.35) Color of the separator

For more involved styling you can target the component's child elements.

Class Description
.split-view Styles applied to the top-level container
.split-view-horizontal Styles applied to the top-level container if `vertical={false}
.split-view-vertical Styles applied to the top-level container if `vertical={true}
.split-view-separator-border Styles applied to the top-level container if `separator={true}
.sash-container Styles applied to the sash container
.sash Styles applied to the sash
.sash-active Styles applied to the sash if being dragged
.sash-disabled Styles applied to the sash if disabled
.sash-horizontal Styles applied to the sash if vertical={false}`
.sash-hover Styles applied to the sash if being hovered over
.sash-mac Styles applied to the sash if running under macos
.sash-maximum Styles applied to the sash if the pane is maximised
.sash-minimum Styles applied to the sash if the pane is minimised
.sash-vertical Styles applied to the sash if vertical={true}`
.split-view-container Styles applied to the split view container
.split-view-view Styles applied to the split view view
.split-view-view-visible Styles applied to the split view view if visible={true}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].