[go: up one dir, main page]

Skip to content

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

License

Notifications You must be signed in to change notification settings

cdaz5/react-adjustable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-adjustable

Check out the demo.

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

react-adjustable exports two components, Adjustable, 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 auto flex for you!

Requirement

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

Installation

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

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 { Adjustable, Child } from 'react-adjustable';

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

export default SomeComponent;

<Parent />

Props:

interface ParentProps {
  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 {
  adjust: {
    width: string;
    resizeDir?: 'none' | 'both' | 'horizontal' | 'vertical' | 'initial' | 'inherit';
    resizeable?: boolean;
    minWidth?: string;
    height?: string;
    minHeight?: string;
    as?: keyof JSX.IntrinsicElements;
  };
}

Defaults:

  {
    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!

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published