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.
What do you mean by the comment here?
There was a problem hiding this comment.
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.
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.
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.
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.
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.
why? isNaN is available in more places, and the typeof ensures it'll behave identically.
There was a problem hiding this comment.
Yeah we came full circle on this one
|
@lencioni Hey Joe, thanks for the comments! I went ahead and addressed them. |
|
|
||
| function isSimplePositionValue(value: any) { | ||
| return typeof value === 'number' && !isNaN(value) | ||
| return typeof value === 'number' && !Number.isNaN(value) |
There was a problem hiding this comment.
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.
@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 |
|
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. |
|
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.
@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-gridgrid-column | grid-column-start | grid-column-end | grid-row | grid-row-start | grid-row-endalign-selfandjustify-selfgrid-template-columns | grid-template-rowsHere's what I did not add (beyond the properties not listed above, obviously):
spanvaluesrepeatconversion (e.g.,repeat(2, 1fr)->(1fr)[2])grid-columnandgrid-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
repeatsyntax and add basicspansupport, 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.jsmay be generating invalid styles. Should I try to trim that down?