Coder Social home page Coder Social logo

react-occamy-text's Introduction

Occamy Text

Occamy is choranaptyxic, meaning it will grow or shrink to fit available space

-- Fantastic Beasts and Where to Find Them

React component for automatically sized text that fits in its parent.

NPM JavaScript Style Guide

Alt text

Demo & Examples

Live demo: splact.github.io/react-occamy-text

To build the examples locally, run:

cd example
npm install
npm start

Installation

npm install --save react-occamy-text

Usage

import * as React from 'react';

import OccamyText from 'react-occamy-text';

class Example extends React.Component {
  render () {
    return <OccamyText>Abra cadabra flipendo, alabif shazam!</OccamyText>;
  }
}

It should not be used inside auto-sized (eg. height: auto) elements.

Properties

  • children – the text that need to be resized
  • grow – true if the text can scale up its original size (default true)
  • shrink – true if the text can scale down its original size (default true)
  • maxFontSize – maximum font size in pixels (default 96)
  • minFontSize – minimum font size in pixels (default 4)
  • maxFontSizeVariation – maximum font size variation per iteration (default 8)
  • minFontSizeVariation – minimum font size variation per iteration (default 0.3)
  • maxHeight – maximum height (default undefined, parent height will be used instead)

Notes

OccamyText is rendered as a div with occamy-text class and height: 100% style defined inline to make it fits in its parent.

Tollerance

The output text will not always perfectly fit the parent height, in some cases a subtile tollerance is accepted, giving always the larger text that doesn't exceed its parent.

Development

To get started, in one tab, run: npm run start And in another tab, run the create-react-app devserver: cd example && npm run start

License

MIT © Splact

react-occamy-text's People

Contributors

splact avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.