0.1.18 • Published 5 years ago

@render-props/image-props v0.1.18

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

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 ref must be provided to whatever element you are trying to observe the the size or orientation of. e.g. <img ref={imageRef}>

State

  • orientation {landscape|square|portrait}
    • returns landscape when width > height, square when width == height, and portrait when width < height
  • 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}
    • true if the image loaded successfully
0.1.18

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago