0.1.0 • Published 5 years ago

react-scaled-props v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

📏 react-scaled-props

Props that scale based on the size of their container

NPM code style: prettier Build Status

scale by height example

Try it yourself!

Install

npm install --save react-scaled-props

ResizeObserver

In order to efficiently observe changes to an element's size, we make use of ResizeObserver which is not fully implemented by every browser.

If your target browsers do not yet support ResizeObserver, you'll need to add a polyfill to your app in order to use 📏 react-scaled-props.

tl;dr - if you want cross-browser support, you probably need to do something like this:

import ResizeObserver from 'resize-observer-polyfill';

if (window.ResizeObserver === undefined) {
  window.ResizeObserver = ResizeObserver;
}

Usage / Quickstart

function App() {
  const boxRef = useRef(null);
  const fontSize = useScaledProp(boxRef, {
    // 'height' or 'width'
    dimension: 'width',
    // width where our fontSize will reach its minPropValue
    minDimensionValue: 200,
    // width where our fontSize will reach its maxPropValue
    maxDimensionValue: 600,
    // min fontSize value
    minPropValue: 12,
    // max fontSize value
    maxPropValue: 36,
  });

  return (
    <div ref={boxRef}>
      <p style={{ fontSize }}>I grow and shrink!</p>
    </div>
  );
}

License

MIT © tripphamm

0.1.0

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago