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/ |
Beta Was this translation helpful? Give feedback.
-
@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 |
Beta Was this translation helpful? Give feedback.
-
@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? |
Beta Was this translation helpful? Give feedback.
-
material-ui also has a createMuiTheme function that creates their theme object. I think this can also be used. |
Beta Was this translation helpful? Give feedback.
-
@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/ |
Beta Was this translation helpful? Give feedback.
-
@clarkkozak That was my initial intention. But I'd also like to create a feature that does this for theme-ui if possible. |
Beta Was this translation helpful? Give feedback.
-
@TheFirstMe right on :) well, if you make a fork, let me know and I'd love to help. |
Beta Was this translation helpful? Give feedback.
-
@clarkkozak I'll let you know. Thanks :) |
Beta Was this translation helpful? Give feedback.
-
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>
|
Beta Was this translation helpful? Give feedback.
-
@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? |
Beta Was this translation helpful? Give feedback.
-
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 🤔) |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
My bad I just saw they are using the theme generated from that function by default so it's fine. |
Beta Was this translation helpful? Give feedback.
-
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:
|
Beta Was this translation helpful? Give feedback.
-
The only thing that looks like something not in Theme UI is the |
Beta Was this translation helpful? Give feedback.
-
@clarkkozak Here's the Theme UI theme:
The default Material UI theme can be found here The problems:
|
Beta Was this translation helpful? Give feedback.
-
@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 |
Beta Was this translation helpful? Give feedback.
-
@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: |
Beta Was this translation helpful? Give feedback.
-
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? |
Beta Was this translation helpful? Give feedback.
-
@TheFirstMe do you have a fork that we can look at? I'd love to see what you got! |
Beta Was this translation helpful? Give feedback.
-
@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: |
Beta Was this translation helpful? Give feedback.
-
@jxnblk @clarkkozak All set for opening a PR. I hope the fork is ok. |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
Hi @TheFirstMe , is there anything blocking you from submitting the PR? |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
@zerubeus Can you check it out and suggest any improvements or if there are any bugs? |
Beta Was this translation helpful? Give feedback.
-
@jxnblk have you checked this out? It works and seems like solid code. |
Beta Was this translation helpful? Give feedback.
-
@clarkkozak Sorry I forgot about this. The tests are incomplete though. If anyone can help me with those we can open a PR. |
Beta Was this translation helpful? Give feedback.
-
( 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
Beta Was this translation helpful? Give feedback.
All reactions