1.2.1 • Published 6 months ago

@unparallel/react-sliding-panes v1.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

React Sliding Panes

Sliding pane component used for react, providing the following features:

  • Stack panes in top of each other
  • Open a pane side by side
  • Open a pane in fullscreen mode

Install

npm install @unparallel/react-sliding-panes

Usage

Basic usage example showing all the features

import {Pane, PaneManager, PaneManagerControls, ViewMode} from "@unparallel/react-sliding-panes";
import "@unparallel/react-sliding-panes/dist/main.css";

interface SideContentProps {
    title: string,
    paneManagerControls:PaneManagerControls
}


interface ContentProps {
    title: string,
    paneManagerControls:PaneManagerControls
}


function SideContent({paneManagerControls, title}:SideContentProps){
    const {closeSidePane} = paneManagerControls
    return (
        (
            <div>
                <h1>{title}</h1>
                <button onClick={closeSidePane}>Close</button>
            </div>
        )
    )
}

function Content({title,paneManagerControls}:ContentProps){
    const {setSidePane, closeSidePane,addPane,closeLastPane} = paneManagerControls

    function setSidePaneBtn(){
        setSidePane({content:()=><SideContent title={"Side Content"} paneManagerControls={paneManagerControls} />,shouldClose:()=>confirm("Should close side pane?")})
    }

    function openNewPane(){
        addPane({content:()=><Content title={"Other panes"} paneManagerControls={paneManagerControls} />,shouldClose:()=>confirm("Should close pane?")})
    }

    function openNewPaneAsFullscreen(){
        addPane({content:()=><Content title={"Second Pane as fullscreen"} paneManagerControls={paneManagerControls} />,viewMode:ViewMode.FullScreen,shouldClose:()=>confirm("Should close pane?")})
    }

    return(
        <div>
            <h1>{title}</h1>
            <button onClick={()=>closeLastPane()}>Close Pane</button>
            <button onClick={()=>closeSidePane()}>Close side Pane</button>
            <button onClick={()=>setSidePaneBtn()}>Set side pane</button>
            <button onClick={()=>openNewPane()}>Open new pane</button>
            <button onClick={()=>openNewPaneAsFullscreen()}>Open new pane as fullscreen</button>
        </div>

    )
}

export const Main = function(){

    const pane:Pane = {
        content:((paneManagerControls) =><Content title={"First Pane"}   paneManagerControls={paneManagerControls}/> ),shouldClose:()=>confirm("Should close pane?")
    }


    return (
        <PaneManager>
            {(paneManagerControls)=>(
                <div>
                    <h1>Root Content</h1>
                    <button onClick={()=>{paneManagerControls.addPane(pane)}}>Add first pane</button>
                </div>
            )}
        </PaneManager>
    )
}

PaneManager component

Wrapper component which will provide the "paneManagerControls" object containing methods required to open and close panes

Properties

NameTypeis OptionalDefault ValueDescription
children(paneManagerControls: PaneManagerControls)=>React.ReactNodenoRender of Pane Manager root content, the object "paneManagerControls" is provided and could be used to launch new panes
minPaneDistancenumberyes10Minimum distance (in px) between panes
maxPaneDistancenumberyes200Maximum distance (in px) between panes
paneWidthnumberyes300Width for each pane
timeoutMSnumberyes500Duration of the animation during pane opening, close and adjustment
baseZIndexnumberyes2000Where the z index should start, defining this value could be required ensure that pane manager is rendered as the last layer
paneStartPaddingnumberyes0X position of the first pane
paneClassNamestringyesnullCustom classname for sliding pane container
paneBackgroundClassNamestringyesnullCustom classname for sliding pane background
paneContentClassNamestringyesnullCustom classname for sliding pane content
onPaneClose(index:number)=>voidyesnullEvent fired after closing the pane
paneWillClose(index: number)=>voidyesnullEvent fired before closing a pane
onPaneOpen(index: number, pane:Pane)=>voidyesnullEvent fired after open the pane
onSidePaneOpen(paneIndex: number, sidePane:SidePane)=>voidyesnullEvent fired after opened the side pane

Structures

PaneManagerControls

Object containing several methods to control the behaviour of the Pane manager

NameTypeDescription
addPane(pane:Pane)=>voidUsed to add a new pane
closeLastPane()=>voidClose the last pane
closePane(index: number)=>voidClose a specific pane
setSidePane(sidePane: SidePane)=>voidAdd a side pane to the last pane
closeSidePane()=>voidClose side pane
updateLastPaneProps(props:object)=>voidUpdate props sent to the last pane, this update will re fire a render of the pane content
updateSidePaneProps(props:object)=>voidUpdate props sent to the side pane, this update will re fire a render of the side pane content
compressPanes()=>voidForces all panes to collapses until the meet the "minPaneDistance" regarding its distance
decompressPanes()=>voidSet panes distance to their default distance
getPaneCount()=>number or nullNumber of panes stacked on the pane manager

Pane

Object describing a pane

NameTypeis OptionalDefault ValueDescription
content(paneManagerControls: PaneManagerControls, props: object)=>React.ReactNodenonullContent of the new pane, a "paneManagerControls" object will be sent to the content
viewModeViewModeyesViewMode.DefaultView mode of the new pane, allowed options ViewMode.Default or ViewMode.Fullscreen
shouldClose()=>booleanyes()=>trueConfirmation step before closing the pane
onClose()=>voidyesFired after closing the pane
willClose()=>voidyesFired before closing the pane
propsobjectyesProperties object sent on the content method

SidePane

Object describing a side pane

NameTypeis OptionalDefault ValueDescription
content(paneManagerControls)=>React.ReactNodenonullContent of the new pane, a "paneManagerControls" object is sent to the content
shouldClose()=>booleanyes()=>trueConfirmation step before closing the pane
onClose()=>voidyesFired after closing the side pane
willClose()=>voidyesFired before closing the side pane
propsobjectyesProperties object sent on the content method

Development

npm install
npm start
1.2.1

6 months ago

1.2.0

11 months ago

1.1.0

1 year ago

1.2.0-0

1 year ago

1.0.0

2 years ago

1.0.0-1

2 years ago

1.0.0-0

2 years ago