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-scale-text

v1.2.2

Published

A React component for keeping a component's text sized to fill it's container

Downloads

55,061

Readme

React ScaleText Component

NPM Version Coverage Status Build Status Standard Version

ScaleText is a component that allows for dynamically sizing the text within a given component to fit its parent container's width and height. It should work with various positioning and should scale the text smoothly. The scaling of an elements text is done on initial render, and then triggered again from a window resize, which should keep the child element's text scaled to the parent's dimensions.

View demo page.

Installation

Install as npm module and then Use via import or require

npm install --save react-scale-text
import ScaleText from "react-scale-text";

or include the UMD build via script tag from CDN:

<script src="https://unpkg.com/react-scale-text@latest/lib/react-scale-text.js"></script>

or, use the minified version, https://unpkg.com/react-scale-text@latest/lib/react-scale-text.min.js. The UMD build makes the component ScaleText available globally for use in the script.

Usage

ScaleText wraps a single Element. Upon render it will scale the text (font-size) of that element to match the width and height of the parent element (ScaleText's direct parent). Upon resize of the browser window after the intial render, it will ensure the text is always scaled to match the parent container's dimensions.

Example

<div className="parent" style={{ width: "400px", height: "400px" }}>
  <ScaleText>
    <p className="child">Some text</p>
  </ScaleText>
</div>

In the above example, the p elements font-size would be scaled to match the width/height of the the div.parent element that contains it on initial render, and thereafter, on any window resize event. With no minFontSize or maxFontSize props, the text will scale infinitely with the div.parent element as it is resized.

widthOnly Example

<div className="parent" style={{ width: "100%", height: "400px" }}>
  <ScaleText widthOnly={true}>
    <p className="child">Some text</p>
  </ScaleText>
</div>

The above example, using the widthOnly prop tells ScaleText to only scale its child element based on the parent's width, not the height. This essentially turns off overflow checking on height to allow the element to scale to the full width of the container. You can then control the height directly via CSS or other means.

Props

This component takes a single Element as a child to render, which is required.

There are two optional props that can be passed.

  • minFontSize - the minimum font size to scale down to (floor) - default Number.NEGATIVE_INFINITY
  • maxFontSize - the maximum font size to scale up to (ceiling) - default Number.POSITIVE_INFINITY
  • widthOnly - will scale the element based on the width of it's container only, not the height - default false