Git Product home page Git Product logo

cdaz5 / react-resizeable Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 476 KB

A react library that allows you to place custom resizeable grid components throughout your codebase.

Home Page: https://codesandbox.io/s/react-resizeable-examples-vsdcj?file=/src/app.js

License: MIT License

HTML 3.17% TypeScript 96.83%
react grid resize resizeable resize-events resizer resizeableview responsive-layout responsive-grid

react-resizeable's Introduction

react-resizeable

Check out the demo.

A react library that allows you to place custom resizeable grid components throughout your codebase.

react-resizeable exports two components, Resizeable, the parent container and, Child, the wrapper for any children. See demo for examples.

Features

⏳ Saves you time by handling all the annoying event listeners for you.

⭐️ Flexibility to use proper semantic HTML (both components accept an as prop!)

🐑 Simplicity -- no need to pass multiple breakpoints, if each child has a minWidth we'll handle the wrap for you!

Requirement

To use react-resizeable, you must use styled-component > 4.1 as it is a peer dependency.

Installation

$ yarn add react-resizeable
// or
$ npm i react-resizeable

Example

NOTE: most arguments are provided defaults (see Full API below) with the only required one being width on the <Child> component, however it is strongly recommended to include minWidth as well. (see demo for additional examples).

import React from 'react';
import { Resizeable, Child } from 'react-resizeable';

const SomeComponent = () => (
    <Resizeable height="100vh" as="main">
      <Child resize={{
        width: '50%',
        minWidth: '300px'
        resizeable: true,
        resizeDir: 'both'
      }}>
        <p>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit
        </p>
      </Child>
      <Child resize={{
        as: 'article',
        width: '50%',
        minWidth: '300px',
        height: '450px',
        minHeight: '350px'
      }}>
        <p>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit
        </p>
      </Child>
    </Resizeable>
)

export default SomeComponent;

<Parent />

Props:

interface ResizeableProps {
  flexDirection?: 'row' | 'column';
  height?: string;
  as?: keyof JSX.IntrinsicElements;
}

Defaults:

 {
   flexDirection: 'row',
   height: '100%',
   as: 'div',
 }

<Child />

Note:

  • <Child /> includes a forwardRef wrapper, so feel free to pass it a ref if need be.
  • all additional props passed to child are forwarded to the styled component so you could pass a style prop to override things if you were so inclined.

Props:

interface ChildProps {
  resize: {
    width: string;
    resizeDir?: 'none' | 'both' | 'horizontal' | 'vertical' | 'initial' | 'inherit';
    resizeable?: boolean;
    minWidth?: string;
    height?: string;
    minHeight?: string;
    as?: keyof JSX.IntrinsicElements;
  };
}

Defaults:

  resize: {
    width: 'n/a',
    resizeable: false,
    resizeDir: 'n/a',
    as: 'div',
    minWidth: 'min-content',
    height: '100%',
    minHeight: '100%',
  }

License

MIT Licensed

Contributors

This project follows the all-contributors specification. Contributions of any kind welcome!

react-resizeable's People

Contributors

cdaz5 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.