Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fluid-resize-react

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fluid-resize-react

Scale props to fill a container using binary search

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
Maintainers
1
Weekly downloads
 
Created
Source

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 JavaScript Style Guide

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

npm install --save fluid-resize-react

Usage

function App() {
  const renderer = current => (
    <span style={{ fontSize: `${current}px` }}>
      Lorem ipsum dolor sit amet sed adipiscitur sit adipiscitur a very big
      heading that im writing
    </span>
  );

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

  return (
    <div className="App">
      <FixedSize style={{ ...style, width: 500, height: 50 }}>
        {renderer}
      </FixedSize>
      <FixedHeight style={{ ...style, height: 100 }}>{renderer}</FixedHeight>
      <FixedWidth style={{ ...style, width: 500 }}>{renderer}</FixedWidth>
      <FixedWidth style={{ ...style, width: 300 }}>{renderer}</FixedWidth>
      <FixedWidth style={{ ...style, width: 200 }}>{renderer}</FixedWidth>
    </div>
  );
}

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:

function App() {
  const renderer = current => (
    <span style={{ fontSize: `${current}px` }}>Test</span>
  );

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

  return (
    <div className="App">
      <FixedWidth maxSteps={10} min={10} max={12} style={{ ...style }}>
        {renderer}
      </FixedWidth>
    </div>
  );
}

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

function App() {
  const renderer = current => (
    <div style={{ display: "flex" }}>
      {new Array(Math.floor(current)).fill(0).map(_ => (
        <div
          style={{
            margin: 3,
            height: "20px",
            width: "20px",
            backgroundColor: "blue"
          }}
        />
      ))}
    </div>
  );

  return (
    <div className="App">
      <FixedWidth
        min={1}
        max={30}
        style={{
          overflow: "hidden",
          whiteSpace: "nowrap"
        }}
      >
        {renderer}
      </FixedWidth>
    </div>
  );
}

License

MIT © giulioz

Keywords

FAQs

Package last updated on 30 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc