-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add support for different units in TextStyle.lineHeight
#156
Add support for different units in TextStyle.lineHeight
#156
Conversation
Hi @blinpete, thanks a lot for your PR, it looks amazing! I have just one doubt. In my figma-export example file, I have two different texts (different font-size) with line-height set to // first text with line-height: Auto
{
type: "TEXT",
style: {
...,
"fontSize": 14,
"lineHeightPx": 16.40625,
"lineHeightPercent": 100,
"lineHeightUnit": "INTRINSIC_%"
}
}
// second text with line-height: Auto
{
type: "TEXT",
style: {
...,
"fontSize": 18,
"lineHeightPx": 21.09375,
"lineHeightPercent": 100,
"lineHeightUnit": "INTRINSIC_%"
}
} Before this change, the line height was generated as What do you think about it? How can we manage it? |
Hey @marcomontalbano! not sure about this
what are your thoughts on this? |
I would proceed with the option 2. Since |
…r for backward compatability
@marcomontalbano |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done, thanks!
I just released v4.8.0-alpha.1 Let me know if everything is working as expected. |
Yep, figma-export handles all the line heights as expected. |
This pull request adds support for different line height units.
Issue
Currently
TextStyle.lineHeight
is a unitless number and storeslineHeightPx
coming from figma-js and Figma API itself. Which results in unexpected behavior when you set up your line height in font size percentage but still end up with pixels exported.Having this as the default behavior is a bit confusing cuz a unitless line height in web development carries a different meaning.
Solution
Figma supports 3 line height units
PIXELS
,INTRINSIC_%
andFONT_SIZE_%
.Now
TextStyle.lineHeight
is a string and thetextStyle
parser handles all of the units correctly according tolineHeightUnit
value.The difference in behavior
Considering this Figma
TextNode
here's howfigma-export
handles a line height depending on thelineHeightUnit
key:lineHeightUnit
lineHeight: 30
✅lineHeight: "30px"
✅lineHeight: 30
❌lineHeight: "106%"
✅lineHeight: 30
❌lineHeight: "1.25"
✅@marcomontalbano Thanks for your work,
figma-export
is damn well designed!