# extend-react-rnd

> A resizable and draggable and rotate component for React

Latest version **0.1.1** (published 2021-06-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install extend-react-rnd
pnpm add extend-react-rnd
yarn add extend-react-rnd
bun add extend-react-rnd
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2021-06-11 |
| First published | 2021-06-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 265.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | devninja718 |
| Maintainers | devninja718 |
| Keywords | react-rnd, Draggable, Rotatable, Resizable |

## Links

- npm: https://www.npmjs.com/package/extend-react-rnd
- Repository: https://github.com/devninja718/extend-react-rnd
- Homepage: https://github.com/devninja718/extend-react-rnd#readme
- Issues: https://github.com/devninja718/extend-react-rnd/issues
- npm.io page: https://npm.io/package/extend-react-rnd

## Dependencies (3)

- [react-lineto](https://npm.io/package/react-lineto.md) ^3.2.1
- [re-resizable-rotate](https://npm.io/package/re-resizable-rotate.md) 0.0.9
- [react-draggable-rotate](https://npm.io/package/react-draggable-rotate.md) 0.0.21

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2021-06-11
- 0.1.0 — 2021-06-11
- 1.0.0 — 2021-06-10

## README

## Table of Contents

- [Install](#install)
- [Usage](#usage)
- [Props](#props)
- [Callback](#callback)
- [Method](#method)
- [Test](#test)
- [Changelog](#changelog)
- [License](#license)

## Install

- use yarn

```sh
yarn add react-rnd
```

## Usage

### Example with `default`

``` javascript
<Rnd
  default={{
    x: 0,
    y: 0,
    width: 320,
    height: 200,
  }}
>
  Rnd
</Rnd>
```

### Example with `position` and `size`

``` javascript
<Rnd
  size={{ width: this.state.width,  height: this.state.height }}
  position={{ x: this.state.x, y: this.state.y }}
  onDragStop={(e, d) => { this.setState({ x: d.x, y: d.y }) }}
  onResize={(e, direction, ref, delta, position) => {
    this.setState({
      width: ref.offsetWidth,
      height: ref.offsetHeight,
      ...position,
    });
  }}
>
  001
</Rnd>
```

## Props

#### `default: { x: number; y: number;  width?: number | string;  height?: number | string; };`

The `width` and `height` property is used to set the default size of the component.
For example, you can set `300`, `'300px'`, `50%`.     
If omitted, set `'auto'`.

The `x` and `y` property is used to set the default position of the component.   

#### `size?: { width: (number | string), height: (number | string) };`

The `size` property is used to set size of the component.
For example, you can set 300, '300px', 50%.

Use `size` if you need to control size state by yourself.

#### `position?: { x: number, y: number };`

The `position` property is used to set position of the component.
Use `position` if you need to control size state by yourself.

see, following example.    
    
``` javascript
<Rnd
  size={{ width: this.state.width,  height: this.state.height }}
  position={{ x: this.state.x, y: this.state.y }}
  onDragStop={(e, d) => { this.setState({ x: d.x, y: d.y }) }}
  onResize={(e, direction, ref, delta, position) => {
    this.setState({
      width: ref.offsetWidth,
      height: ref.offsetHeight,
      ...position,
    });
  }}
>
  001
</Rnd>
```

#### `className?: string;`

The `className` property is used to set the custom `className` of the component.

#### `style?: { [key: string]: string };`

The `style` property is used to set the custom `style` of the component.

#### `minWidth?: number | string;`

The `minWidth` property is used to set the minimum width of the component.
For example, you can set `300`, `'300px'`, `50%`.  

#### `minHeight?: number | string;`

The `minHeight` property is used to set the minimum height of the component.
For example, you can set `300`, `'300px'`, `50%`.  

#### `maxWidth?: number | string;`

The `maxWidth` property is used to set the maximum width of the component.
For example, you can set `300`, `'300px'`, `50%`.  

#### `maxHeight?: number | string`;

The `maxHeight` property is used to set the maximum height of the component.
For example, you can set `300`, `'300px'`, `50%`.  

#### `z?: number;`

The `z` property is used to set the zIndex of a component.

#### `resizeGrid?: [number, number];`

The `resizeGrid` property is used to specify the increments that resizing should snap to. Defaults to `[1, 1]`.

#### `dragGrid?: [number, number];`

The `dragGrid` property is used to specify the increments that moving should snap to. Defaults to `[1, 1]`.

#### `lockAspectRatio?: boolean;`

The `lockAspectRatio` property is used to lock aspect ratio.
If omitted, set `false`.

#### `dragHandleClassName?: string;`

Specifies a selector to be used as the handle that initiates drag.
Example: '.handle'.

#### `resizeHandleStyles?: HandleStyles;`

The `resizeHandleStyles` property is used to override the style of one or more resize handles.
Only the axis you specify will have its handle style replaced.
If you specify a value for `right` it will completely replace the styles for the `right` resize handle,
but other handle will still use the default styles.

``` javascript

type Style = { [key: string]: string | number };

export type HandleStyles = {
  bottom?: Style,
  bottomLeft?: Style,
  bottomRight?: Style,
  left?: Style,
  right?: Style,
  top?: Style,
  topLeft?: Style,
  topRight?: Style
}
```

#### `resizeHandleClasses?: HandleClasses;`

The `resizeHandleClasses` property is used to set the className of one or more resize handles.

``` javascript
type HandleClasses = {
  bottom?: string;
  bottomLeft?: string;
  bottomRight?: string;
  left?: string;
  right?: string;
  top?: string;
  topLeft?: string;
  topRight?: string;
}
```

#### `resizeHandleWrapperClass?: string;`

The `resizeHandleWrapperClass` property is used to set css class name of resize handle wrapper(`span`) element.

#### `resizeHandleWrapperStyle?: Style;`

The `resizeHandleWrapperStyle` property is used to set css class name of resize handle wrapper(`span`) element.

#### `enableResizing?: ?Enable;`

The `enableResizing` property is used to set the resizable permission of the component.

The permission of `top`, `right`, `bottom`, `left`, `topRight`, `bottomRight`, `bottomLeft`, `topLeft` direction resizing.
If omitted, all resizer are enabled.
If you want to permit only right direction resizing, set `{ top:false, right:true, bottom:false, left:false, topRight:false, bottomRight:false, bottomLeft:false, topLeft:false }`.

``` javascript
export type Enable = {
  bottom?: boolean;
  bottomLeft?: boolean;
  bottomRight?: boolean;
  left?: boolean;
  right?: boolean;
  top?: boolean;
  topLeft?: boolean;
  topRight?: boolean;
}
```

#### `disableDragging?: boolean;`

The `disableDragging` property disables dragging completely.

#### `extendsProps?: { [key: string]: any };`

This property is used to pass the other props to the component.

e.g.

``` javascript
const extendsProps = {
  data-foo: 'foo',
  onMouseOver: () => {},
};

<Rnd extendsProps={extendsProps} />
```

#### `dragAxis?: 'x' | 'y' | 'both' | 'none'`

The direction of allowed movement (dragging) allowed ('x','y','both','none').

#### `bounds?: string;`

Specifies movement boundaries. Accepted values:
 - `parent` restricts movement within the node's offsetParent
    (nearest node with position relative or absolute), or
 - Selector, like `.fooClassName`.

## Callback

#### `onResizeStart?: RndResizeStartCallback;`

`RndResizeStartCallback` type is below.

``` javascript
export type RndResizeStartCallback = (
  e: SyntheticMouseEvent<HTMLDivElement> | SyntheticTouchEvent<HTMLDivElement>,
  dir: ResizeDirection,
  refToElement: React.ElementRef<'div'>,
) => void;
```

Calls when resizable component resize start.

#### `onResize?: RndResizeCallback;`

`RndResizeCallback` type is below.

``` javascript
export type RndResizeCallback = (
  e: MouseEvent | TouchEvent,
  dir: ResizeDirection,
  refToElement: React.ElementRef<'div'>,
  delta: ResizableDelta,
  position: Position,
) => void;
```

Calls when resizable component resizing.

#### `onResizeStop?: RndResizeCallback;`

`RndResizeCallback` type is below.

``` javascript
export type RndResizeCallback = (
  e: MouseEvent | TouchEvent,
  dir: ResizeDirection,
  refToElement: React.ElementRef<'div'>,
  delta: ResizableDelta,
  position: Position,
) => void;
```

Calls when resizable component resize stop.

#### `onDragStart: DraggableEventHandler;`

Callback called on dragging start.

``` javascript
type DraggableData = {
  node: HTMLElement,
  x: number,
  y: number,
  deltaX: number, deltaY: number,
  lastX: number, lastY: number
};

type DraggableEventHandler = (
  e: SyntheticMouseEvent | SyntheticTouchEvent, data: DraggableData,
) => void | false;
```

#### `onDrag: DraggableEventHandler;`

`onDrag` called with the following parameters:

``` javascript
type DraggableData = {
  node: HTMLElement,
  x: number,
  y: number,
  deltaX: number, deltaY: number,
  lastX: number, lastY: number
};

type DraggableEventHandler = (
  e: SyntheticMouseEvent | SyntheticTouchEvent, data: DraggableData,
) => void | false;
```

#### `onDragStop: DraggableEventHandler;`

`onDragStop` called on dragging stop.


``` javascript
type DraggableData = {
  node: HTMLElement,
  x: number,
  y: number,
  deltaX: number, deltaY: number,
  lastX: number, lastY: number
};

type DraggableEventHandler = (
  e: SyntheticMouseEvent | SyntheticTouchEvent, data: DraggableData,
) => void | false;
```

## Method


#### `updateSize(size: { width: string | number, height: string | number })`

Update component size.
For example, you can set `300`, `'300px'`, `50%`.    

- for example

``` js
class YourComponent extends Component {

  ...

  update() {
    this.rnd.updateSize({ width: 200, height: 300 });
  }

  render() {
    return (
      <Rnd ref={c => { this.rnd = c; }} ...rest >
        example
      </Rnd>
    );
  }
  ...
}
```

#### `updatePosition({ x: number, y: number })`

Update component position.
`grid` `bounds` props is ignored, when this method called.

- for example

``` js
class YourComponent extends Component {

  ...

  update() {
    this.rnd.updatePosition({ x: 200, y: 300 });
  }

  render() {
    return (
      <Rnd ref={c => { this.rnd = c; }} ...rest >
        example
      </Rnd>
    );
  }

  ...
}
```  

#### `updateZIndex(z: number)`

Update component z-index.

- for example

``` js
class YourComponent extends Component {

  ...

  update() {
    this.rnd.updateZIndex(200);
  }

  render() {
    return (
      <Rnd ref={c => { this.rnd = c; }} ...rest>
        example
      </Rnd>
    );
  }

  ...
}
```

---
_Source: https://npm.io/package/extend-react-rnd · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
