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

[system] Add createTheme util #26490

Merged
merged 39 commits into from
Jun 4, 2021
Merged

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented May 28, 2021

The createTheme as part of the system has all defaults as the original @material-ui/core's createTheme, except the values inside the palette, typography, zIndex.

The createTheme in the core now uses the one from the system.

@mui-pr-bot
Copy link

mui-pr-bot commented May 28, 2021

Details of bundle changes (experimental)

@material-ui/system: parsed: +2.70% , gzip: +2.25%

Generated by 🚫 dangerJS against 1b26150

@oliviertassinari oliviertassinari added the package: system Specific to @mui/system label May 28, 2021
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label May 31, 2021
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 1, 2021
@@ -82,69 +79,6 @@ export const sizeHeight: SimpleStyleFunction<'sizeHeight'>;
export const boxSizing: SimpleStyleFunction<'boxSizing'>;
export type SizingProps = PropsFor<typeof sizing>;

// spacing.js
Copy link
Member Author

@mnajdova mnajdova Jun 1, 2021

Choose a reason for hiding this comment

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

Moved to spacing.d.ts and style.d.ts

Copy link
Member

@oliviertassinari oliviertassinari Jun 1, 2021

Choose a reason for hiding this comment

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

Oh yes, we need to break down this file 😅, or even jump one step and migrate the modules to TS.

const Div = styled('div')`
width: ${(props) => `${props.theme.spacing}px`};
width: ${(props) => props.theme.spacing(1)};
Copy link
Member Author

Choose a reason for hiding this comment

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

Support the original props.theme.spacing(1)


export type Direction = 'ltr' | 'rtl';

export interface ThemeOptions {
Copy link
Member Author

Choose a reason for hiding this comment

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

Part of these types are already included in the @material-ui/system ThemeOptions & Theme. We are now extending those.

@mnajdova mnajdova marked this pull request as ready for review June 1, 2021 14:30
@@ -0,0 +1,44 @@
import { deepmerge } from '@material-ui/utils';
import createBreakpoints from './createBreakpoints';
Copy link
Member Author

Choose a reason for hiding this comment

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

All these are moved from the @material-ui/core/styles.

docs/src/pages/customization/breakpoints/breakpoints.md Outdated Show resolved Hide resolved
@@ -82,69 +79,6 @@ export const sizeHeight: SimpleStyleFunction<'sizeHeight'>;
export const boxSizing: SimpleStyleFunction<'boxSizing'>;
export type SizingProps = PropsFor<typeof sizing>;

// spacing.js
Copy link
Member

@oliviertassinari oliviertassinari Jun 1, 2021

Choose a reason for hiding this comment

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

Oh yes, we need to break down this file 😅, or even jump one step and migrate the modules to TS.

@mnajdova mnajdova requested a review from oliviertassinari June 2, 2021 10:54
typography: createTypography(palette, typographyInput),
spacing,
shape: { ...shape },
transitions: createTransitions(transitionsInput),
Copy link
Member

@oliviertassinari oliviertassinari Jun 2, 2021

Choose a reason for hiding this comment

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

Not sure about the default value. Aren't the transition values specific to Material Design? Same for the shadows, border radius, mixins, spacing, breakpoints.

Copy link
Member

@oliviertassinari oliviertassinari Jun 2, 2021

Choose a reason for hiding this comment

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

I'm not sure that any of them should be in the system. But it's not all black and white; my attempt at ranking by order of what MD is the most unique about and the system should likely no include:

  1. mixins very specific to the AppBar
  2. shadows very specific to MD
  3. border-radius, specific to MD
  4. transition, specific to MD
  5. breakpoints, somewhat generic
  6. spacing, somewhat generic (TW uses 0.25rem, we use 8px, BS uses 0.5rem)

Copy link
Member

Choose a reason for hiding this comment

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

@material-ui/system: parsed: +7.94% , gzip: +7.85%

To be careful because the larger the system is, the less likely it will be used by third parties. What we currently have: https://bundlephobia.com/result?p=@material-ui/[email protected].

Copy link
Member

Choose a reason for hiding this comment

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

To be careful because the larger the system is, the less likely it will be used by third parties.

It is still not viable to cater to these people. Tree-shaking is a thing. If you want to live in the past with old technology then stay there. We're moving forwards where overall package size is mostly irrelevant.

Copy link
Member Author

Choose a reason for hiding this comment

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

My opinion on the matter:

mixins very specific to the AppBar - agree, will remove it
shadows very specific to MD - agree, will remove it
border-radius, specific to MD - I will think it's good default, would rather leave it, other can override
transition, specific to MD - agree, will remove it
breakpoints, somewhat generic - agree would leave it
spacing, somewhat generic (TW uses 0.25rem, we use 8px, BS uses 0.5rem) - agree, would leave it

Regarding the typings, I would leave all values in the ThemeOptions and as optional in the Theme, and in the core we can make the typings stricter, basically as they are in the moment. What do you think?

Regarding the bundle size, we are extending this package to be the styling package for building a custom design system, so I don't think we can compare with the previous implementation, but agree that we should be careful around not adding too many things which are not generic enough.

Copy link
Member

Choose a reason for hiding this comment

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

@mnajdova Sounds fair.


Tree-shaking

@eps1lon In the current approach, there is no tree shaking possible when importing Box or styled, we force the default theme. AFAIK, these two are meant to be the most popular modules used from @material-ui/system.

Do you mean that you would make the default version of the helper with an empty theme and allow developers to cherry-pick which baseline theme they want? It could be a thing

If you want to live in the past with old technology then stay there.

I assume "you" is targeted at the audience that is excessively worried about bundle size. The number of developers that were complaining about bundle size was relatively low in our last survey, maybe this audience is marginal. Assuming it's not a filtering bias, it supports the idea that we can take some liberties with bundle size and not care too much. For instance, chakra having all the styles of the components inside a non-tree-shakeable theme.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 3, 2021
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 3, 2021
@mnajdova mnajdova requested a review from oliviertassinari June 3, 2021 15:24
@mnajdova mnajdova merged commit 8a71384 into mui:next Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants