Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

resizable-panes-react

Package Overview
Dependencies
Maintainers
0
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resizable-panes-react

A straightforward library that enables dynamic resizing of layouts and saves the layout configurations.

  • 6.0.26
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

The modern library that solve all resizing use cases. Don't trust! Try it

resizable-panes-react nycrc config on GitHub NPM Version npm bundle size Quality Gate Status

Quick Demo!

Key Features

  • Smooth Resizing: Enjoy smooth and fast pane resizing without performance issues.

  • No Unnecessary Rerenders: Child components in the panes won't rerender during resizing, ensuring a seamless experience.

  • Show and Hide Panes: Easily show and hide panes, considering the minimum and maximum size constraints of other panes.

  • Custom Resizers: Customize resizer handles to match your app's design.

  • Unique Resizers: Single Resizer handle can push and pull n number of Panes in forward and backword direction.

  • Responsive: In ratio mode, It adjusts pane sizes responsively to fit in available space, making it perfect for dynamic layouts.

  • Auto-Save Sizes: Pane size and visibility are automatically saved in the browser's memory for consistent layouts across sessions.

Installation

npm i resizable-panes-react --save
# or
yarn add resizable-panes-react

Usage

.bg-slate-500 {
  background-color: rgb(100 116 139);
}
import { Pane, ResizablePanes } from "resizable-panes-react";

function App() {
  return (
    <div
      style={{
        height: "300px",
      }}
    >
      <ResizablePanes uniqueId="uniqueId" vertical resizerClass="bg-slate-500">
        <Pane id="P0" size={1}>
          Your component 1
        </Pane>
        <Pane id="P1" size={2}>
          Your component 2
        </Pane>
        <Pane id="P2" size={3}>
          Your component 3
        </Pane>
      </ResizablePanes>
    </div>
  );
}

👋 Hi there! If you find this project useful or valuable do give it star on GitHub or Buy Me a Coffee

ResizablePanes Props

PropTypeDefaultRequiredDescription
uniqueIdstringtrueHelps identify ResizablePanes component.
unmountOnHidebooleantruefalsetrue - Unmounts the child or children of Pane in Hidden state.
false - keeps the child or children of Pane in DOM in Hidden state.
classNamestringfalseIt will get attached to ResizablePanes container element.
verticalbooleanfalsefalseIt sets the orientation of Panes.
unit'ratio' or 'pixel'ratiofalseIt sets the unit of size of panes.
minMaxUnit'ratio' or 'pixel'Same value as of unit propsfalseIt sets the unit of minSize and maxSize of panes.
detectionRadiusnumber6falseIt create the extra margin on both side for handle/resizer detection.
visibilityObjectfalseIt accepts a boolean map of Pane Ids visibility.
storageApiObjectfalseIt used to store data across session. It can be localStorage, sessionStorage or any other following the interface of localStorage.
resizerClassstringfalseIt gets applied to the main resizer element in normal state.
activeResizerClassstringfalseIt gets applied to the main resizer element in active state.
resizerReactElementfalseIt will replace the in build resizer.
resizerSizenumber2optionally requiredIt is the size of resizer. If the size of resizer is other than 2px you will have to provide the value.
onResizefunctionfalseIt emits size map while resizing layout.
onResizeStopfunctionfalseIt emits size map after the layout resizing is complete.
onReadyfunctionfalseIt emits ResizablePanes component's api once it is constructed.
onChangeVisibilityfunctionfalseIt emits visibility map when there is change in visibility. A Pane can have 'visible', 'hidden' or 'zipped' state.
onMinSize(id: string, minSize:number) => voidfalseIt emits when a Pane enters min size.
onMaxSize(id: string, maxSize:number) => voidfalseIt emits when a Pane enters max size.
onNormalSize(id: string) => voidfalseIt emits when a Pane enters normal size.

Pane Props

PropTypeDefaultRequiredDescription
idstringtrueHelps identify Pane component.
sizenumbertrueSets the size of Pane.
unmountOnHidebooleanSame behaviour as of ResizablePanes Prop but works for individual Pane.
classNamestringfalseIt will get attached to Pane element.
maxSizenumberInfinityfalseThe maximum size limit of the Pane.
minSizenumber0falseThe minimum size limit of the Pane.
resizerReactElementfalseIt will replace the in build resizer of Pane.
resizerSizenumberOptionally requiredIt is the size of attached Resizer Element. It is required when we have passed resizer prop to the Pane.
detectionRadiusnumber6falseWorks at individual Pane level.
onMinSize(id: string, minSize:number) => voidfalseIt emits when it enters min size of the Pane.
onMaxSize(id: string, maxSize:number) => voidfalseIt emits when it enters max size of the Pane.
onNormalSize(id: string) => voidfalseIt emits when it enters normal size of the Pane.

ResizablePanes component api

MethodParamsDescription
restoreIt restores the default view of layout.
setSize(paneId: string, size: number,
behaviour: ISetSizeBehaviour)
It excepts the positive number. It sets the size of Pane depending upon:
1. Its min and max.
2. Min and max of other panes.
setSizeRatio(paneId: string, size: number,
behaviour: ISetSizeBehaviour)
Pass value 0 to 1. It will automatically covert it percent in Pixel.
1 corresponds to the sum of size of visible Panes.
setVisibilitiesObjectIt sets the visibility of Panes using the Boolean map of id of Panes.
getSizesIt returns the size map object of Ids of Panes
getVisibilitiesIt returns the visibility map object of Ids of Panes
getStateIt return the current state of all Panes.

Custom Resizer Component (resizer prop of ResizablePanes/Pane)

PropTypeDefaultRequiredDescription
isMouseDownbooleanUse it style you Custom resizer element behavior.

interface ICustomResizerProp {
    isMouseDown: boolean,
  }


export const CustomResizer = ({
    isMouseDown
}: ICustomResizerProp) => {

 // isMouseDown: use it to style the elements

  return (
    <SOME_ELEMENT>
      <TARGET_ELEMENT>

      </TARGET_ELEMENT>
    </SOME_ELEMENT>
  )
}

Nesting


      <ResizablePanes uniqueId="uniqueId" vertical resizerClass="bg-slate-500">

      <Pane id="P0" size={1}>    
          <ResizablePanes uniqueId="uniqueId2" resizerClass="bg-slate-500">

            <Pane id="P01" size={2}>
              Your child component 1
            </Pane>
            <Pane id="P01" size={3}>
              Your child component 2
            </Pane>

          </ResizablePanes>
      </Pane>

        <Pane id="P1" size={2}>
          Your component 2
        </Pane>
        <Pane id="P2" size={3}>
          Your component 3
        </Pane>
      </ResizablePanes>

How to move Pane by n pixel


import {RATIO, BUTTOM_FIRST, TOP_FIRST} from 'resizable-panes-react'

    const n = 100
    const paneId = 'P2'

    // resizableApi: Emitted by onReady event 
    const currentP2Size = resizableApi.getSizes()[paneId]
    resizableApi.setSize(paneId, currentP2Size - n, TOP_FIRST)

    const nowP2Size = resizableApi.getSizes()[paneId]
    resizableApi.setSize(P2, nowP2Size + n, BUTTOM_FIRST)

Quick Demo

Feel Free to Raise Pull Request

Keywords

FAQs

Package last updated on 14 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc