npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-essentialrect-editor

v2.0.2

Published

React components for implementing essentialRect image display and editing

Downloads

5

Readme

React EssentialRect Editor

EssentialRectEditor is a React component that allows selection of an essential rectangle, optionally contraining to require letterbox-free display within a range of aspect ratios. EssentialRectEditor uses the react-image-crop module as a dependency.

Also see react-essentialrect

EssentialRect Library on NPM

Editor demo

Table of Contents

  1. What is essentiaRect?
  2. Dependencies
  3. Installation
  4. Usage
  5. Example
  6. Props

What is essentialRect?

EssentialRect is a standard for responsive image display. Rather than cropping an image to a rectangle of a certain aspect ratio, a rectangle (its essentialRect) is defined for an image as "essential". This allows the image to be shown in a wide range of aspect ratios without cropping or leterboxing. The essentialRect will be guaranteed to be displayed, while the rest of the image will be considered "nice to have", and will be used to fill the remaining client area. The essentialRect will be as centered as possible while still avoiding letterboxing.

Dependencies

react-essentialrect

react-image-crop

Installation

npm i react-essentialrect-editor --save

Usage

There is no default export.

import { EssentialRectEditor } from "react-essentialrect-editor";
import "react-essentialrect-editor/dist/essentialrect-editor.css";

Example

import { useState } from "react";
import { EssentialRectEditor } from "react-essentialrect-editor";
import { Rect } from "react-essentialrect";
import "react-image-crop/dist/ReactCrop.css";
import "react-essentialrect-editor/dist/css/essentialrect-editor.css";

const editorSize = 300;

function App(imageUrl) {
  const [essentialRect, setEssentialRect] = useState();

  const onEssentialRectChange = (r: Rect): void => {
    setEssentialRect(r);
  };

  const editorStyles = {
    width: `${editorSize}px`,
    height: `${editorSize}px`,
  };

  return (
    <div className="App">
      <EssentialRectEditor
        style={editorStyles}
        imageUrl={imageUrl}
        essentialRect={essentialRect}
        onEssentialRectChange={onEssentialRectChange}
      />
    </div>
  );
}

Props

imageUrl (required)

The url for the image. Can be any url that <img> accepts.

essentialRect (optional)

A Rect object that defines the essential rectangle for the image. If not provided, it will be set to the rectangle of the entire image, or a centered rectangle that is contrained by minAspectRatio and/or maxAspectRatio.

onEssentialRectChange (optional)

The parent component should maintain the update of the essentialRect in this callback. Without this callback provided, the editor will not function.

minAspectRatio (optional)

Specify that if the aspect ratio of the box the image is displayed in is above minAspectRatio, it should not be letterboxed. This contrains the width of the essentialRect.

maxAspectRatio (optional)

Specify that if the aspect ratio pf the box the image is displayed in is below maxAspectRatio, it should not be letterboxed. This contrains the height of the essentialRect.

onImageError (optional)

Callback if the image fails to load

onImageLoaded (optional)

Callback when the image successfully loads, passing the loaded HTMLImageElement as a parameter.

className (optional)

CSS class to add class to the EssentialRectEditor.

style (optional)

CSSProperties object to add styles to the EssentialRectEditor.