1.0.0 • Published 5 years ago

react-adaptive-layout v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

react-adaptive-layout

React component that helps to make adaptive layout.

npm version

Install

npm install react-adaptive-layout

or

yarn add react-adaptive-layout

Usage

This is basic example:

import Layout from 'react-adaptive-layout'
...
render(){
    return(
       <Layout>
            {
                ({width}) => {
                    return width < 768
                        ? <img 
                            src="http://placekitten.com/g/300/300" 
                            alt="Wanna some small kitty"/>
                        : <img 
                            src="http://placekitten.com/g/800/600" 
                            alt="Wanna some big kitty"/>
                }
            }
        </Layout>
    )
}

You can provide a prop shouldRender and use it as common component:

<Layout shouldRender={ window.innerWidth > 1280.991 }>
    <p>
        Welcome PC user =)
    </p>
</Layout>

Static methods.

Here are some helper methods and constants.

Layout.breakpoints

Default breakpoints.

NameWidth
xs480
sm576
md990
lg1024
xl1280
xxl1920
Layout.breakpoints.sm => 576

Layout.inRange(value, start, end) => boolean

Check if value between start and end.

ParamTypeDescription
valuenumber
startstring | numberOne of Layout.breakpoints key or a number
endstring | numberOne of Layout.breakpoints key or a number

Example

Layout.inRange(1280, 'sm', 1024) => true

Layout.setBreakPoint(point)

Add or update breakpoints.

ParamTypeDescription
pointObjectObject to merge with break points.

Example

Layout.setBreakPoint({custom: 320, sm: 480})

Layout.isMobile(), Layout.isTablet(), Layout.isDesktop()

Checking screen width.

Layout.isMobile() => true
Layout.isTablet() => false

License

MIT © Dmitriy Dymarchyk