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

react-resizable-layout

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

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.

  • 0.7.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.6K
increased by23.23%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 21 Oct 2023

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