2.0.1 • Published 6 years ago

react-dynamic-font v2.0.1

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

react-dynamic-font Build Status

This is a react component which made your text does not wrap and dynamically adjust the font size

Sometimes we want some text to have a fixed width, and it will automatically reducing the font size when the number of characters is too large, so that the text is always in one line without wrapping. This is why I created this component.

Demo

A simple live demo

Installation

npm install react-dynamic-font --save

or

yarn add react-dynamic-font

This package require react v16.3 or higher, if you want to use at lower react version(v15.x - v16.2.x), try yarn add react-dynamic-font@^1.0.0, for React v0.14 and below, try yarn add react-dynamic-font@^0.0.6

Usage

ReactDynamicFont use the width of its parent element as the fixed width, and remember to add the css style overflow: hidden to its parent element.

import React, { Component } from 'react';
import DynamicFont from 'react-dynamic-font';

class Demo extends Component {
  render() {
    const style = {
      width: 400,
      fontSize: 30,
      lineHeight: 30,
      overflow: 'hidden',
    };
    return (
      <div style={{style}}>
        <DynamicFont content={/* Your text here */} />
      </div>
    );
  }
}

If you want to add smooth animation while font size changing, add the smooth props.

<DynamicFont smooth content={/* Your text here */} />

Have fun!

2.0.1

6 years ago

2.0.0

6 years ago

1.1.0

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.6

7 years ago

0.0.6-alpha.1

7 years ago

0.0.6-alpha-1

7 years ago

0.0.5

7 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago