2.1.1 • Published 3 years ago

react-aspect-ratio-img v2.1.1

Weekly downloads
64
License
ISC
Repository
github
Last release
3 years ago

react-aspect-ratio-img

Build Status codecov NPM version

Render HTML img tag with specific aspect ratio with React. for more information, please see: Document

Installation

npm i react-aspect-ratio-img

Components

  • AspectRatioImg (no IE support)

    Use AspectRatioFence as wrap element to set the aspect ratio and pass <img /> element as children props into it.

    propstyperequireddefaultdescription
    outerElementTypestringfalsedivhtml tag name of the wrap component
    rationumbertrue1The aspect ratio of an image describes the proportional relationship between width and height
    classNamestringfalse-Custom class name of the wrap component
    srcstringtrue-The URL of an image
    imgAttributesobjectfalse-The attributes of <img /> tag
    childrenReactNodefalse-Custom children node which as silbing of <img /> tag
  • AspectRatioImgLegacy

    Use AspectRatioFenceLegacy as wrap element to set the aspect ratio and pass <img /> element as children props into it.

    propstyperequireddefaultdescription
    outerElementTypestringfalsedivhtml tag name of the outer component
    innerElementTypestringfalsedivhtml tag name of the inner component
    rationumbertrue1The aspect ratio of an image describes the proportional relationship between width and height
    classNamestringfalse-Custom class name of the wrap component
    srcstringtrue-The URL of an image
    imgAttributesobjectfalse-The attributes of <img /> tag
    childrenReactNodefalse-Custom children node which as silbing of <img /> tag
  • SquareImg

    Use SquareFence as wrap element and pass <img /> element as children props into it.

    propstyperequireddefaultdescription
    outerElementTypestringfalsedivhtml tag name of the wrap component
    classNamebooleanfalse-Custom class name of the wrap component
    srcstringtrue-The URL of an image
    imgAttributesobjectfalse-The attributes of <img /> tag
    childrenReactNodefalse-Custom children node which as silbing of <img /> tag

Way to Ride

  • Common jS
// import from package entry point
const uc = require('react-aspect-ratio-img')
require('react-aspect-ratio-img/css/style.css')

  <uc.AspectRatioImg {...props} />
  <uc.SquareImg {...props} />
// only import specific component
const AspectRatioImg = require('react-aspect-ratio-img/lib/components/AspectRatioImg')
require('react-aspect-ratio-img/css/components/AspectRatioImg/style.css')

  <AspectRatioImg {...props} />
  • ESM
// import from package entry point
import { AspectRatioImg, SquareImg } from 'react-aspect-ratio-img'
import 'react-aspect-ratio-img/css/style.css'

  <AspectRatioImg {...props} />
  <SquareImg {...props} />
// only import specific component
import AspectRatioImg from 'react-aspect-ratio-img/es/components/AspectRatioImg'
import 'react-aspect-ratio-img/css/components/AspectRatio/style.css'

  <AspectRatioImg {...props} />

Development by storybook

npm install
npm start storybook
  • configuration files list in .storybook directory
  • story files list in .stories directory

Test with Jest and Puppeteer

npm run test
  • __tests__
    • unit test running by jest
    • use test:update to update jest snapshot
2.1.1

3 years ago

2.1.0

4 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago