0.3.1 • Published 6 years ago

react-tailor v0.3.1

Weekly downloads
82
License
MIT
Repository
github
Last release
6 years ago

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.

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago