Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-aspect-ratio-img

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-aspect-ratio-img

Set Custom Aspect Ratio Image to the Wrap Element(fence)

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

Keywords

FAQs

Package last updated on 21 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc