项目作者: cdaz5

项目描述 :
A react library that allows you to place custom resizeable grid components throughout your codebase.
高级语言: TypeScript
项目地址: git://github.com/cdaz5/react-resizeable.git
创建时间: 2020-06-06T11:53:39Z
项目社区:https://github.com/cdaz5/react-resizeable

开源协议:MIT License

下载


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

  1. $ yarn add react-resizeable
  2. // or
  3. $ 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).

  1. import React from 'react';
  2. import { Resizeable, Child } from 'react-resizeable';
  3. const SomeComponent = () => (
  4. <Resizeable height="100vh" as="main">
  5. <Child resize={{
  6. width: '50%',
  7. minWidth: '300px'
  8. resizeable: true,
  9. resizeDir: 'both'
  10. }}>
  11. <p>
  12. Lorem ipsum dolor sit amet, consectetur adipiscing elit
  13. </p>
  14. </Child>
  15. <Child resize={{
  16. as: 'article',
  17. width: '50%',
  18. minWidth: '300px',
  19. height: '450px',
  20. minHeight: '350px'
  21. }}>
  22. <p>
  23. Lorem ipsum dolor sit amet, consectetur adipiscing elit
  24. </p>
  25. </Child>
  26. </Resizeable>
  27. )
  28. export default SomeComponent;

Full API

<Parent ></Parent>

Props:

  1. interface ResizeableProps {
  2. flexDirection?: 'row' | 'column';
  3. height?: string;
  4. as?: keyof JSX.IntrinsicElements;
  5. }

Defaults:

  1. {
  2. flexDirection: 'row',
  3. height: '100%',
  4. as: 'div',
  5. }

<Child ></Child>

Note:

  • <Child ></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:

  1. interface ChildProps {
  2. resize: {
  3. width: string;
  4. resizeDir?: 'none' | 'both' | 'horizontal' | 'vertical' | 'initial' | 'inherit';
  5. resizeable?: boolean;
  6. minWidth?: string;
  7. height?: string;
  8. minHeight?: string;
  9. as?: keyof JSX.IntrinsicElements;
  10. };
  11. }

Defaults:

  1. resize: {
  2. width: 'n/a',
  3. resizeable: false,
  4. resizeDir: 'n/a',
  5. as: 'div',
  6. minWidth: 'min-content',
  7. height: '100%',
  8. minHeight: '100%',
  9. }

License

MIT Licensed

Contributors

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