All Projects → datchley → react-scale-text

datchley / react-scale-text

Licence: MIT license
A React library to keep an element's text scaled to fit it's container

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-scale-text

vscode-exts
Visual Studio Code Extensions
Stars: ✭ 33 (-15.38%)
Mutual labels:  react-component
Temps
λ A selfhostable serverless function runtime. Inspired by zeit now.
Stars: ✭ 15 (-61.54%)
Mutual labels:  scale
react-ignore-rerender
🚀 Simple component for ignoring the re-rendering of a piece of React's render method.
Stars: ✭ 28 (-28.21%)
Mutual labels:  react-component
react-mason
React Masonry grid
Stars: ✭ 13 (-66.67%)
Mutual labels:  react-component
react-timer-wrapper
Composable React Timer component that passes status props to children, in addition to some basic callbacks. Can be used at a countdown timer ⏲ or as stopwatch ⏱ to track time while active.
Stars: ✭ 14 (-64.1%)
Mutual labels:  react-component
git-issue-react-electronjs
⚙️. ⚛️. A desktop application created with Electronjs and Reactjs to be cross-platform to manage and track GitHub issues.
Stars: ✭ 21 (-46.15%)
Mutual labels:  react-component
react-native-tabbar
A tabbar component for React Native
Stars: ✭ 59 (+51.28%)
Mutual labels:  react-component
Flutter-KenBurns
Kenburns effect on flutter
Stars: ✭ 82 (+110.26%)
Mutual labels:  scale
react-dates
An easily internationalizable, mobile-friendly datepicker library for the web
Stars: ✭ 12,032 (+30751.28%)
Mutual labels:  react-component
react-tags-input
[Not Actively Maintained] An input control that handles tags interaction with copy-paste and custom type support.
Stars: ✭ 26 (-33.33%)
Mutual labels:  react-component
react-scroll-trigger
📜 React component that monitors scroll events to trigger callbacks when it enters, exits and progresses through the viewport. All callback include the progress and velocity of the scrolling, in the event you want to manipulate stuff based on those values.
Stars: ✭ 126 (+223.08%)
Mutual labels:  react-component
traefik-ondemand-service
Traefik ondemand service for the traefik ondemand plugin
Stars: ✭ 35 (-10.26%)
Mutual labels:  scale
aspect-ratio-imageview
A simple imageview which scales the width or height aspect with the given ratio
Stars: ✭ 72 (+84.62%)
Mutual labels:  scale
React-Express-JWT-UserPortal
React.js & Express.js User portal Using Core UI, JWT, JWT Token, Refresh Token, Role & Permission management, User manamgenet, Event Log.
Stars: ✭ 22 (-43.59%)
Mutual labels:  react-component
react-file-input
⚛️  A file Input, with drag'n'drop and image editor for React
Stars: ✭ 71 (+82.05%)
Mutual labels:  react-component
Registration-and-Login-using-MERN-stack
Simple Registration and Login component with MERN stack
Stars: ✭ 210 (+438.46%)
Mutual labels:  react-component
react-ratings-declarative
A customizable rating component for selecting x widgets or visualizing x widgets
Stars: ✭ 41 (+5.13%)
Mutual labels:  react-component
anovos
Anovos - An Open Source Library for Scalable feature engineering Using Apache-Spark
Stars: ✭ 77 (+97.44%)
Mutual labels:  scale
react-native-slider-intro
A simple and fully customizable React Native component that implements an intro slider for your app
Stars: ✭ 80 (+105.13%)
Mutual labels:  react-component
react-textarea-code-editor
A simple code editor with syntax highlighting.
Stars: ✭ 247 (+533.33%)
Mutual labels:  react-component

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].