Comments (3)
I am starting with the text transparent and then using the useFitText({onFinish}) callback to make it opaque after resizing completes. It's a bit of a pain to do this everywhere manually, but it works.
from use-fit-text.
I am starting with the text transparent and then using the useFitText({onFinish}) callback to make it opaque after resizing completes. It's a bit of a pain to do this everywhere manually, but it works.
Thanks for the idea @masonlee... I'm using this custom hook:
export const useFitTextFinished = (options) => {
const [finished, setFinished] = useState(false);
const { ref, fontSize } = useFitText({
...options,
onFinish: () => setFinished(true),
});
return { ref, fontSize, finished };
};
Edit:
Ok, now I'm getting wacky with it... considering this method so I don't have to explicitly handle hiding outside of the hook:
export const useFitTextFinished = ({ color: finishedColor, ...options }) => {
const [color, setColor] = useState("transparent");
const { ref, fontSize } = useFitText({
...options,
onFinish: () => setColor(finishedColor),
});
return { ref, fontSize, color };
};
from use-fit-text.
I made this custom hook. It uses undefined
color to use the original color.
import { useState } from 'react';
import useFitText, { TOptions } from 'use-fit-text';
const useBetterFitText = (options?: TOptions) => {
const [color, setColor] = useState<'transparent' | undefined>('transparent');
const { ref, fontSize } = useFitText({
...options,
onFinish: (finishedFontSize: number) => {
setColor(undefined);
if (options?.onFinish) options?.onFinish(finishedFontSize);
},
});
return { ref, fontSize, color };
};
export default useBetterFitText;
from use-fit-text.
Related Issues (16)
- Would be great to recalculate on window resize HOT 5
- Text exceeds the div boundary for some font family HOT 9
- Initial fontSize value is not updated and onStart/onFinish do not fire HOT 5
- Overflow with padding HOT 2
- Not resizing on dynamically received data
- Not resizing on dynamically received data HOT 8
- We can get rid of the binary search in the font size algorithm HOT 2
- Fails setting `lineHeight` HOT 3
- Not resizing on the first rendering HOT 1
- Support non-px width values? HOT 1
- Consider removing polyfill
- Fill the whole width initially & 'text-align: center;' problem
- Cannot find type definition file for 'next'. HOT 3
- How to be sure that redraw is finished ? HOT 4
- Maximum update depth exceeded HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from use-fit-text.