New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: additionalElementStyles
prop on fitText
and measureText
#3685
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thanks a lot for the PR! 🙌🏼 💙 I changed it to |
JonnyBurger
approved these changes
Apr 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With all the existing inputs
fitText
andmeasureText
expose, it's not possible to use these functions for more complex inputs where you need more control over the underlying<span>
element that gets created to measure the textExample
Before the addition
Adding a property like this:
Would make the fitText and measureText break and wrap the output.
After the addition,
It properly fits the text in now!
Why not just expose
textTransform
in as an input instead of creating a totally newadditionalElementStyles
I use this function in a project that uses this function in a complex text element inside a editor that supports various font properties on an element, like textTransform, transform, etc., which I don't think would make sense to have as explicit inputs to this function.
As for the risk of specifying fontFamily or fontSize, or any other property through
additionalElementStyles
, I've excluded them from the type for this property, hence leaving no scope of accidentally specifying the same property twice, once through the direct function params, and again throughadditionalElementStyles
.What could be improved
additionalElementStyles
is not the best and could be better. It sayselement
in the name, whereas the docs don't specify what theelement
actually is. Unless someone digs through the source code and finds out themeasureText
function actually creates an invisible text element in the DOM, they won't know this abstraction exists. Feels like it exposes parts of the abstraction that haven't been documented.fitText
docs, which says something like "it usesmeasureText
under the hood to calculate the size of the text with a standard fontSize, then uses the ratio of the resulting element's width to proportionally find the fontSize that would fit into the passed inwithinWidth
property. This property exposes the styles on the underlying invisible span element that is created", and something similar onmeasureText
as well.