-
Notifications
You must be signed in to change notification settings - Fork 59
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 basic support for CSS grid prefixing #174
Add basic support for CSS grid prefixing #174
Conversation
@garrettberg @ljharb @lencioni @calinoracation Hey there! Would you take a look whenever you have a chance? 🙏 |
const output = { | ||
gridTemplateColumns: '1fr auto', | ||
msGridColumns: '1fr auto', | ||
msGridTemplateColumns: '1fr auto', // Not a valid property |
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.
What do you mean by the comment here?
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.
The list of properties defined here causes this prefix to be automatically generated, even if it isn't valid (to the best of my knowledge). I don't have full context on why this is generated, but I think it could be removed - just waiting to hear back for confirmation.
|
||
describe('template', () => { | ||
it('should prefix column templating', () => { | ||
const input = { gridTemplateColumns: '1fr auto' } |
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.
Can you add some test cases for named grid areas?(e.g. https://vgpena.github.io/using-css-grid-the-right-way/#use-names-not-numbers)
return typeof value === 'number' && !isNaN(value) | ||
} | ||
|
||
const alignmentValues = ['center', 'end', 'start', 'stretch'] |
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 wonder if it is worth using something that has constant time lookup for this? I don't see Set
used anywhere though, but an object should do the trick. n=4 though, so maybe it doesn't really matter.
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.
It definitely shouldn't matter, but an object would be fine too i suppose.
/* @flow */ | ||
|
||
function isSimplePositionValue(value: any) { | ||
return typeof value === 'number' && !isNaN(value) |
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.
Can we use Number.isNaN
instead of this function? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN
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.
why? isNaN
is available in more places, and the typeof
ensures it'll behave identically.
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 we came full circle on this one
@lencioni Hey Joe, thanks for the comments! I went ahead and addressed them. |
modules/plugins/grid.js
Outdated
@@ -1,10 +1,10 @@ | |||
/* @flow */ | |||
|
|||
function isSimplePositionValue(value: any) { | |||
return typeof value === 'number' && !isNaN(value) | |||
return typeof value === 'number' && !Number.isNaN(value) |
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.
Actually, I wonder if Number.isFinite
is what you want here.
Also, I noticed that IE does not support either, so maybe what you originally had would be better in the end?
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.
@lencioni I went back to isNaN
and removed the use of Set
because I don't think IE11 supports constructing one from an iterable.
@rofrischmann Hey Robin! I'm trying to add basic support for CSS grid. Would you please take a look when you have a chance? |
Sure! Ill check it once I wake up tomorrow! Is it ready yet? Wanna get it merged and releasd asap :p |
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.
This looks fantastic!
It's ready! It doesn't fully cover the grid spec, but it adds enough basic compatibility that you can make things work on IE10/11. I might try to add more advanced features in other PRs. |
@rofrischmann Hey there, would you please take a look when you have time? I think this is ready to go. |
About the |
@rofrischmann I think we can probably take it out. I took a look at the older IE spec and some MDN data and came up with this:
|
Sorry for the delay. I had some unpredictable incidents in my family that required my full attention. |
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.
Alright, LGTM! Great work all of you, thank you =)
Weeeh, its out at 5.1.0 :P |
Thank you so much! 🙏 |
}) | ||
|
||
it('should not expand non-numerical values', () => { | ||
const input = { gridRow: '2 / span 3' } |
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.
@lencioni What's the reason why we wouldn't want 2 / span 3
to expand?
This PR implements very basic style prefixing for CSS grid. This is the first step to solving #173.
First, here's what I added:
display: grid | inline-grid
grid-column | grid-column-start | grid-column-end | grid-row | grid-row-start | grid-row-end
align-self
andjustify-self
grid-template-columns | grid-template-rows
Here's what I did not add (beyond the properties not listed above, obviously):
span
valuesrepeat
conversion (e.g.,repeat(2, 1fr)
->(1fr)[2]
)grid-column
andgrid-row
(see caveats at https://css-tricks.com/css-grid-in-ie-css-grid-and-the-new-autoprefixer/)This provides basic support for IE10/11 and early versions of Edge. The rest is difficult to add given the limited ability of this program to set styles on child elements (a general limitation of style composability imposed by React). I think it's possible to convert the
repeat
syntax and add basicspan
support, but that looks like it may be reaching beyond the scope of this program.Ah! One last note: I noticed that the grid values in
propertyMap.js
may be generating invalid styles. Should I try to trim that down?