johnwalley / allotment

A React component for resizable split views
https://allotment.mulberryhousesoftware.com/
MIT License
949 stars 52 forks source link

Persist resize pane width on reload (Feature request) #795

Open abhishekmg opened 5 months ago

abhishekmg commented 5 months ago

When the changes the width of a pane and then refreshes the changes width needs to persist

current behaviour

https://github.com/johnwalley/allotment/assets/34393560/1820c05d-8c58-411c-9776-fb59bc3182ba

vimalsharma124 commented 4 months ago

I'm searching similar

vimalsharma124 commented 4 months ago

Found it https://www.npmjs.com/package/resizable-panes-react

AruhaMaeda commented 3 months ago

You can achieve it using local storage.

Here is the sample code.

import { Allotment } from "allotment"

const LOCAL_STORAGE_KEY = "splitSizes"
let initialSizes = [500, 500, 500]
if (typeof window !== "undefined") {
  const savedSizes = localStorage.getItem(LOCAL_STORAGE_KEY)
  if (savedSizes) {
    initialSizes = JSON.parse(savedSizes)
  }
}

function Test() {
  return (
    <>
      <Allotment
        defaultSizes={initialSizes}
        onDragEnd={(sizes) => {
          if (typeof window !== "undefined") {
            localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(sizes))
          }
        }}
      >
        <div>First</div>
        <div>Second</div>
        <div>Third</div>
      </Allotment>
    </>
  )
}
export default Test