Skip to content
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

Merged
merged 5 commits into from
Apr 4, 2019

Conversation

etripier
Copy link
Contributor

@etripier etripier commented Mar 3, 2019

This PR implements very basic style prefixing for CSS grid. This is the first step to solving #173.

First, here's what I added:

  • Prefixing for display: grid | inline-grid
  • Prefixing / expansion for grid-column | grid-column-start | grid-column-end | grid-row | grid-row-start | grid-row-end
  • Prefixing for align-self and justify-self
  • Prefixing for grid-template-columns | grid-template-rows

Here's what I did not add (beyond the properties not listed above, obviously):

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 basic span 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?

@etripier
Copy link
Contributor Author

etripier commented Mar 3, 2019

@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
Copy link
Contributor

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?

Copy link
Contributor Author

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' }
Copy link
Contributor

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']
Copy link
Contributor

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.

Copy link

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

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.

Copy link
Contributor

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

@etripier
Copy link
Contributor Author

etripier commented Mar 4, 2019

@lencioni Hey Joe, thanks for the comments! I went ahead and addressed them.

@@ -1,10 +1,10 @@
/* @flow */

function isSimplePositionValue(value: any) {
return typeof value === 'number' && !isNaN(value)
return typeof value === 'number' && !Number.isNaN(value)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@etripier
Copy link
Contributor Author

etripier commented Mar 7, 2019

@rofrischmann Hey Robin! I'm trying to add basic support for CSS grid. Would you please take a look when you have a chance?

@robinweser
Copy link
Owner

Sure! Ill check it once I wake up tomorrow! Is it ready yet? Wanna get it merged and releasd asap :p

Copy link

@calinoracation calinoracation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fantastic!

@etripier
Copy link
Contributor Author

etripier commented Mar 8, 2019

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.

@etripier
Copy link
Contributor Author

@rofrischmann Hey there, would you please take a look when you have time? I think this is ready to go.

@robinweser
Copy link
Owner

robinweser commented Mar 14, 2019

About the propertyMap.js, did you remove that or do you think we should do it? After all, it should just add prefixes to some values, so it won't break anything. But, it might be unnecessary as well.

@etripier
Copy link
Contributor Author

etripier commented Mar 15, 2019

@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:

gridTemplateColumns - `-ms-grid-columns` is used instead
gridTemplateRows    - `-ms-grid-rows` is used instead
gridTemplateAreas   - not supported in IE
gridTemplate        - not supported in IE
gridAutoColumns     - `-ms-grid-columns` is used instead
gridAutoRows        - `-ms-grid-rows` is used instead
gridAutoFlow        - not supported in IE
grid                - not supported in IE
gridRowStart        - `-ms-grid-row` is used instead (not a 1-1 match)
gridColumnStart     - `-ms-grid-column` is used instead (not a 1-1 match)
gridRowEnd          - `-ms-grid-row-span` is used instead (not a 1-1 match)
gridRow             - not a 1-1 match, implemented in the PR
gridColumn          - not a 1-1 match, implemented in the PR
gridColumnEnd       - `-ms-grid-column-span` is used instead (not a 1-1 match)
gridColumnGap       - not supported in IE
gridRowGap          - not supported in IE
gridArea            - not supported in IE
gridGap             - not supported in IE

@lencioni
Copy link
Contributor

:shipit:

@robinweser
Copy link
Owner

Sorry for the delay. I had some unpredictable incidents in my family that required my full attention.
I'll try to merge and release this one asap. Probably on monday or tuesday.

@robinweser robinweser self-requested a review April 4, 2019 08:42
Copy link
Owner

@robinweser robinweser left a 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 =)

@robinweser robinweser merged commit 0bc1284 into robinweser:master Apr 4, 2019
@robinweser
Copy link
Owner

Weeeh, its out at 5.1.0 :P

@etripier
Copy link
Contributor Author

etripier commented Apr 5, 2019

Thank you so much! 🙏

})

it('should not expand non-numerical values', () => {
const input = { gridRow: '2 / span 3' }
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants