Gathering detailed insights and metrics for @pakholeung37/allotment
Gathering detailed insights and metrics for @pakholeung37/allotment
A React component for resizable split views
npm install @pakholeung37/allotment
Typescript
Module System
Node Version
NPM Version
71.2
Supply Chain
94.2
Quality
80.1
Maintenance
100
Vulnerability
98.9
License
TypeScript (82.96%)
CSS (12.35%)
JavaScript (4.69%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
702
Last Day
1
Last Week
1
Last Month
32
Last Year
702
MIT License
1,035 Stars
772 Commits
57 Forks
8 Watchers
18 Branches
15 Contributors
Updated on Feb 14, 2025
Minified
Minified + Gzipped
Latest Version
1.24.1
Package Id
@pakholeung37/allotment@1.24.1
Unpacked Size
356.96 kB
Size
78.51 kB
File Count
40
NPM Version
10.5.2
Node Version
20.13.1
Published on
Jun 21, 2024
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-83.3%
1
Compared to previous week
Last Month
6.7%
32
Compared to previous month
Last Year
0%
702
Compared to previous year
57
React split-pane component.
You can find examples of using the library here.
Allotment is available from npm.
Allotment has react
and react-dom
as peer dependencies.
1npm install react react-dom
1npm install allotment
1import React from "react"; 2import { Allotment } from "allotment"; 3import "allotment/dist/style.css"; 4 5export const App = () => ( 6 <Allotment> 7 <ComponentA> 8 <ComponentB> 9 </Allotment> 10);
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.
1<Allotment> 2 <Allotment.Pane minSize={200}> 3 <ComponentA> 4 </Allotment.Pane> 5 <Allotment.Pane snap> 6 <ComponentB> 7 </Allotment.Pane> 8</Allotment>
All properties are optional.
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.
1<Allotment defaultSizes={[100, 200]}> 2 <div /> 3 <div /> 4</Allotment>
Infinity
)Maximum size of any pane.
30
)Minimum size of any pane.
true
)Resize each view proportionally when resizing container.
true
)Whether to render a separator between panes.
false
)Enable snap to zero for all panes.
false
)Direction to split. If true then the panes will be stacked vertically, otherwise they will be stacked horizontally.
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.
Callback that is fired when the user clicks on the sash
Callback that is fired when the user stops clicking the sash
Callback that is fired whenever the user double clicks a sash.
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.
Maximum size of this pane. Overrides maxSize
set on parent component.
Minimum size of this pane. Overrides minSize
set on parent component.
The priority of the pane when the layout algorithm runs. Panes with higher priority will be resized first.
Only used when proportionalLayout
is false.
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%".
Enable snap to zero for this pane. Overrides snap
set on parent component.
Whether the pane should be visible.
Allotment uses CSS variables for styling. You can customize the following default variables.
1:root { 2 --focus-border: #007fd4; 3 --separator-border: #838383; 4}
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
You can use a ref to get access to the Allotment component instance and call its reset and resize methods manually:
1const ref = React.useRef(ref); 2 3return ( 4 <div> 5 <button 6 onClick={() => { 7 ref.current.reset(); 8 }} 9 > 10 Reset 11 </button> 12 <button 13 onClick={() => { 14 ref.current.resize([100, 200]); 15 }} 16 > 17 Resize 18 </button> 19 <Allotment ref={ref}> 20 <div /> 21 <div /> 22 </Allotment> 23 </div> 24);
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:
1import "allotment/dist/style.css";
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.
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.
Set minSize
and maxSize
props to the same value.
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} |
.split-view-sash-dragging | Styles applied to the top-level container if sash is dragging |
.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} |
No vulnerabilities found.
No security vulnerabilities found.