npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-resizable-component

v1.1.0

Published

A simple React resizable component that comes with features that you might need.

Downloads

30

Readme

react-resizable-component

DEMO: http://herlaang.com/resizable.html

GITHUB: https://github.com/wongherlung/react-resizable-component

A simple React resizable component that comes with features that you might need. You can make any other react components resizable by wrapping it into this component or you can just use this component as a resizable div. The main features of this component are as follows:

  • Selectable resizable direction
    • East, South and South-east
  • Resize in steps/intervals
    • Say resize in intervals of 50 pixels
  • Callbacks for important actions
    • onStartResize
    • onDuringResize
    • onStopResize
    • onEachStep
  • Ghost resizing
    • Resizes a transparent absolutely positioned div instead of the original component.
    • To be used in conjunction with onStopResize to achieve something like Microsoft Office Excel's drag down function.

Installation

This module does not need any other dependencies except React and ReactDOM. No jQuery needed.

Simply run:

npm install react-resizable-component --save

Usage

// Simple example shown using ES6
import ResizableBox from 'react-resizable-component';

export default class MyApp extends React.Component {
  render() {
  
    // Custom CSS for ResizableBox
    let customStyles = {
      marginTop: this.state.marginBetBoxes + 'px',
      backgroundColor: 'transparent'
    };
    
    return <div> // NOTE that this parent div should be larger than ResizableBox, if not it can't be resized
      <ResizableBox className="my-custom-class-name" style={customStyles}>
        // A children component is *required*.
        <MyOtherComponent/> // Be sure to give your component 100% height and width for it to be resizable
      </ResizableBox>
    </div>;
  }
}

Docs

IMPORTANT: Before you carry on, you should take note how the resizing is done for this component:

  • Every ResizableBox has to be enclosed in a larger div for resizing to happen.
  • All eventListeners for resizing will be attached to the parent of ResizableBox.

Index

1. Children

A child component must be provided, if not an error would be thrown. If you have no child component, just put it a div with height: 100% and width: 100%. See below:

let style = {
  width: '100%',
  height: '100%'
};

<ResizableBox cssStyles={customStyles}>
  // A children component is *required*.
  <div style={style}>
    My own stuff...
  </div>
</ResizableBox>

2. Props

All props that are passed into ResizableBox are optional.

2.1 height (number)

default: 50

Specifies the height of the component in pixels

<ResizableBox height={50}>
  <div>
    My own stuff...
  </div>
</ResizableBox>

2.2 width (number)

default: 250

Specifies the width of the component in pixels

<ResizableBox width={250}>
  <div>
    My own stuff...
  </div>
</ResizableBox>

2.3 direction ('s' || 'e' || 'se')

default: 's'

Specifies the direction of which the component can extend.

's' -> South / downwards

'e' -> East / rightwards

'se' -> South-east / downwards and rightwards

<ResizableBox direction="se">
  <div>
    My own stuff...
  </div>
</ResizableBox>

2.4 onStartResize (func)

Callback that will be invoked when resizing starts. Width and height of component will be available. See below:

myFunc(width, height) {
  console.log('Width: ' + width);
  console.log('Height: ' + height);
}
...
<ResizableBox onStartResize={this.myFunc}>
  <div>
    My own stuff...
  </div>
</ResizableBox>

2.5 onDuringResize (func)

Callback that will be invoked when the size of the component changes. Width and height of component will be available. See below:

// Note that this will be called only when the component is undergoing resizing and will be called multiple times.
myFunc(width, height) {
  console.log('Width: ' + width);
  console.log('Height: ' + height);
}
...
<ResizableBox onDuringResize={this.myFunc}>
  <div>
    My own stuff...
  </div>
</ResizableBox>

2.6 onStopResize (func)

Callback that will be invoked when resizing is stopped. Resizing only stops on mouseup or when the mouse leaves the parent div. Width and height of component will be available. See below:

myFunc(width, height) {
  console.log('Width: ' + width);
  console.log('Height: ' + height);
}
...
<ResizableBox onStopResize={this.myFunc}>
  <div>
    My own stuff...
  </div>
</ResizableBox>

2.7 onEachStep (func)

Callback that will be invoked on each interval/step only when step is provided. Width and height of component will be available. See below:

// Note that this will be called only when the component is undergoing resizing and will be called multiple times.
myFunc(width, height) {
  console.log('Width: ' + width);
  console.log('Height: ' + height);
}
...
<ResizableBox onEachStep={this.myFunc}>
  <div>
    My own stuff...
  </div>
</ResizableBox>

2.8 options (object)

See below for list of options available:

let myOptions = {
  minHeight: 50, // default is set to initial height of component
  minWidth: 250, // default is set to initial width of component
  maxHeight: 500, // default is set to Infinity
  maxWidth: 500, // default is set to Infinity
  lockAspectRatio: true, // default is set to false; Only works when direction="se"
  
  // Box only resizes at a set interval of pixels
  step: 50, // default is set to 1 (i.e. there is no step)
  
  // Width/Height of handle for resizing, region of component where user can click to start resizing
  cursorMargin: 20, // default is set to 10 pixels
  
  // Ghost resize does not change the size of the component, but only allows you to resize an absolutey positioned semi-transparent
  // div. This is to be used in conjunction with onStopResize and step to achieve something like Microsoft Excel's drag down formula
  // feature.
  allowGhostResize: true, // default is set to false

  // Set ResizableBox to full width to match parent, ignoring any width given
  fullWidth: true // default is set to false
};
...
<ResizableBox options={myOptions}>
  <div>
    My own stuff...
  </div>
</ResizableBox>

2.8.1 style (object)

Custom styling for ResizableBox. Do not change the position, width and height attributes as it might affect the behaviour of this component.

let customStyles = {
  marginTop: this.state.marginBetBoxes + 'px',
  backgroundColor: 'transparent'
};
...
<ResizableBox style={customStyles}>
  <MyOtherComponent/>
</ResizableBox>

2.8.2 className (object)

Custom class name for ResizableBox. Do not change the position, width and height attributes as it might affect the behaviour of this component.

<ResizableBox className="my-custom-class-name">
  <MyOtherComponent/>
</ResizableBox>

2.9 ghostCssStyles (object)

Custom styling for ResizableBox. Do not change the position, width and height attributes as it might affect the behaviour of this component.

let customStyles = {
  marginTop: this.state.marginBetBoxes + 'px',
  backgroundColor: 'transparent'
};
...
<ResizableBox ghostCssStyles={customStyles}>
  <MyOtherComponent/>
</ResizableBox>

License

MIT