Git Product home page Git Product logo

allotment's Introduction

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.

npm install react react-dom

Installation

npm install 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.

onDragStart

Callback that is fired when the user clicks on the sash

onDragEnd

Callback that is fired when the user stops clicking the sash

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}
.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}

allotment's People

Contributors

china-bin avatar dependabot[bot] avatar dsherret avatar gelio avatar github-actions[bot] avatar jerebtw avatar johnwalley avatar mahendradambe avatar marcgabe15 avatar masesk avatar pahen avatar percy507 avatar renovate[bot] avatar sergeysova avatar su-yong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

allotment's Issues

Add prop `resetToDefaultSizes` to fine-tune reset behavior

As a developer I want to be able to control the reset behavior with one flag instead of having to write custom code, in order to make the reset functionality respect the defaultSizes property.

Currently double-clicking on a sash doesn't really "reset" the layout to it's inital state if defaultSizes are set, but distributes everything equally.

I see that there were some issues regarding this but as I can see the only option is for now to use the callbacks.

Describe how you should style your content

Purpose

As a developer I want it to be clear how I ensure my content takes up the available space provided.

Proposal

Make it clear that the library does not modify the styling of you content. Instead it wraps it with a div of the appropriate width or height. It's up to the user to ensure their content responds accordingly.

Acceptance criteria

  • As a developer I can read a description of how the library works
  • As a developer I can access an example of styling content

Impossible to use `visible` and `snap` props at the same time

Snapping to zero size internally involves setting visible to false. However, if the visible prop is set to true then there is a conflict and the implementation does not aim to handle it.

This is an example of where we run into problems with mixing controlled and uncontrolled state in one component. For performance reasons I want to keep the sizes of the panes uncontrolled as the user interacts with them.

Using controlled props like snap and visible is a good fit for React and its declarative nature. And in this case there appears to be an obvious solution: provide a callback for when the visibility changes. Perhaps onVisibleChange?

Document styling the component

Purpose

As a developer I want to know what and how I can style the component.

Proposal

Customisation is currently done using CSS custom properties. We should document this.

Additionally, it might be helpful to explain how the children should be styled. In particular, the children should take up the parents' dimensions and so should have at least height: 100%;.

Acceptance criteria

  • As a developer I can read about at least one CSS custom variable I can override in the README

Changing minSize or maxSize prop has no effect

Purpose

As a developer I want to control the size of a pane and update this over time, e.g. as the contents change dimensions.

Proposal

The underlying VS Code implementation supports this so investigate and decide how to implement the React side.

This will, in general, cause the size of the panes to change.

See the "Open Editors" pane in VS Code as a canonical example.

Acceptance criteria

  • As a developer I can change both minSize and maxSize props and see this reflected in the rendered component

Allotment.Pane add prop defaultSize

The Allotment.Pane seem to use the maxSize to as a default size. But I want to controll the default pane size. so. I think that is great to add prop defaultSize.

example code:

<Allotment.Pane maxSize={200} minSize={100} defaultSize={100}>
  <div>div1</div>
</Allotment.Pane>

Permanently visible sash

Hi. I am trying to use the library to show resize handles (sashes?) permanently.

It seems like the current solution floats the overlay on top of the content, showing the blue bar when hovered. I would like to produce a handle that is either 10px wide or tall, dependant on orientation, and 'pushes' the other content away from it, such that this 10px handle produces a gap between the two panes. I then also plan to add an icon indicating that the divider itself is a drag handle, to visually aid users.

Given the divider is permanently floating on top of the content, and not actually affecting the gap between two panels, I don't see a way to implement this common use-case with Allotment.

Here is an example demonstrating my intentions, with rather large drag handles (30px wide/tall) that have a visual indicator as a background-image, and demonstrates the handle eating into the space of the panels rather than being laid on top of it.

Please could you advise if this is a use-case you plan to support? The support for visual indication & large drag handles that don't cut-off content by floating above it are high-priority for users with visual impairment, which I am obligated to support.

Thanks in advance.

Support programmatic reset

Purpose

As a developer I want to 'reset' the pane layout.

Proposal

Expose a method reset via useImperativeHandle.

Acceptance criteria

  • As a developer I can call a reset method via a React ref to the Allotment component

Shrink contents of pane to pane size

Hello John,

See the following video, how do I shrink the contents of the pane to be the pane size?
I'm not quite sure the CSS I need to change.
I would appreciate your help.

Screencast.from.31-10-21.11.49.48.mp4

Thanks,
Marten Mooij

Sash is not centered around border

This is because the size of the sash is hardcoded to 4. Instead it should reflect the CSS Custom Property `--sash-size`` if available.

Mention mobile/touch friendly

Purpose

As a developer I want to know this library will play nice with mobile and touch devices.

Proposal

Check this is true! If it is then add a line near the top of the README to this effect.

Acceptance criteria

  • As a developer I can validate that the library works on mobile and touch devices
  • As a developer I can learn that the library works on mobile and touch devices from reading the documentation

Sash is wrong on mobile

Currently we detect whether we're on a touch/mobile device and set the sash size based on this. However, this has no effect on the related css variables.

Screenshot 2021-12-25 at 00 11 02

I think we will have to give up using css variables to customise the size of the sash and move to setting it using javascript. Basically, the way VS Code does it. We can still use css variables internally, but it will no longer be the documented method of customising the sash. This will be a breaking change.

I can't seem to change the props for onChange.

I can't seem to change the props for onChange.

If I dynamically add a new pane, I want to change the onChange function to be able to act on the new pane.

Currently the onChange function is saved on first render and any updates, or passing useCallback function won't update the internal onChange function.
So it's impossible to act on the new state.

Only way to make it work now was to do the following

  const reducer = useCallback((state, action) => {
    switch (action.type) {
      case "openSideDrawer":
        return {...state, sideDrawer: true}
      case "openBottomDrawer":
        return {...state, bottomDrawer: true}
      case "closeSideDrawer":
        return state.sideDrawer ? {...state, sideDrawer: false} : state
      case "closeBottomDrawer":
        return state.bottomDrawer ? {...state, bottomDrawer: false} : state
      default:
        throw new Error()
    }
  }, [])

  const [state, dispatch] = useReducer(reducer, {sideDrawer: false, bottomDrawer: false})

  const onChangeBottom = useCallback((panes) => {
    if (panes[panes.length - 1] === 0) {
      dispatch({type: "closeBottomDrawer"})
    }
  }, [])

  const onChangeRight = useCallback((panes) => {
    if (panes[panes.length - 1] === 0) {
      dispatch({type: "closeSideDrawer"})
    }
  }, [])
  
  return <Allotment vertical onChange={onChangeBottom}>
        <Allotment.Pane>
          <Allotment onChange={onChangeRight}>
            <Allotment.Pane>
               Main pane
            </Allotment.Pane>
            <Allotment.Pane snap>
               Right pane
            </Allotment.Pane>
            {state.sideDrawer && <Allotment.Pane snap>
                Right drawer
            </Allotment.Pane>}
          </Allotment>
        </Allotment.Pane>

        {state.bottomDrawer && <Allotment.Pane snap>
          Bottom drawer
        </Allotment.Pane>}
      </Allotment>

Originally posted by @benoist in #13 (comment)

defaultSizes behavior combined with minSize and proportionalLayout

Hey @johnwalley ,

Thanks for providing us with Allotment. It is great!

So I think I might be confused at how to correctly use defaultSizes. For my use-case I have two panes (left, right). I expect the one on the left to always be larger than the one on the right [500, 365]. Below is my impl for the Allotment that contains those two panes.

This seems to work correctly unless my parent container (365px) is smaller than the required "allotment" (365+365) due to minSize. At this point both left and right panes are resized to 365 and the right pane seems to take priority pushing the left pane out of view. Where I would expect the left to take priority due to defaultSizes.

Allotment.onChange sizing:
size (2) [1043, 762] <- resize full screen (parent 1043px)
size (2) [365, 365] <- resize parent to 365px.

 <Allotment
            className="dash-allotment"
            onChange={(size: number[]) => {
                console.log('size', size);
            }}
            proportionalLayout
            defaultSizes={[500, 365]}
            minSize={365}
        >
<leftPane/>
<rightPane/>
</Allotment>

My question is should defaultSizes ratio take priority and resize proportionally when the size of the parent is not large enough to account provided panes within? I've added proportionalLayout but seems to have no effect. When I reduce minSize to 150 the layout seems to behave again.

Once again thanks for the help and I appreciate any advice/feedback on what I might be doing incorrect,
Michael

Affect which panels resize when window resizes

First of all, thanks so much for an amazing library - was very happy to find it and the feature set and implementation is excellent.

One last challenge I have is that I have a left and a right sidebar, with main content being in the center. If I increase the window size by dragging it to the right, I would want the center panel to stretch, but sidebars to remain at their preferredSize.

By default, all panels will stretch proportionally, and when I set the proportionalLayout to false, only the right sidebar resizes :)

Any hint as to how I can affect this behaviour?

Thanks!

Content should not be visible if `visible` pane prop is false?

Currently if visible is set to false then the size of the pane is set to 0. However, if the content is larger than the size, it will be visible. For example, the text "Drag view here to display' is visible in this screenshot.

Screenshot 2022-04-20 at 22 22 49

Technically, this could be the concern of the user and they should set a suitable overflow value. Also note, that this is not really about whether the pane is visible, if the content overflows the pane at any size it is an issue. In practice I wonder if it is more ergonomic for Allotment to set overflow hidden and remove the requirement to care about this?

Describe in more details how you would use library with Next.js

Purpose

As a developer using Next.js I want it know how I should use the library

Proposal

We have a link to the workaround in the Next.js documentation but it would be even more helpful to give examples.

Acceptance criteria

  • As a developer I can see example code which I can copy and paste to get it working in my own project

SplitView class should be responsible for adding and removing elements from the DOM

Purpose

As a library developer I never want the child elements and internal classes to get out of sync. In particular, I want to test the internal classes separately from the React component.

Proposal

Currently, the React component is responsible for including the elements which wrap the children.

Is it possible to have the SplitView class take on this responsibility? I suspect the complication is needing access to the child (which would have to be via a direct or indirect ref). But that's what the Pane component is for. Needs some thought.

Acceptance criteria

  • As a library developer I can confirm that the child elements can not get out of sync with the internal classes

Unexpected behavior when passing defaultSizes

Thanks for the great library!

I've just started using it, but it seems like the behavior with defaultSizes is not as it should be.
When passing defaultSizes as defaultSizes={[]} the screen is split into two equal parts. Yet, when passing defaultSizes={[100, 100]} the library adds additional 2 splits, resulting in 4 equally spaced Panes.

Is this the expected behavior or is there a workaround to avoid this issue?
I wanted to keep the current size (obtained from the onChange callback) in the localStorage and initialize the panes from the previous run. Yet, when passing the defaultSizes to the <Allotment>, it creates two additional Panes and eventually crashes.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm @babel/plugin-proposal-class-properties Unavailable
npm @babel/plugin-proposal-private-methods Unavailable
npm @babel/plugin-proposal-private-property-in-object Unavailable
npm xterm Unavailable
npm xterm-addon-fit Unavailable

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency @rollup/plugin-commonjs to v25.0.8
  • chore(deps): update dependency @types/react to v18.3.3
  • chore(deps): update dependency lint-staged to v15.2.7
  • chore(deps): update dependency postcss to v8.4.39
  • fix(deps): update dependency @vscode/codicons to v0.0.36
  • chore(deps): update dependency prettier to v3.3.3
  • chore(deps): update dependency ts-jest to v29.2.3
  • chore(deps): update dependency typescript to v5.5.3
  • chore(deps): update dependency webpack to v5.93.0
  • chore(deps): update dependency @rollup/plugin-commonjs to v26
  • chore(deps): update dependency css-loader to v7
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-plugin-simple-import-sort to v12
  • chore(deps): update dependency storybook-dark-mode to v4
  • chore(deps): update dependency style-loader to v4
  • chore(deps): update storybook monorepo to v8 (major) (@storybook/addon-actions, @storybook/addon-essentials, @storybook/addon-links, @storybook/react, @storybook/react-webpack5, storybook)
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/build.yml
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/release-please.yml
  • google-github-actions/release-please-action v4
npm
package.json
  • classnames ^2.3.0
  • eventemitter3 ^5.0.0
  • lodash.clamp ^4.0.0
  • lodash.debounce ^4.0.0
  • lodash.isequal ^4.5.0
  • use-resize-observer ^9.0.0
  • @babel/core 7.24.4
  • @babel/plugin-proposal-class-properties 7.18.6
  • @babel/plugin-proposal-private-methods 7.18.6
  • @babel/plugin-proposal-private-property-in-object 7.21.11
  • @babel/plugin-transform-runtime 7.24.3
  • @babel/preset-env 7.24.4
  • @babel/preset-react 7.24.1
  • @babel/preset-typescript 7.24.1
  • @rollup/plugin-babel 6.0.4
  • @rollup/plugin-commonjs 25.0.7
  • @rollup/plugin-node-resolve 15.2.3
  • @rollup/plugin-terser 0.4.4
  • @rollup/pluginutils 5.1.0
  • @storybook/addon-actions 7.6.17
  • @storybook/addon-essentials 7.6.17
  • @storybook/addon-links 7.6.17
  • @storybook/react 7.6.17
  • @storybook/react-webpack5 7.6.17
  • @testing-library/dom 9.3.4
  • @types/jest 29.5.12
  • @types/lodash.clamp 4.0.9
  • @types/lodash.debounce 4.0.9
  • @types/lodash.isequal 4.5.8
  • @types/react 18.3.1
  • @types/react-dom 18.3.0
  • @typescript-eslint/parser 6.21.0
  • @vscode/codicons 0.0.35
  • babel-jest 29.7.0
  • babel-loader 9.1.3
  • css-loader 6.10.0
  • eslint 8.57.0
  • eslint-config-prettier 9.1.0
  • eslint-plugin-react-hooks 4.6.2
  • eslint-plugin-simple-import-sort 10.0.0
  • eslint-plugin-storybook 0.8.0
  • husky 8.0.3
  • jest 29.7.0
  • jest-environment-jsdom 29.7.0
  • lint-staged 15.2.2
  • postcss 8.4.38
  • prettier 3.2.5
  • react 18.3.1
  • react-dom 18.3.1
  • rollup 4.9.6
  • rollup-plugin-postcss 4.0.2
  • storybook 7.6.17
  • storybook-dark-mode 3.0.3
  • style-loader 3.3.4
  • ts-jest 29.1.2
  • ts-node 10.9.2
  • typescript 5.4.5
  • webpack 5.91.0
  • xterm 5.1.0
  • xterm-addon-fit 0.7.0
  • react ^17.0.0 || ^18.0.0
  • react-dom ^17.0.0 || ^18.0.0
website/package.json
  • @docusaurus/core 3.1.0
  • @docusaurus/preset-classic 3.1.0
  • @docusaurus/remark-plugin-npm2yarn 3.1.0
  • @mdx-js/react 3.0.1
  • @svgr/webpack 8.1.0
  • @vscode/codicons ^0.0.35
  • allotment ^1.19.4
  • clsx ^2.0.0
  • file-loader 6.2.0
  • prism-react-renderer 1.3.5
  • react 18.3.1
  • react-dom 18.3.1
  • url-loader 4.1.1
  • xterm ^5.0.0
  • xterm-addon-fit 0.6.0
  • @docusaurus/module-type-aliases 3.1.0
  • @docusaurus/tsconfig 3.1.0
  • typescript 5.4.5

  • Check this box to trigger a request for Renovate to run again on this repository

Expose `onChange` event

Purpose

As a developer I want to pass a callback which is called whenever the layout is changed.

Proposal

This one is not fully thought through but is inspired by the onLayout callback exposed by the VS Code implementation as well as the onChange callback exposes by react-split-plane. Part of the solution should be deciding what information to pass to the callback.

Check out https://golden-layout.com/tutorials/saving-state.html for interesting observations.

Acceptance criteria

  • As a developer I can pass a callback which is called when the layout changes

Changing props after mount should have an effect

Purpose

As a developer I expect changing a prop to have an effect, e.g. changing vertical from false to true would change the direction of the split.

Proposal

It's worth checking each prop to see if it's worthwhile supporting. Assuming it is then it might just be a case of re-initialising the internal state appropriately. We can even stand to lose some information, e.g. pane sizes.

A key requirement would be not to cause any child components to remount.

Acceptance criteria

  • As a developer I can change at least one prop and see the change reflected in the rendered component.

Specify initial view sizes

Purpose

As a developer I want to set the initial view sizes so that I can support persisting the layout across component unmounting/mounting.

Proposal

Not obvious what the behaviour should be. Need to keep in mind that the container dimensions could be different so simply specifying absolute pixel values would not work. Could attempt to maintain proportions? Worth checking out how VS Code handles this.

Acceptance criteria

  • As a developer I can specify initial view sizes such that I can recreate an existing layout given the same container dimensions

Changing order of panes should not cause components to remount

This is a placeholder for when I come up with some test cases.

Currently, Allotment relies on the keys of its children to associate them with panes. The index of a pane is decided when it is first added. I think this means that if a pane 'moves' to a different position it won't be reflected in the order of the panes.

Alternatively, if the pane is given a different key, it will appear in the correct position but it will be a new element, i.e. the old component will be unmounted and the new one mounted.

Could not make it work with basic set up

I´ve just created a app using CRA, add the allotment dependency and copy/past the sample

yarn create react-app my-app then yarn add allotment
and changed the src/App.js to:

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

function App() {
  return (
    <Allotment>
      <Allotment.Pane>
        <div>A simple div</div>
      </Allotment.Pane>
      <Allotment.Pane>
        <div>Just a div</div>
      </Allotment.Pane>
    </Allotment>
  );
}

export default App;

I´ve got a blank screen.
When adding the vertical prop (<Allotment vertical>) it renders the divs and a line between it, where I can not interact with.
image

I am using
Microsoft Edge
Version 96.0.1054.53 (Official build) (64-bit)
on Windows 11

SyntaxError: Cannot use import statement outside a module

Hello John,

I'm wanting to try allotment in a new React project but I'm getting the following:

SyntaxError: Cannot use import statement outside a module

At:

allotment (1:0) @ eval

> 1 | module.exports = require("allotment");

Any idea how to solve this issue?

Kind regards,
Marten Mooij

Deploy storybook

Purpose

As a developer I want to see live examples of how to use the component.

Proposal

Automatically deploy main to a suitable domain using Netlify.

Acceptance criteria

  • As a developer I can visit a publicly accessible url to view the storybook examples

Support setting properties on individual views

Purpose

As a developer I expect to be able to set properties such as minimumSize and maximumSize on individual views.

Proposal

Currently, these properties are the same across all views contained in an Allotment component. A solution could be to allow these properties to be set on Allotment.Pane and to make these available somehow to the underlying class.

Acceptance criteria

  • As a developer I can set at least minimumSize and maximumSize on individual views

Write documentation

Purpose

As a developer I want to know how to use the library.

Proposal

Document each of the props and give at least one example.

Acceptance criteria

  • As a developer I can find information on all component props
  • As a developer I can find at least one example of using both components

AllotmentHandle does not have resize function

The doc shows that we can use ref.current.resize([123,344]) however the AllotmentHandle does not have resize function

export declare type AllotmentHandle = {
reset: () => void;
};

Any help?

Create Github action to run tests

Purpose

As a library developer I want to be confident that any changes I make do not break things.

Proposal

Create a Github action to run tests.

Acceptance criteria

  • As a library developer I see the test being run in Github for the main branch and PRs

Document similarities and differences to react-split-pane

Purpose

As a developer I'd like to see how the library compares to a popular alternative.

Proposal

Create an informal page on the documentation website outlining similarities and differences.

Acceptance criteria

  • As a developer I can visit a web page with information on the similarities and differences to react-split-pane

Bundle css with javascript

Purpose

As a developer I don't want to have to remember to import a separate css file.

Proposal

We can bundle the css by setting the postcss extract option to false. The only thing to check is that the library is still usable when included with a script tag.

Acceptance criteria

  • As a developer I can use the library from a script tag
  • As a developer I do not need to import or include a separate css file

Set preferred size for a pane

Purpose

As a developer I would like to set a preferred size for when the user double clicks a sash adjacent to a pane.

Proposal

Let's play with the idea of using defaultSizes purely for setting the sizes on initial mount. The main use case here is for applications to persist the layout.

We can then introduce a concept of preferred size purely for use when resetting the panes' layout.

A good starting point would be to look at the VS Code Grid component.

Screenshot 2022-04-08 at 12 01 46

Acceptance criteria

  • As a developer I can set a preferred size for a pane
  • As a developer when I double clock a sash adjacent to a pane with a preferred size that pane should be set to that size (unless minimum or maximum size conflict)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.