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

resizable-panes-js

Package Overview
Dependencies
Maintainers
0
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resizable-panes-js

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

  • 6.0.26
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-57.14%
Maintainers
0
Weekly downloads
 
Created
Source

The modern library that solve all resizing use cases of a Layout. 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: Best for mobile devices. Resizer can have 0 size pixel.

  • 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-js --save
# or
yarn add resizable-panes-js

Usage

.bg-slate-500 {
  background-color: rgb(100 116 139);
}
import resizablePanes from "resizable-panes-js";

const INTIAL_CONFIG = {
  vertical: true,
  id: 'container',
  resizerSize: 2,
  resizerClass: 'bg-slate-500',
  panes: [
    {
      id: 'P0',
      size: 100
    },
    {
      id: 'P1',
      size: 100
    },
    {
      id: 'P2',
      size: 100
    }
  ]
}

resizablePanes(INITIAL_CONFIG)

    <div id="container" style="height: 200px;" >

        <div id="P0" style="background-color: blue;" > Your HTML/Component </div>

        <div id="resizer-P0">
          Node: Id of resizer should be equals to "resizer-" + id of previous pane.
          You can add your custom element inside it.
        </div>

        <div id="P1" style="background-color: orange;" > Your HTML/Component </div>

        <div id="resizer-P1"></div>
        
        <div id="P2" style="background-color: green;" > Your HTML/Component </div>
    </div>

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

ResizablePanes Options

PropTypeDefaultRequiredDescription
uniqueIdstringtrueHelps identify ResizablePanes container.
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.falseIt sets the unit of minSize and maxSize of panes.
detectionRadiusnumber6falseIt create the extra virtual margin on both side for handle/resizer to detect handle position.
visibilityObjectfalseIt accepts a boolean map of visibility of Pane Ids.
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.
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.
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.
panesIPanetrueIt is an array which hold the properites of all panes. Click here to ream more.

Pane options

PropertyTypeDefaultRequiredDescription
idstringtrueHelps identify Pane component.
sizenumbertrueSets the size of Pane.
maxSizenumberInfinityfalseThe maximum size limit of the Pane.
minSizenumber0falseThe minimum size limit of the Pane.
resizerSizenumberOptionally requiredIt is the size of attached Resizer Element. Works at individual Pane level.
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.

How to access ResizablePanes's api and other methods

import resizablePanes from "resizable-panes-js";

const [resizableApi, refreshResizable, clearResizable] = resizablePanes(config object)

resizableApi - It is explained bellow.
refreshResizable - It reattaches the DOM events.
clearResizable - It clears the DOM events.

ResizablePanes's 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.

Nesting

import resizablePanes from "resizable-panes-js";

const PARENT_CONFIG = {
  vertical: true,
  id: 'container',
  resizerSize: 2,
  resizerClass: 'bg-slate-500',
  panes: [
    {
      id: 'P0',
      size: 100
    },
    {
      id: 'P1',
      size: 100
    },
    {
      id: 'P2',
      size: 100
    }
  ]
}

export const CHILD_CONFIG:IResizableOptions = {
  vertical: false,
  uniqueId: 'uniqueId2',
  resizerSize: 2,
  resizerClass: 'bg-slate-500',
  panes: [
    {
      id: 'P00',
      size: 100
    },
    {
      id: 'P01',
      size: 100
    }
  ]
}

resizablePanes(PARENT_CONFIG)
resizablePanes(CHILD_CONFIG)

    <div id="container" style="height: 200px;" >

        <div id="P0" style="background-color: blue;" >
        
            <div id="uniqueId2">

                <div id="P00" style="background-color: orange;">
                  Your child component 1
                </div>
                   <div id="resizer-P00" > </div>
                <div id="P01" style="background-color: green;">
                  Your child component 2
                </div>
    
              </div>

        </div>

        <div id="resizer-P0"></div>

        <div id="P1" style="background-color: orange;" > Hey two </div>

        <div id="resizer-P1"></div>
        
        <div id="P2" style="background-color: green;" > Hey One </div>
    </div>

How to move Pane by n pixel


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

    const n = 100
    const paneId = 'P2'

    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