react-adaptive
A Higher Order Component (HOC) allowing you to adapt your component display according to its own size and integrate you website with adaptive design.
Information
Package | react-adaptive |
Description | Element size in react for adaptive design |
Example (basic for now) | https://lokymil.github.io/react-adaptive/ |
Install
npm install --save react-adaptive
Usage
Using withAdaptive HOC
In that case, you have to define a function receiving the size of the component and returning expected component according to your own process.
;; { return <div> My large component thispropsname </div> ; } { return <div> My medium component thispropsname </div> ; } { return <div> My small component thispropsname </div> ; } const mapSizeToComponent = { if sizewidth < 400 return <SmallComponent ...props />; if sizewidth < 700 return <MediumComponent ...props />; return <LargeComponent ...props />;}; mapSizeToComponent ;
Using withBreakpoint HOC
In that case, you have to define a set of breakpoints, up to 7, and a set of associated components. You can define an optionnal default Component.
Breakpoints name :
;; { return <div>My large component componentsname}</div> ; } { return <div>My medium component componentsname}</div> ; } { return <div>My small component componentsname}</div> ; } const components = breakpointslarge: LargeComponent breakpointsmedium: MediumComponent breakpointssmall: SmallComponent; const breakPoints = breakpointslarge: 1000 breakpointsmedium: 700 breakpointssmall: 400; breakPoints components defaultComponent: LargeComponent;
Using withSize HOC
In that case, your component will have an additionnal props as:
size = width: `current component width`
;; const MyComponent = <div>My own size is sizewidth</div>; MyComponent;
License
MIT © Lokymil