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.
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(transforms): adds 'px to rem' transform #491
feat(transforms): adds 'px to rem' transform #491
Changes from 1 commit
41857ff
2f6ec3c
9f7efa0
244ba69
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I like the spirit of this check, but no other transforms right now check for a unit, making this an outlier. What are your thoughts on removing this check in this transform, and then creating some more generic size transforms that look for units and apply the proper transform? I think it would be good to have these more intelligent transforms for people that want to specify borders in px but everything else in rem.
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.
Yeah, I can drop the check. Using
parseFloat
allows safely ignoring the unit if it is present.I'm not entirely sure what you mean by "[create] some more generic size transforms that look for units and apply the proper transform"? Do you mean something like
font/remToPx
, wherematcher: isFontSize
? That's the only example that I can think of.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.
I'm thinking of a transform that would transform web-based values (in either px or rem) and covert them to dp/sp on Android and pts (CGFloats) on iOS. And it would do a check like above to tell whether the number should be directly translated (px are roughly equivalent to dp/sp/pt) or multiplied by the basePxFontSize for rem units. That way someone could define sizes in pixels and rems and not need 2 separate transforms. Does that make sense? Maybe I just need to write a PR with some example code...
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.
Something like this?
size/webToSp
isFontSize()
if "rem", scale and append "sp"
size/webToDp
isNotFontSize()
if "rem", scale and append "dp"
size/webToPt
isSize()
if "rem", scale and append "pt"
The one thing I can't wrap my head around is from your original comment...
Looking at existing transforms:
*ToSp
always usesisFontSize
, so it is already specific to fonts.*ToDp
always usesisNotFontSize
, so, I think, it only applies to borders, spacing, etc.*ToPt
aways usesisSize
, so it applies to everything.Android appears to already handle making a distinction between fonts and borders. Not entirely sure how the same can be done to ios, or the web for that matter?
Apologies, I have zero experience with andoid and ios development, which I think is causing me all kinds of confusion.
Sidenote, I dropped the "px" check.
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.
Your table is exactly what I was imagining. Right now the existing transforms assume all sizes are either defined in rem or px, but could never be a combination of them. For example I could not define my borders in px and my font size and paddings in rem because the transforms assume all sizes are one or the other (using size/remToSp and size/remToDp or size/pxToSp and size/pxToDp). With the current transforms I could have fonts in rems, and paddings and borders in px, but I couldn't have font and padding in rem and borders in pixels. Hopefully that makes sense 🥴
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.
Hmm, I think I'm getting confused because I'm trying to apply the
size/webTo*
transforms to my scenario, when I think they might not actually apply.In my scenario, the design system has everything in pixels. Our only target for now is the web (no mobile) and all values are to be converted to rems. Therefore, I want to use something like
size/pxToRem
to avoid manually performing the px-to-rem conversions.If I'm understanding your comments, another scenario is a design system that defines mixed units. In that case, the expectation would be that any rem values would have been manually converted prior to being dropped into a property.json file? And, therefore,
size/pxToRem
would not be used at the same time assize/webTo*
? Is that correct?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.
I think what I'm ultimately trying to get at... is adding the
size/webTo*
transforms appropriate for this PR, or should they be the star of their own PR?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.
I think we should address it in a separate PR, I think this one is good enough as it is!