1.3.1 • Published 8 days ago

react-modern-drawer v1.3.1

Weekly downloads
12
License
MIT
Repository
github
Last release
8 days ago

react-modern-drawer

creating drawers made easy!

NPM npm npm npm bundle size (version) npm bundle size (version) NPM

Low bundle size with fantastic performance

Demo 💻🔥

click here to see the demo

Browsers support

IE / EdgeFirefoxChromeSafariiOS SafariSamsungOpera
AllAllAllAllAllAllAll

Install

npm install --save react-modern-drawer

or if you are using yarn :

yarn add react-modern-drawer

Usage

import React from 'react'

// import component 👇
import Drawer from 'react-modern-drawer'

//import styles 👇
import 'react-modern-drawer/dist/index.css'

const App = () => {
    const [isOpen, setIsOpen] = React.useState(false)
    const toggleDrawer = () => {
        setIsOpen((prevState) => !prevState)
    }

    return (
        <>
            <button onClick={toggleDrawer}>Show</button>
            <Drawer
                open={isOpen}
                onClose={toggleDrawer}
                direction='right'
                className='bla bla bla'
            >
                <div>Hello World</div>
            </Drawer>
        </>
    )
}

export default App

API

apityperequireddefaultvaluedesciption
directionstringyes"right""right" , "left" , "top","bottom"Selecting the direction that drawer opens
openbooleanyesfalsetrue , falseSelect when to show drawer
onClosefunctionno( )=>{ }any executable functionThis function is called when clicking on backdrop layer usually used for closing the drawer
sizenumber or stringno250integer or '{integer}px' or '{integer}vw'Determines the size of drawer
styleReact.CSSPropertiesnonullNormal stylingsCan be used for inline styles
durationnumberno300Any positive IntegerDetermines the duration of opening the drawer
overlayOpacitynumberno0.4Number between 0 and 1Determines the opacity of overlay
overlayColorstringno"#000"Any color codeDetermines the color of overlay
enableOverlaybooleannotruetrue , falseDetermines whether to show the overlay
zIndexnumberno100Any positive IntegerDetermines the zIndex of drawer
childrenReact.ReactNodenonullAny ReactNodeThis is the same as props.children
classNamestringnoundefined-normal regular classNames and stuff
overlayClassNamestringnoundefined-normal regular classNames and stuff
customIdSuffixstringnoA random string based on Math.random()-Used for making different ids for drawers, can be customized for special cases.
lockBackgroundScrollbooleannofalse-Locks the body scroll when drawer is open.

Support

If you like this package please consider giving it a star.

Contribution

clone the project and run yarn install then run yarn start to run the main project.

then cd example and run yarn start to start the development example in order to test the component.

any PRs are welcome!

License

MIT © Farzin-Firoozi