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

Utility classes #3

Open
wants to merge 23 commits into
base: origin/next
Choose a base branch
from
Open

Utility classes #3

wants to merge 23 commits into from

Conversation

mnajdova
Copy link
Owner

docs/src/pages/system/global-classes/spacings.js Outdated Show resolved Hide resolved
cssProperties.forEach((cssProperty) => {
spacings[cssKey][
`${properties[property]}${cssProperty}`
] = theme.spacing(val / 2);

Choose a reason for hiding this comment

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

Later on, we will probably want to move mui#21030 forward.

@@ -153,6 +153,7 @@ const pages = [
{ pathname: '/system/screen-readers' },
{ pathname: '/system/typography' },
{ pathname: '/system/api', title: 'API' },
{ pathname: '/system/global-classes' },

Choose a reason for hiding this comment

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

Seeing the structure makes me think of how we don't explain well the value proposition of the helpers on the /basics page. http:https://material-ui.com/system/basics#real-world-use-case should be at the top like they did on https://tailwindcss.com/docs/utility-first. Or even https://chakra-ui.com/ on the homepage 😆

Copy link
Owner Author

Choose a reason for hiding this comment

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

I was missing explanation a bit too to be honest..

}
};

export default function colors(theme) {

Choose a reason for hiding this comment

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

I wonder if it would make sense to expose the Material Design colors https://material-ui.com/customization/color/#2014-material-design-color-palettes

Copy link
Owner Author

Choose a reason for hiding this comment

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

Interesting, I just exported only the ones that are in the palette inside the theme, thinking that if users will restrict that set or add new colors the classes would reflect that. On the other hand I don't see why we should not expose these colors too...

Choose a reason for hiding this comment

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

If we have a doubt, we can wait to see if people ask for it

docs/src/pages/system/global-classes/colors.js Outdated Show resolved Hide resolved
docs/src/pages/system/global-classes/colors.js Outdated Show resolved Hide resolved
docs/src/pages/system/global-classes/colors.js Outdated Show resolved Hide resolved
whiteSpaces,
} from './displays';

const GlobalCss = withStyles((theme) => {

Choose a reason for hiding this comment

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

I think that we will need to look at

  1. the time it takes to build the styles
  2. how we can handle server-side rendering, if we trust https://tailwindcss.com/docs/controlling-file-size/, 144.5kb gzipped is no way for inlining critical CSS. In our current experimentation, we are at 4kb gzipped. https://www.nytimes.com/ is 210kB gzipped. Youtube.com is 56kb gzipped. Amazon.com is at 93kb gzipped. So I would say 40kB gzipped isn't too far from our limit.

Choose a reason for hiding this comment

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

Actually, for 2. I remember emotion having some sort of critical extraction tool, to only include the required class names. Tailwind has something similar, if it's fast enough to be run at each server-side query, it could move the limitation to 1. only. On the server 1. can be cached.

Choose a reason for hiding this comment

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

For 1. I measure 1ms to build the object and 12ms for JSS to process the object before injection in the page. I have no idea how it scales. They might be way to bypass the plugins, speeding things up. We would also need to look at how long it makes with styled-components and emotion.

docs/src/pages/system/global-classes/Basics.tsx Outdated Show resolved Hide resolved
'.d-none': { display: 'none' },
'.d-initial': { display: 'initial' },
'.d-inherit': { display: 'inherit' },
'.d-print-inline': { '@media print': { display: 'inline' } },

Choose a reason for hiding this comment

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

I wonder if we couldn't handle print as a custom breakpoint, as we would handle sm, or md.

Copy link
Owner Author

Choose a reason for hiding this comment

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

One thing I was thinking about was, whether we should include the breakpoints inside the class names (Vuetify has them), so that.. It could be useful I think

Copy link

@oliviertassinari oliviertassinari Jul 16, 2020

Choose a reason for hiding this comment

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

Yeah, it seems that being able to change the values based on the media query is a critical feature they all have. I also don't see how I could implement anything without it 😁. And yes, agree, to make it work, it has to be in the class names.

The question I see left is where? Should it be a prefix like Tailwind, or in the middle Like Bootstrap/Vuetify, or should it be at the end? I think that it's mostly about how you want to organize your code. Consider how the sx prop and our current system works, I would be leaning toward as a prefix sm:p-3, print:p-3. Thought?

Choose a reason for hiding this comment

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

Hum, not sure actually, we document the following for the props API:

display={{ xs: 'none', sm: 'block' }}

Copy link
Owner Author

Choose a reason for hiding this comment

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

added breakpoints on all classes as prefix

Copy link
Owner Author

Choose a reason for hiding this comment

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

I left print as is for now, mainly because it may be combined with other breakpoints...

Copy link

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

docs/src/pages/system/global-classes/global-classes.md Outdated Show resolved Hide resolved
docs/src/pages/system/global-classes/texts.js Outdated Show resolved Hide resolved
'.d-none': { display: 'none' },
'.d-initial': { display: 'initial' },
'.d-inherit': { display: 'inherit' },
'.d-print-inline': { '@media print': { display: 'inline' } },

Choose a reason for hiding this comment

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

Hum, not sure actually, we document the following for the props API:

display={{ xs: 'none', sm: 'block' }}

docs/src/pages/system/global-classes/spacings.js Outdated Show resolved Hide resolved
@jedwards1211
Copy link

jedwards1211 commented Jul 16, 2020

Seems like we would just need to make a PR to that html-css-class-completion extension that lets us configure additional directories inside node_modules to scan for CSS classes

I wasn't thinking, these CSS classes are defined in JS files. Maybe we could propose a way to have that extension run user-defined scripts that return additional class names...seems like it wouldn't be super trivial to make our own thing from scratch, I haven't looked at what technique they use to decide when to show the autocomplete

@mnajdova
Copy link
Owner Author

mnajdova commented Jul 17, 2020

@oliviertassinari here are some answers.

What's missing before we can accurately know the performance implication of the approach?

We were missing the breakpoints, they are added now, so I believe we should be ready. I was not sure whether we want to generate classes for the borders, if we do we may want to add those first too.

Regarding the diff with the prop base approach. I assume people will only want to use one of the two approaches, depending on what they enjoy most. I wonder about how we can best organize the documentation have the two live together. What elements we should highlight to help developers pick a side?

Hmm, I was ideally thinking that we would create the utility classes which can be used on all components, so that we don't need to actually add the Box's system API on all components. If I am correct in this thinking, I would say that the Box should be use only for prototyping purposes, not sure when we would like to use it over the utility classes (maybe if people need more dynamics?)

Shouldn't we move the pull request to the main repo as a draft?

Let me move the changes to the system package and will create draft PR on the main repo 👍

Note: I had to add !important to some of the classes generate, to make sure they would always win, not sure if it is the best approach... @oliviertassinari what are your thoughts?

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