Help with integrating theme-ui and material-ui #819
Replies: 33 comments
|
Here's something that's helped me: https://theme-ui.com/use-theme-ui/ |
|
@clarkkozak Sounds good but I'll have to create a different theme object for different use cases. I was thinking of a transformer as mentioned in #164 |
|
@jxnblk Do you have any ideas? I was thinking of finding properties of material-ui theme object from the theme-ui one and do the corresponding mapping. What do you think? |
|
material-ui also has a createMuiTheme function that creates their theme object. I think this can also be used. |
|
@TheFirstMe sounds perfect! Honestly though, I'd close this issue ASAP because it's more asking for help with coding rather than an issue with the code base. I suggest checking out a forum specifically centered around helping others code. For example: https://stackoverflow.com/ |
|
@clarkkozak That was my initial intention. But I'd also like to create a feature that does this for theme-ui if possible. |
|
@TheFirstMe right on :) well, if you make a fork, let me know and I'd love to help. |
|
If my understanding is correct, it should be possible to store your theme values canonically in Theme UI's format/schema, but use a transformer to accommodate Material UI's schema. I can see value in adding something like this as an optional package here in Theme UI, if you're interested in helping out. I'd imagine the API could look something like the following: import { jsx, ThemeProvider } from 'theme-ui'
import { MaterialUIProvider } from '@theme-ui/material-ui'
import theme from './theme'
export default props =>
<ThemeProvider theme={theme}>
<MaterialUIProvider>
{props.children}
</MaterialUIProvider>
</ThemeProvider> |
|
@jxnblk One thing I found confusing from Theme UI's docs is that not all values are required in the schema but that's not the case in Material UI. I tried building a mock transformer using the createMuiTheme from Material UI's API and it works fine (not all values from Theme UI theme were used). Should the transformer account for all possible values in Theme UI's schema that are relevant to Material UI's schema? There are also values in Material UI schema that are not relevant to Theme UI so those should be left untouched? |
|
If Material UI requires all fields in its API, you could provide those as defaults (I'm surprised that library doesn't do that already 🤔) |
|
I am not sure if they are absolutely required but they don't state that it's not in the docs unlike Theme UI. Also their default theme is generated using their createMuiTheme API. I suppose those fields are necessary because all components are styled based on those values. |
|
My bad I just saw they are using the theme generated from that function by default so it's fine. |
|
As I said above, there are fields used by Material UI that are not used by Theme UI. What should we do about them? Here's the default theme used by Material UI: |
|
The only thing that looks like something not in Theme UI is the |
|
@clarkkozak Here's the Theme UI theme: The default Material UI theme can be found here The problems:
|
|
@TheFirstMe I see! I'll think about this over my weekend and see if I can think about what it would be like EDIT: Yet I don't think I'll be much help :P you have a great understanding of the problem, and I agree with @jxnblk. Something like |
|
@clarkkozak I do have an idea on how If we can do that, then all we need to do is pass that theme to their ThemeProvider? EDIT: EDIT v2: EDIT v3: |
|
I made a transformer that transforms almost all Theme UI fields to the Material UI with some additional fields that were not in the standard Theme UI object. But I left out some Material UI only fields for now because I need some input from others before I can continue on that. Can I start working on the package now? |
|
@TheFirstMe do you have a fork that we can look at? I'd love to see what you got! |
|
@clarkkozak Here's the fork. But I am having trouble running it as a package. I suspect it's because I'm using I haven't worked on a package before so I must be missing something here. Can you help me out? Edit: Edit v2: |
|
@jxnblk @clarkkozak All set for opening a PR. I hope the fork is ok. |
|
@TheFirstMe Perhaps include an example of how it works in the README and write a test for it? I haven't read it closely yet double check the Contributions.md EDIT: And your code looks clean and readable :) I like it, yet i have no authority in this project. |
|
@clarkkozak Ah forgot about the README. Just added it to the fork. It's usage is how @jxnblk mentioned in his comment above: import { jsx, ThemeProvider } from 'theme-ui'
import { MaterialUIProvider } from '@theme-ui/material-ui'
import theme from './theme'
export default props =>
<ThemeProvider theme={theme}>
<MaterialUIProvider>
{props.children}
</MaterialUIProvider>
</ThemeProvider>I have never worked with Jest before so I'm not sure about the tests. I will try making one. |
|
Hi @TheFirstMe , is there anything blocking you from submitting the PR? |
|
@jgoux I see that each package needs its tests so I'm working on that right now. I'm new to testing so it's taking some time. |
|
Hello, I just want to say this is a very good idea, I was just trying to do something similar until I found this issue |
|
@zerubeus Can you check it out and suggest any improvements or if there are any bugs? |
|
@jxnblk have you checked this out? It works and seems like solid code. |
|
@clarkkozak Sorry I forgot about this. The tests are incomplete though. If anyone can help me with those we can open a PR. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
( Related to #164 )
I have a Gatsby application that runs on theme-ui. I really love the API that comes with theme-ui. But at the same time I also want to use material-ui components inside my application. Can someone help me on how I would approach this problem?
In the end, I should be able to access theme-ui theme from the sx prop and it should be passed down to the material-ui components. I’m thinking of a transformer as mentioned in the above issue. Right now, I am using Gatsby plugins for theme-ui and material-ui but it requires two separate theme objects. If someone can give me ideas on how to transform theme-ui theme to material-ui theme, I could work on a PR
All reactions