# react-scaled-props

> Props that scale based on the size of their container

Latest version **0.1.0** (published 2019-03-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-scaled-props
pnpm add react-scaled-props
yarn add react-scaled-props
bun add react-scaled-props
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2019-03-03 |
| First published | 2019-02-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 1 |
| Unpacked size | 20.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | tripphamm |
| Maintainers | tripphamm |
| Keywords | react, responsive, resize, breakpoints, scale |

## Links

- npm: https://www.npmjs.com/package/react-scaled-props
- Repository: https://github.com/tripphamm/react-scaled-props
- npm.io page: https://npm.io/package/react-scaled-props

## Dependencies (1)

- [gh-pages](https://npm.io/package/gh-pages.md) ^2.0.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2019-03-03
- 0.0.8 — 2019-02-02
- 0.0.7 — 2019-02-02
- 0.0.6 — 2019-02-02
- 0.0.5 — 2019-02-02
- 0.0.4 — 2019-02-02
- 0.0.3 — 2019-02-02
- 0.0.2 — 2019-02-01
- 0.0.1 — 2019-02-01

## README

# 📏 react-scaled-props

> Props that scale based on the size of their container

[![NPM](https://img.shields.io/npm/v/react-scaled-props.svg)](https://www.npmjs.com/package/react-scaled-props) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![Build Status](https://travis-ci.org/tripphamm/react-scaled-props.svg?branch=master)](https://travis-ci.org/tripphamm/react-scaled-props)

![scale by height example](https://i.ibb.co/GRL97rZ/react-scaled-props.gif)

[Try it yourself!](https://tripphamm.github.io/react-scaled-props/)

## Install

```bash
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](https://caniuse.com/#feat=resizeobserver).

If your target browsers do not yet support ResizeObserver, you'll need to add a [polyfill](https://www.npmjs.com/package/resize-observer-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:

```tsx
import ResizeObserver from 'resize-observer-polyfill';

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

## Usage / Quickstart

```tsx
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](https://github.com/tripphamm)

---
_Source: https://npm.io/package/react-scaled-props · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
