0.7.2 β€’ Published 7 months ago

react-resizable-layout v0.7.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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.

0.7.2

7 months ago

0.7.1

8 months ago

0.7.0

8 months ago

0.6.0

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.0

2 years ago

0.3.0

2 years ago

0.3.1

2 years ago

0.2.1

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.4

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago