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

[Modal] Migrate to emotion + unstyled #24857

Merged
merged 29 commits into from Feb 23, 2021
Merged

[Modal] Migrate to emotion + unstyled #24857

merged 29 commits into from Feb 23, 2021

Conversation

povilass
Copy link
Contributor

@povilass povilass commented Feb 10, 2021

Closes #20957
Closes #16442

@mui-pr-bot
Copy link

mui-pr-bot commented Feb 10, 2021

@material-ui/core: parsed: +0.37% , gzip: +0.23%
@material-ui/lab: parsed: +0.38% , gzip: +0.41%
@material-ui/unstyled: parsed: +26.65% , gzip: +23.41%

Details of bundle changes

Generated by 🚫 dangerJS against 13ffe70

@povilass
Copy link
Contributor Author

povilass commented Feb 10, 2021

Any ideas why karma fails?

Firefox 78.0 (Windows 10) ERROR
  ReferenceError: before is not defined
  at webpack:///test/utils/setupKarma.js:17:1 <- test/karma.tests.js:351818:1

Seen other pull request but their just fail because of timeout https://app.circleci.com/pipelines/github/mui-org/material-ui/37775/workflows/a3c068e5-582a-4e66-9564-d7f0eccd2d54/jobs/223216

Firefox 78.0 (Windows 10) ERROR
  Disconnectedreconnect failed before timeout of 120000ms (transport close)
Firefox 78.0 (Windows 10): Executed 2945 of 3434 (skipped 125) DISCONNECTED (6 mins 45.288 secs / 3 mins 46.492 secs)

@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 10, 2021

@povilass It has been failing like this for a week. I can even reproduce it locally. I was planning to solve/spend time on this issue. There is a high variance in the builds in BrowserStack, for some reason, sometimes it runs in 40s, sometimes in 3min+. cc @eps1lon CircleCI isn't the only one with unstable builds durations 🙃

@povilass
Copy link
Contributor Author

@oliviertassinari well that's disappointing, but at least I know code is not failing.

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.

The modal is tricky. We can't simply migrate it to emotion as it would break its current value proposition. It's meant to be very lightweight without any style library dependencies.

I see two possible options:

  1. We don't do anything about it, we keep the current inline style tradeoff
  2. We add an unstyled version of it

@povilass
Copy link
Contributor Author

povilass commented Feb 11, 2021

@oliviertassinari so you can decide which are you preferring and we could close this pull request and I would open a new request if you want to migrate it to UnstyledModal. But keep in mind Modal uses theme to get zIndex.

@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 11, 2021

@povilass I think that option 2 would be better longer-term. It would normalize the pattern. Right now, it's somewhat a hybrid. For instance, we have a SimpleBackdrop that uses inline style and a proper Backdrop that we inject when we need to use the Modal component in the other component, e.g. Dialog.

@povilass
Copy link
Contributor Author

@oliviertassinari Ok got, I would suggest updating the v5 list with NO_NEED_FOR_CONVERSION and move this change to the next iteration to the Unstyled package.

@oliviertassinari
Copy link
Member

@povilass Well, I still think that it needs to be migrated to emotion, but it needs the unstyled version too, otherwise, it's a regression for many developers using it as an alternative to https://github.com/reactjs/react-modal.

@povilass
Copy link
Contributor Author

@oliviertassinari Ok gonna try to add Unstyled version too.

@oliviertassinari
Copy link
Member

@povilass Sounds great, the Slider is a great one as a model.

@povilass
Copy link
Contributor Author

povilass commented Feb 11, 2021

@oliviertassinari I have 1 question about moving Modal to Unstyled package, it depends on Portal and TrapFocus I have to move those to unstyled package also otherwise I can not migrate Modal is it ok or not?

Update:
Also, it depends on BackdropComponents props.

I think we should first move TrapFocus, Portal and Backdrop(has Fade props too) to unstyled version.

@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 11, 2021

Portal and TrapFocus are already unstyled. We could indeed move them to the other package (@material-ui/unstyled) into a different pull request.

@povilass
Copy link
Contributor Author

povilass commented Feb 11, 2021

Backdrop migrated to emotion, probably can be moved to unstyled also and backdrop depends on Fade which already is unstyled just a transition.

Fade, Portal and TrapFocus can be moved with different pull requests now.
Next will be Backdrop to unstyled with other pull request and eventually, we can move Modal with this one.

Or should we merge Modal to emotion now close this issue and moved everything with other pull requests to unstyled package one by one? Do not want to mix emotion and unstyled issues in this one pull.

If you will let me I can create pull requests for each component and move it slowly.

@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 11, 2021

Backdrop migrated to emotion, probably can be moved to unstyled also and backdrop depends on Fade which already is unstyled just a transition.

@povilass Yes, I agree. For the Modal to be unstyled, it needs its leaves to be too.

Fade, Portal and TrapFocus can be moved with different pull requests now.

Fade is handled, we don't need to change it. It's using inline-style.

Or should we merge Modal to emotion now close this issue and moved everything with other pull requests to unstyled package one by one? Do not want to mix emotion and unstyled issues in this one pull.
If you will let me I can create pull requests for each component and move it slowly.

I think that we should move one component at a time, starting from the most nested blockers. I imagine the following possible iterations:

  1. Move TrapFocus from core to unstyled
  2. Move Portal from core to unstyled
  3. Move Backdrop to emotion + unstyled
  4. Move Modal to emotion + unstyled. Remove SimpleBackdrop. Update the demos to document both styled/unstyled components.

cc @eps1lon

@povilass
Copy link
Contributor Author

povilass commented Feb 12, 2021

@oliviertassinari I mean Backdrop depends on Fade props check and Fade depends on Transition props probably also can be moved to unstyled? Or BackdropUnstyled component can be without transition

UPDATE:

I think unstyled components should be without transition itself but you can pass components in core like Slider does with additional properties.

@oliviertassinari
Copy link
Member

@povilass Yes, you got the idea. Transitions don't make sense for unstyled components. The styled Backdrop should inject it's transition.

@povilass povilass mentioned this pull request Feb 12, 2021
1 task
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 12, 2021
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 19, 2021
@povilass
Copy link
Contributor Author

Gonna move it to unstyled and remove a simple backdrop so don't need a review for now

@povilass
Copy link
Contributor Author

TODO: Updating docs (for myself)

@oliviertassinari I have a problem with how to resolve exit property it's duplicate in both components. It depends on the transition component passed as a child. Should I move exit handling to Modal and pass it to ModalUnstyled as prop (both need to apply current styles and classes)?

@povilass
Copy link
Contributor Author

povilass commented Feb 20, 2021

There is a problem with typings where OverridableComponent returns JSX.Element.

declare const Backdrop: OverridableComponent<BackdropTypeMap>;
Backdrop -> JSX.Element

But BackdropComponent requires ComponentType or ElementType

In Modal.d.ts
    /**
     * A backdrop component. This prop enables custom backdrop rendering.
     * @default Backdrop
     */
    BackdropComponent?: React.ComponentType<BackdropProps>;

And can't resolve this issue because of this difference in SpringModal.tsx

image

UPDATE:
Adding changes to Modal -> BackdropComponent: React.ElementType work but if I add ModalUnstyled -> BackdropComponent: React.ElementType don't get it, is it typescript problem with overriding same property?

Index: packages/material-ui-unstyled/src/ModalUnstyled/ModalUnstyled.d.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- packages/material-ui-unstyled/src/ModalUnstyled/ModalUnstyled.d.ts	(revision f9712c1fdc04bb538703de2c56086d38572e1ed3)
+++ packages/material-ui-unstyled/src/ModalUnstyled/ModalUnstyled.d.ts	(date 1613855414514)
@@ -9,7 +9,7 @@
     /**
      * A backdrop component. This prop enables custom backdrop rendering.
      */
-    BackdropComponent?: React.ComponentType<BackdropUnstyledProps>;
+    BackdropComponent?: React.ElementType;
     /**
      * Props applied to the [`BackdropUnstyled`](/api/backdrop-unstyled/) element.
      */
@@ -136,7 +136,8 @@
  * Utility to create component types that inherit props from ModalUnstyled.
  */
 export interface ExtendModalUnstyledTypeMap<M extends OverridableTypeMap> {
-  props: M['props'] & ModalUnstyledTypeMap['props'];
+  // props: M['props'] & ModalUnstyledTypeMap['props'];
+  props: ModalUnstyledTypeMap['props'] & M['props'];
   defaultComponent: M['defaultComponent'];
 }
 
Index: packages/material-ui/src/Modal/Modal.d.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- packages/material-ui/src/Modal/Modal.d.ts	(revision f9712c1fdc04bb538703de2c56086d38572e1ed3)
+++ packages/material-ui/src/Modal/Modal.d.ts	(date 1613855212495)
@@ -14,7 +14,7 @@
      * A backdrop component. This prop enables custom backdrop rendering.
      * @default Backdrop
      */
-    BackdropComponent?: React.ComponentType<BackdropProps>;
+    BackdropComponent?: React.ElementType<BackdropProps>;
     /**
      * Props applied to the [`Backdrop`](/api/backdrop/) element.
      */

@oliviertassinari oliviertassinari changed the title [Modal] Migrate to emotion [Modal] Migrate to emotion + unstyled Feb 21, 2021
@oliviertassinari oliviertassinari added the component: modal This is the name of the generic UI component, not the React module! label Feb 21, 2021
@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 21, 2021

Rebased on HEAD.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 21, 2021
@povilass
Copy link
Contributor Author

Ok great, a lot of work done by this task did not even realize it will close other issues xd

@oliviertassinari
Copy link
Member

@povilass Definitely fixing old issues :). What do you think about handling the documentation of unstyled before we merge?

@povilass
Copy link
Contributor Author

povilass commented Feb 22, 2021

I think both are needed. The question is why?
A styled component can introduce new properties or omit properties from ModalUnstyled properties
If you omit properties from unstyled components we will miss some documentation. If we leave only unstyled documentation we will miss documentation from added properties there (for example sx property) :(

Same problem with newly added classes which does not exist in the unstyled components.

@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 22, 2021

@povilass I don't follow your point. For the documentation, I was referring to having a ## Unstyled modal demo after https://next.material-ui.com/components/modal/#simple-modal so the developers can see two options exist and how to apply the basic styles to get it working with a decent layout.

@povilass
Copy link
Contributor Author

povilass commented Feb 22, 2021

@oliviertassinari Oh ok, though you are talking about API documentation of Modal and ModalUnstyled, yes later I can provide a demo for the unstyled one too.

@povilass
Copy link
Contributor Author

@oliviertassinari need to re-run the test because everything runs for me and I updated docs.

@oliviertassinari oliviertassinari merged commit c425353 into mui:next Feb 23, 2021
@oliviertassinari
Copy link
Member

@povilass Great job here! This wasn't an easy one :)

@povilass
Copy link
Contributor Author

I call it medium difficulty but with a lot of boilerplate still need to improve in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: modal This is the name of the generic UI component, not the React module!
Projects
Status: Done
4 participants