Socket
Socket
Sign inDemoInstall

react-resizable-layout

Package Overview
Dependencies
5
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-resizable-layout

Lightweight, accessible headless React component and hook for drag-and-drop resizable layouts.


Version published
Weekly downloads
3.3K
increased by9.54%
Maintainers
1
Install size
25.9 kB
Created
Weekly downloads
 

Readme

Source

react-resizable-layout

npm version MIT License minziggped size dependencies count tree shaking

A lightweight, accessible headless React component and hook for drag-and-drop resizable layouts.

Hero Image

Edit react-resizable-layout

Storybook Demo

Features

  • 📦 Lightweight
  • 🕳 Headless
  • 🫶🏽 Accessible
  • 🤏 Drag and Drop Support
  • ⌨️ Keyboard Support
  • 🫙 Zero Dependencies

Installation

Install from npm:

# Using npm
npm install react-resizable-layout

# Using Yarn
yarn add react-resizable-layout

Usage

Resizable component

import Resizable from 'react-resizable-layout';

<Resizable axis={'x'}>
  {({ position, separatorProps }) => (
    <div className="wrapper">
      <div className="left-block" style={{ width: position }} />
      <YourSeparatorComponent {...separatorProps} />
      <div className="right-block" />
    </div>
  )}
</Resizable>

useResizable hook

import { useResizable } from 'react-resizable-layout';

const Component = () => {
  const { position, separatorProps } = useResizable({
    axis: 'x',
  })

  return (
    <div className="wrapper">
      <div className="left-block" style={{ width: position }} />
      <YourSeparatorComponent {...separatorProps} />
      <div className="right-block" />
    </div>
  )
}

Aria Props

The following attributes are added to separatorProps in accordance with W3C.
https://www.w3.org/TR/wai-aria-1.2/#separator

AttributeValue
role'separator'
aria-valuenowposition
aria-valueminprops.min
aria-valuemaxprops.max
aria-orientation'vertical' or 'horizontal'
aria-disabledprops.disabled

Configuration

Common Props

NameTypeDefaultRequiredDescription
axis'x' or 'y'-Resize direction
containerRefReactRef--Reference to container for calculating position
disabledbooleanfalse-Disable resize
initialnumber0-Initial size
minnumber0-Minimum size
maxnumberInfinity-Maximum size
reversebooleanfalse-If true, returns position of the opposite side
stepnumber10-Pixel steps when operating with keyboard
shiftStepnumber50-Pixel steps when operating with keyboard while holding down the shift key
onResizeStartfunction--Callback on resize start
onResizeEndfunction--Callback on resize end

Resizable component children args

useResizable hook returns same.

NameTypeDescription
positionnumberSeparator's position (Width for 'x' axis, height for 'y' axis)
endPositionnumberSeparator's position at end of drag
isDraggingbooleanTrue if dragging
separatorPropsobjectSeparator's props like onPointerDown
setPositionfunctionSet separator's position

About keyboard support

The following keyboard operations are supported.

KeyOperation
Arrow (,,,)Move the separator by 10px (default)
Shift + Arrow (,,,)Move the separator by 50px (default)
EnterReset the separator to the initial position

About mouse support

Double-click on the separator to return it to its initial position.

Contribution

Feel free to open an issue or make a pull request.

License

Distributed under the MIT License. See LICENSE for more information.

Keywords

FAQs

Last updated on 21 Oct 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc