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

[Table] Migrate TablePagination to emotion #25809

Merged
merged 29 commits into from
Apr 23, 2021

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Apr 17, 2021

One of #24405

@siriwatknp siriwatknp changed the title [Table] migration TablePagination to emotion [Table] migrate TablePagination to emotion Apr 17, 2021
@mui-pr-bot
Copy link

mui-pr-bot commented Apr 17, 2021

Details of bundle changes

@material-ui/core: parsed: +0.33% , gzip: +0.28%

Generated by 🚫 dangerJS against abf563b

@siriwatknp
Copy link
Member Author

image

Styling is a bit ugly, is this the expected result? (v4 implementation does not work, I think it is because emotion merge the styles, so I need to add breakpoints to overrides)

const TablePaginationToolbar = experimentalStyled(
  Toolbar,
  { shouldForwardProp: (prop) => shouldForwardProp(prop) || prop === 'classes' },
  {
    name: 'MuiTablePagination',
    slot: 'Toolbar',
    overridesResolver: makeOverridesResolver('toolbar'),
  },
)(({ theme }) => ({
  minHeight: 52,
  paddingRight: 2,
  [`${theme.breakpoints.up('xs')} and (orientation: landscape)`]: {
    minHeight: 52,
  },
  [theme.breakpoints.up('sm')]: {
    minHeight: 52,
  },
}));

@oliviertassinari oliviertassinari added the component: table This is the name of the generic UI component, not the React module! label Apr 17, 2021
@siriwatknp

This comment has been minimized.

@oliviertassinari
Copy link
Member

@siriwatknp use the as prop

@siriwatknp
Copy link
Member Author

@siriwatknp use the as prop

So, the demo should change from using component="div" to as="div" right? If yes, do I need to add types to .d.ts?

@siriwatknp
Copy link
Member Author

Open another issue to fix className overwritten #25814

@oliviertassinari oliviertassinari changed the title [Table] migrate TablePagination to emotion [Table] Migrate TablePagination to emotion Apr 17, 2021
Copy link
Member

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

@siriwatknp I have pushed extra commits, as small as I could, please review. I have tried to make so the changes have as few breaking changes as possible.

@mnajdova The most interesting aspect seems the overridesResolver structure. I like how it's more isolated, how the CSS specificity is flatter, and how it enables having a default behavior (automatically allowing a slot in the theme from the name of the styled slot). Is there a reason for not doing this in the whole codebase (e.g. performance)?

@siriwatknp
Copy link
Member Author

Looks good to me 😊

@mnajdova
Copy link
Member

@mnajdova The most interesting aspect seems the overridesResolver structure. I like how it's more isolated, how the CSS specificity is flatter, and how it enables having a default behavior (automatically allowing a slot in the theme from the name of the styled slot). Is there a reason for not doing this in the whole codebase (e.g. performance)?

I didn't want to push forward with this strictly because of perf, we would need for each slot to resolver theme overrides and merge... It is useful for containers or other non-child slots, but I wouldn't add it everywhere... I remember we had this discussion when we were comparing one styled() component in the root, or multiple styled components, this would be similar..

Anyway, it would be interesting to measure how big this difference would be now that we have some actual components migrated. Not sure what the benefit would be, as developers are either going to use theme for overrides, or use styled() for wrapping slots, so both of those independently work. If they want to mix these two, than using overrides resolver on each slot would help

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

@siriwatknp @oliviertassinari we should not however add this new overridesResolver on each slot paradigm in just few components before we measure how expensive it is and describing what issues it will solve. We should have a unified way of defining styles & overrides. Especially that we have few components left to be migrated.

@siriwatknp if you would like to create RFC with the proposed changes on one component with details on what problems the new definition of the styles solve and measure the perf difference it would be great.
Created #25850 seems like we can go with this option :).

Edit: One thing it would help us with is #25075 (comment), but again not sure what the cost would be.

@mnajdova mnajdova dismissed their stale review April 20, 2021 14:21

Seems like in the end we will go with overridesResolver per slot. No changes needed.

)(({ theme }) => ({
minHeight: 52,
paddingRight: 2,
[`${theme.breakpoints.up('xs')} and (orientation: landscape)`]: {
Copy link
Member

Choose a reason for hiding this comment

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

Where are these styles coming from?

Copy link
Member Author

Choose a reason for hiding this comment

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

same as above, to override Toolbar styles

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to have a Toolbar in the first place? It seems odd in hindsight.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think let's keep it because the PR is only about migration.

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Nice! Sorry it took me some time to wrap up the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: table This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants