0.1.18 • Published 7 years ago
@render-props/image-props v0.1.18
ImageProps
A state container which provides an interface for getting the natural size,
rendered size and orientation from <img> elements.
Installation
yarn add @render-props/image-props or npm i @render-props/image-props
Usage
import ImageProps from '@render-props/image-props'
const ImageWithStats = props => (
<ImageProps>
{
({
orientation,
width,
height,
naturalWidth,
naturalHeight,
complete,
}) => (
<div>
<img src='some-cat-photo.jpg' ref={hoverRef}/>
Loaded? {complete};
Width: {width};
Height: {height};
</div>
)
}
</ImageProps>
)Render Props
Ref
imageRef- This
refmust be provided to whatever element you are trying to observe the the size or orientation of. e.g.<img ref={imageRef}>
- This
State
orientation {landscape|square|portrait}- returns
landscapewhenwidth > height,squarewhenwidth == height, andportraitwhenwidth < height
- returns
width {number}- the rendered width of the image
height {number}- the rendered height of the image
naturalWidth {number}- the actual width of the image
naturalHeight {number}- the actual height of the image
complete {bool}trueif the image loaded successfully
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
7 years ago
0.1.10
7 years ago
0.1.9
7 years ago
0.1.8
7 years ago
0.1.7
7 years ago
0.1.6
7 years ago
0.1.5
7 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