react-object-fit-container
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

"object-fit: cover" polyfill for react

Image or Video takes 100% height and width of container;

Install

yarn add react-object-fit-container 
npm install react-object-fit-container

Usage

import { Image, Video } from "react-object-fit-container";
 
render() {
  const {  
    verticalAlign, // unnecessary attribute, vertilcalAlign can be: 'top' or 'bottom', default is 'center'
    horizontalAlign, // unnecessary attribute, horizontalAlign can be: 'left' or 'right', default is 'center'
    data 
  } = this.props; 
 
  return (
    <Image src={data.image} verticalAlign={verticalAlign} horizontalAlign={horizontalAlign}/>
  )
}

You can manually use ObjectFitWrapper just take ratio from child image/video and set to ObjecFitWrapper's prop ratio:

import { ObjectFitWrapper } from "react-object-fit-container";
 
render() {
  const { ratio } = this.state; 
  const {  
    verticalAlign, // unnecessary attribute, vertilcalAlign can be: 'top' or 'bottom', default is 'center'
    horizontalAlign, // unnecessary attribute, horizontalAlign can be: 'left' or 'right', default is 'center'
    data 
  } = this.props; 
 
  return (
    <ObjectFitWrapper ratio={ratio} verticalAlign={verticalAlign} horizontalAlign={horizontalAlign}>
      <img src={data.image} />
    </ObjectFitWrapper>
  )
}

Readme

Keywords

none

Package Sidebar

Install

npm i react-object-fit-container

Weekly Downloads

1

Version

1.0.8

License

MIT

Unpacked Size

13.6 kB

Total Files

10

Last publish

Collaborators

  • arzamax