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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-fitbox

v0.2.7

Published

[![npm version](https://badge.fury.io/js/react-fitbox.svg)](https://badge.fury.io/js/react-fitbox) [![Build Status](https://travis-ci.com/sergioavazquez/fitbox.svg?branch=master)](https://travis-ci.com/sergioavazquez/fitbox) ![MIT](https://badgen.net/badg

Downloads

44

Readme

FitBox

npm version Build Status MIT

FitBox is a scalable box that allows you to absolutely position elements inside it to compose visuals.

Scaling animations, text and visuals can get tricky very fast. Depening on layout design, scaling everything properly is sometimes time-consuming and challenging, specially if the layout was not well thought through.

Live Example Here

Install

npm i react-fitbox

Minimal Configuration

<FitBox ratio={.5} size={256}>
  // place content here.
</FitBox>

This creates a square box of 256px and centers it in the screen. Inside it elements are absolute positioned so you can compose content just as if you where inside an SVG with such viewport size.

Since no container (more on this later) is used, it assumes the entire height and width of the screen are available.

Depending on screen size, FitBox will either scale the box up or down to match the ratio provided. In this example 0.5 or 50%.

By default, FitBox will scale content to fit vertically without boundaries. You can also configure it to fit content horizontally and set up independent scale boundaries for width and height.

Advanced example

<div className='app'>
  <Navigation className="nav" />
  <div ref={containerRef} className="container">
    <FitBox ratio={.5} size={{ w: 500, h: 360 }} fitWidth container={containerRef} >
      <span className="text">500px x 360px</span>
    </FitBox>
  </div>
</div>

<>

IMPORTANT!

This should go without saying but .container element MUST have defined height and width for this to work.

</>

.app{
  height: 100vh;
  width: 100vw;
}

.nav{
  height: 45px;
  width: 100%;
}

.container{
  height: calc(100% - 45px);
  width: 100%;
}

containerRef is a reference to the element we want to use as the outer boundary. In this case, everything but the navigation bar.

const containerRef = useRef();

size is now a rectangle: { w: 500, h: 360 }

ratio is still .5 which means our 500px high box, is going to take half of the screen with any screen size.

Full HD desktop:

1920_1080

Small phone landscape

640_360

In the example above fitWidth is also enabled which means it's not only going to scale vertically but horizontally as well.

If fitting vertically and horizontally at the same time FitBox will always pick the smallest scale.

Small phone portrait

360_640

limitHeight and limitWitdh can have min, max boundaries, one of them or none. The limits are expressed in ratios. Meaning the minimum and maximum ratios that can be assigned to the scalable box.

This is useful, for example, if using a 500px box with a 1000px image on it, max should be 2 at most to avoid image quality loss when up-scaling.

Props

| prop | Type | Default | | --------------- |:------------------------------------:| ---------:| | size | Number or {h:Number w:Number } | 256 | | ratio | Number or {h:Number w:Number } | 0.5 | | fitHeight | bool | false | | fitWidth | bool | true | | limitHeight | {min:Number, max:Number} | 0 - Inf | | limitWidth | {min:Number, max:Number} | 0 - Inf | | container | ref | false | | debug | bool | false |

Want to try it out?

Fitbox

  • git clone
  • yarn install
  • yarn start (demo)