Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🐙 An intuitive React component set for multi-column resizing

License

NotificationsYou must be signed in to change notification settings

LeetCode-OpenSource/react-simple-resizer

Repository files navigation

An intuitive React component set for multi-column(row) resizing. You couldcustomize the behavior of resizing in a very simple way. Works in every modern browserwhich supportsflexible box layout.

Table of Contents

Installation

Usingyarn:

yarn add react-simple-resizer

Or vianpm:

npm install react-simple-resizer

Examples

Here is a minimal example for two-column layout:

importReactfrom'react';import{Container,Section,Bar}from'react-simple-resizer';exportdefault()=>(<Containerstyle={{height:'500px'}}><Sectionstyle={{background:'#d3d3d3'}}minSize={100}/><Barsize={10}style={{background:'#888888',cursor:'col-resize'}}/><Sectionstyle={{background:'#d3d3d3'}}minSize={100}/></Container>);

We have created several demos on CodeSandbox, check demos below:

Components

<Container />

Literally, it's the container of the other components.

import{Container}from'react-simple-resizer';

Props

import{HTMLAttributes}from'react';interfaceContainerPropsextendsHTMLAttributes<HTMLDivElement>{vertical?:boolean;onActivate?:()=>void;beforeApplyResizer?:(resizer:Resizer)=>void;afterResizing?:()=>void;}
vertical

Determine whether using vertical layout or not, default isfalse.

onActivate

Triggered when anyBar is activated. i.e,onMouseDown oronTouchStart.

beforeApplyResizer

Used tocustomize resize behavior. In this method, youdon't need to callapplyResizer to apply the resize result. Please note that you should not do any side effect on this method. If you want to do something after resizing, seeafterResizing below.

afterResizing

Triggered after aresizing section is completed, which means that it will be triggered afteronMouseUp andonTouchEnd events. If you want to do something after size of section has changed, useonSizeChanged props on theSection instead.

Instance properties

importReactfrom'react';classContainerextendsReact.PureComponent<ContainerProps>{publicgetResizer():ResizerpublicapplyResizer(resizer:Resizer):void}
getResizer

Used to get newestResizer. But any change won't apply unless you pass theResizer toapplyResizer.

applyResizer

Apply the passedResizer toContainer.


<Section />

import{Section}from'react-simple-resizer';

Props

import{HTMLAttributes,RefObject}from'react';interfaceSectionPropsextendsHTMLAttributes<HTMLDivElement>{size?:number;defaultSize?:number;maxSize?:number;minSize?:number;disableResponsive?:boolean;onSizeChanged?:(currentSize:number)=>void;innerRef?:RefObject<HTMLDivElement>;}
size

Used to setSection's size. Ifsize is set,Section will ignore the value ofdefaultSize,maxSize andminSize.

defaultSize

Used to set default size ofSection.

maxSize

Used to set max size ofSection.

minSize

Used to set min size ofSection.

disableResponsive

EachSection is responsive as default, unlesssize exists. Theresponsive here means thatSection's size is related withContainer's size, ifContainer's size turn smaller, theSection's size also turn smaller automatically. Otherwise, changes ofContainer size won't affect theSection whendisableResponsive istrue.

onSizeChanged

Will be triggered each time its size has changed.

innerRef

Used to get the actual DOM ref ofSection.


<Bar />

import{Bar}from'react-simple-resizer';

Props

import{HTMLAttributes,RefObject}from'react';interfaceExpandInteractiveArea{top?:number;left?:number;right?:number;bottom?:number;}interfaceBarPropsextendsHTMLAttributes<HTMLDivElement>{size:number;expandInteractiveArea?:ExpandInteractiveArea;onStatusChanged?:(isActive:boolean)=>void;onClick?:()=>void;innerRef?:RefObject<HTMLDivElement>;}
size

Required, used to set the size ofBar.

expandInteractiveArea

Used to expand interactive area ofBar.

onStatusChanged

Triggered when the state ofBar has changed.

onClick

Triggered if there's no "move" events. The main difference between it and originalonClick event is thatthere is no parameters onthisonClick. You could also use it as a touch event on mobile platform, without 300ms click delay.

innerRef

Used to get the actual DOM ref ofBar.

Customize resize behavior

If you want to customize behavior of resizing, then you have to know how to useResizer.

There is two ways to get theResizer. One isbeforeApplyResizer defined on theprops ofContainer, and the other isgetResizer defined on theinstance ofContainer.

Beware that you needmanually callingapplyResizer every time you want to apply the effect, except inbeforeApplyResizer. Check demoMake Section collapsible to see howapplyResizer is used.

interfaceResizer{resizeSection:(indexOfSection:number,config:{toSize:number;preferMoveLeftBar?:boolean})=>void;moveBar:(indexOfBar:number,config:{withOffset:number;})=>void;discard:()=>void;isSectionResized:(indexOfSection:number)=>boolean;isBarActivated:(indexOfBar:number)=>boolean;getSectionSize:(indexOfSection:number)=>number|-1;getTotalSize:()=>number;}
resizeSection

Used to set size of the nthSection.In multi-column layout, there're severalBars could change theSection's size. Therefore, you could try to use the left sideBar to resizing by settingpreferMoveLeftBar.

moveBar

Used to move the nthBar to resizing.If the value of A is negative, moveBar to the left. Whenvertical istrue, move up.

discard

Discard resizing at this time.

isSectionResized

Used to determine whether the nthSection's size is changed at currentresizing section or not.

isBarActivated

Used to determine whether the nthBar is active or not.

getSectionSize

Used to get size of the nthSection. if there is no nthSection, return-1.

getTotalSize

Used to get total size of allSection.

Contributing

The main purpose of this repository is to continue to evolve react-simple-resizer, making it faster, smaller and easier to use. We are grateful to the community for contributing bugfixes and improvements.

About Demo

Feel free to let us know that you have created some new customized resize behavior. You could create a PR to let more people see your works. Also, if you find some behaviors that you cannot create, let us know too.

About

🐙 An intuitive React component set for multi-column resizing

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp