New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-tailor

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-tailor

Adjust text size to fit its container.

  • 0.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
Maintainers
1
Weekly downloads
 
Created
Source

React Tailor ✂️

npm version Dependency Status

demo

Tailor adjusts the size of text within its children to try and fit it within the available horizontal and vertical space.

Currently tailor only works (and enforces) a single line of non-wrapping text. This might change in the future, but there are also other solution that work with multiple lines of text (see Similar Projects below).

Uses React Measure to resize an element only if its size changes.

Install

yarn add react-tailor

Tailor Component

Wrap any child component and calculate its client rect.

Props

canGrow: boolean

default: false

Can the text size up above its initial size?

minSize: number

default: 11

The minimum size (in px) that text will be sized down to fit. Once text has reached this size and ellipsis will be added to any text cut off.

Example

import Tailor from 'react-tailor'

class Tailor extends Component {
  render() {
    return (
      <div>
        <h1>
          <Tailor>Title Text</Tailor>
        </h1>
        <ul>
          <li>
            <Tailor>List Item</Tailor>
          </li>
          <li>
            <Tailor>List Item 2</Tailor>
          </li>
        </ul>
      </div>
    )
  }
}

Running the demo locally

  1. clone repo

    git clone git@github.com:chrisdrackett/react-tailor.git

  2. install dependencies

    yarn

  3. run dev mode

    yarn start

  4. open your browser and visit: http://localhost:3000/

Similar Projects

  • React FitText

    similar, but resizes all elements on browser resize even if their parent is the same size. Does not calculate best size automatically.

  • React TextFit

    Supports paragraphs but is heavier.

Keywords

FAQs

Package last updated on 26 Apr 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