mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.65k stars 32.22k forks source link

[Docs] - Styled-components examples in docs are using Emotion #36681

Closed amjadorfali closed 9 months ago

amjadorfali commented 1 year ago

Duplicates

Related page

https://mui.com/material-ui/guides/interoperability/#styled-components

Kind of issue

Broken demonstration

Issue description

I was looking for examples of using Styled components instead of emotion in MUI 5. Although the first Edit in code sandbox is working properly and has SC in dependencies, it appears that all the other examples are done in emotion

This one is working (Edit in code sandbox)

Screenshot 2023-03-29 at 1 21 22 PM

When opening any 1 of those 3 (Clicking edit in code sandbox), it shows the example using Emotion, where it should be using styled-components

1- Deeper Elements

Screenshot 2023-03-29 at 1 22 06 PM

2- Theme

Screenshot 2023-03-29 at 1 22 23 PM

3- Portals

Screenshot 2023-03-29 at 1 22 37 PM

I know essentially the differences between the 2 are very minor, but because i've been to multiple hoops to integrate SC with MUI v5, i want to make it easier for future migrations

If you guys think this an issue and needs fixing, i'd be happy to work on it

Context 🔦

Trying to fix examples i guess for future readers, as those are the only styled-components examples provided (i assume)

amjadorfali commented 1 year ago

Just a note, i know both of them will be using the exact same syntax, but it's just about having different dependencies and using the alias/resolutions fields in package.json

mnajdova commented 1 year ago

Thanks for the feedback, the idea was that once you set it up, we can show the code with the additional changes, but we have the codesandbox link on each demo so this may be confusing, agree. We should follow the same way of how they are displayed as the first demo. @samuelsycamore would you like to tackle this?

samuelsycamore commented 1 year ago

Sure thing! I've been meaning to edit and revise this whole doc for awhile now, so I'll add it to the list. 👍

amjadorfali commented 1 year ago

Thank you! If i can help with anything in this library i'd be more than happy. I am new to open source contributions, so I'm struggling to find a first good task😅

samuelsycamore commented 1 year ago

@amjadorfali if you'd like to tackle the specific issue here, please feel free! I can circle back around with a bigger content revision for this doc later.

amjadorfali commented 1 year ago

@samuelsycamore Thank you ! I will handle it ASAP

samuelsycamore commented 1 year ago

Excellent! You can tag me as a reviewer on the PR when you're ready!

amjadorfali commented 1 year ago

@mnajdova @samuelsycamore

Problem

Generating code-sandbox is does not generate proper dependency configuration for styled-components (Not sure if there’s others, as it’s a reusable component <DemotTooltip/>)

Possible Solution

Fix logic in :

docs/src/modules/sandbox/CodeSandbox.ts
docs/src/modules/sandbox/StackBlitz.ts

To generate proper sandbox for styled component docs

How ?

Findings

For the above components, need a way to pass props to parent components

Component ⇒ interoperability.js ⇒ MarkdownDocs.js ⇒ Demo.js ⇒ DemoToolbar.js ⇒

Need to pass custom props to the above functions in order to add more options to package.json

Props will be used in the following files :

Props will be used to add a Record<string, string> to the package.json, in order to add custom properties

What’s next ?

As i’m not sure the solution i’m providing is the proper way to go, there could be something i’m missing out on; I’d love to hear your take on this

samuelsycamore commented 1 year ago

Thanks for digging deeper into this @amjadorfali! I think we should call in @mui/docs-infra here to see what they think :)

mnajdova commented 1 year ago

🤔 Need to figure out a way to pass in custom config to the props Needed special handling for : StyledComponentsPortal.tsx/.js StyledComponentsTheme.tsx/.js StyledComponentsDeep.tsx/.js

You can do something like:

{{"demo": "StyledComponentsPortal.js", "useStyledEngineSc": true}}

Get this prop from demoOptions inside the <Demo /> component and then you can propagate it to the Sandbox and Stackblitz components.

amjadorfali commented 1 year ago

Hey everyone @mnajdova @samuelsycamore , sorry for being late on this, i had a very busy week and i just started working on it tonight.

Uspide ⏫

Downside 🙃

Screenshot 2023-04-15 at 12 29 04 AM

I need to dive more into how codesandbox works, and know why slackblitz just works (with or without the alias, tried it)

If you got any ideas on this please let me know 🙏🏼

Notes :

In the style engine guide, it mentions using resolutions (also differs between yarn / Npm ...)

So i got a bit lost as the "Working sandbox" , uses alias

amjadorfali commented 1 year ago

I am kinda stuck on this part, i will do some cleanups and push my current changes, to see if anyone can help with this issue

One thing to note : Codesandbox did workout eventually, but only when changing the Sandbox.config to vanilla instead of create-react-app (I changed it directly in the sandbox, as in the code i didn't find where to configure it)

For stackblitz as i mentioned, it's working, although it throws a warning about missing peer dependencies at the beginning.