0.1.22 • Published 7 years ago
@render-props/rect v0.1.22
Rect
A state container which provides an interface for retrieving the bounding
client rect of a referenced element. The bounding client rect will update
each time the window resizes - a behavior which can be turned off by setting
the prop recalcOnWindowResize to false. It doesn't provide values for x and
y, as IE, Edge and Safari don't have them as part of their DOMRect.
Installation
yarn add @render-props/rect or npm i @render-props/rect
Usage
import Rect from '@render-props/rect'
function DivWithRect (props) {
return (
<Rect>
({rectRef, recalcRect, top, right, bottom, left, width, height}) => (
<div ref={rectRef}>
<div>
My width: {width}
</div>
<div>
My height: {height}
</div>
<div>
My position: {JSON.stringify({top, right, bottom, left})}
</div>
</div>
)
</Rect>
)
}Props
recalcOnWindowResize {bool}: iftrue, this component will update itself each time a window resize event is detected. Defaults totrue.withCoords {bool}: iftrue, this component will provide its child function with unpacked arguments for its bounding client rect, i.e.{top, right, bottom, left, width, height}. Iffalse, it will provide a functiongetRectinstead which will return the same object just mentioned. Defaults totrue.
Render Props
Ref
rectRef(element)- This
refmust be provided to whatever element you are trying to receive the bounding client rect for. e.g.<div ref={rectRef}>
- This
Methods
recalcRect- remeasures the element bound to
rectRef
- remeasures the element bound to
getRect- only present if
withCoordsis set tofalse. Returns the bounding client rect object.
- only present if
State
Note: these are only provided if withCoords is true.
top {number}: the top coordinate value of theDOMRectright {number}: the right coordinate value of theDOMRectbottom {number}: the bottom coordinate value of theDOMRectleft {number}: the left coordinate value of theDOMRectwidth {number}: the width of theDOMRectheight {number}: the height of theDOMRect
0.1.22
7 years ago
0.1.21
7 years ago
0.1.20
7 years ago
0.1.19
7 years ago
0.1.18
7 years ago
0.1.17
7 years ago
0.1.16
7 years ago
0.1.15
7 years ago
0.1.14
7 years ago
0.1.13
7 years ago
0.1.12
7 years ago
0.1.11
8 years ago
0.1.10
8 years ago
0.1.9
8 years ago
0.1.8
8 years ago
0.1.7
8 years ago
0.1.6
8 years ago
0.1.5
8 years ago
0.1.4
8 years ago
0.1.3
8 years ago
0.1.2
8 years ago
0.1.1
8 years ago
0.1.0
8 years ago