πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

react-fitter

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-fitter

🫸 πš›πšŽπšŠπšŒπš-πšπš’πšπšπšŽπš› 🫷

0.1.8
latest
Source
npm
Version published
Weekly downloads
2
-66.67%
Maintainers
0
Weekly downloads
Β 
Created
Source

🫸 πš›πšŽπšŠπšŒπš-πšπš’πšπšπšŽπš› 🫷

In a project of mine I had to fit some text of unknown length to a container without it wrapping. This utility component does exactly that, regardless of whether if it sits inline, in a flexbox, grid or table. It just works.

Important πŸ’‘

At the moment the fitter can have some issues adjusting to containers that resize based on their content. A feeback loop occurs where the fitter never settles because the size changes with every change in font size. I have some ideas on how to fix this but haven't tried implemented any them yet. If this is an issue for your use case, please don't hesitate to open an issue.

npm install react-fitter

Usage:

import {Β Fitter } from 'react-fitter'

// ...

<div className="my-text">
  <Fitter>
    This is some text that will perfectly fit in the container
  </Fitter>
</div>

And your CSS can be whatever you want. The Fitter component will never make the text larger than what's set by your styles. It will only ever make it smaller.

.my-text {
  width: 400px;
  font-size: 24px;
  border: 1px solid hotpink;
}

Which would look like this:

Example with react-fitter

In contrast to how it would look without react-fitter:

Example without react-fitter

Fitter component props

Prop nameTypeDefault valueDescription
childrenReactNode(required)The content to fit.
minSizenumber0.25The minimum scale that the text will shrink to. E.g. 0.25 means the text will shrink to no less than 25% of its original size.
maxLinesnumber1The maximum number of lines that the text will shrink to fit.
settlePrecisionnumber0.01The precision at which the text will settle. The component finds the best size by halving the difference between the current size and the min/max size. If the difference is less than the settle precision, the component will stop and settle on that size. A value of 0.01 means the component will settle when the difference is less than 1%.
updateOnSizeChangebooleantrueWhether to update the text size when the size of the component changes.
resizeDebounceMsnumber50The time in milliseconds to wait before updating the text size when the size of the component changes. This is useful when the component is being resized frequently and you want to avoid updating the text size on every resize event.

Keywords

react

FAQs

Package last updated on 02 Nov 2024

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