Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/giulioz/fluid-resize-react

Scale props to fill a container using binary search
https://github.com/giulioz/fluid-resize-react

Last synced: about 1 month ago
JSON representation

Scale props to fill a container using binary search

Awesome Lists containing this project

README

        

# fluid-resize-react

> Provide a simple way to scale props to fill a container using binary search. Useful for scaling text sizes to fit a container.

[![NPM](https://img.shields.io/npm/v/fluid-resize-react.svg)](https://www.npmjs.com/package/fluid-resize-react) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

![](demo.png)

### Components
- **FixedWidth**: Scale down to fit container width
- **FixedHeight**: Scale down to fit container height
- **FixedSize**: Scale down to fit container width and height

## Install

```bash
npm install --save fluid-resize-react
```

## Usage

```jsx
function App() {
const renderer = current => (

Lorem ipsum dolor sit amet sed adipiscitur sit adipiscitur a very big
heading that im writing

);

const style = {
overflow: "hidden",
outline: "1px solid red",
whiteSpace: "nowrap"
};

return (



{renderer}

{renderer}
{renderer}
{renderer}
{renderer}

);
}
```

Pass a render function to a component as child. The component will call the render function passing the current iteration size as parameter.

You can also provide max value, min value and max iterations as props:

```jsx
function App() {
const renderer = current => (
Test
);

const style = {
overflow: "hidden",
whiteSpace: "nowrap"
};

return (



{renderer}


);
}
```

This components can be used for text as well for any other usages:

```jsx
function App() {
const renderer = current => (


{new Array(Math.floor(current)).fill(0).map(_ => (

))}

);

return (



{renderer}


);
}
```

## License

MIT © [giulioz](https://github.com/giulioz)