-
Hey, I recently watched a YouTube video about this lib and I started considering using it for an app I'm building. But after reading the docs and finishing the video I haven't seen a convenient way to do a feature I'd like to offer to users. I want to give them control on the theme, so they can change it live. Is there a way to do it using the runtime or registry? Because merging the custom theme manually in each component using dynamic functions or something doesn't feel right to me 🤔. Great job with the lib btw, looks promising |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Hello 👋 , it is not yet possible. I mentioned in the docs that, from an architectural standpoint, it’s possible but not yet implemented. I was waiting for someone to request it. I can introduce a new method in UnistylesRuntime to alter the theme, but it will have limitations:
The more I thought about it, the more I felt that it’s not the right approach. For multiple registered themes, it could be problematic to maintain. Remember, you can always call the UnistylesRegistry when the user preselects the values required to construct the theme. I’m just not sure if that applies in your case. I would like to hear more about your app and requirements. Thanks! |
Beta Was this translation helpful? Give feedback.
-
How about such API: UnistylesRuntime.updateTheme(keyof UnistylesThemes, Partial<UnistylesThemes[keyof UnistylesThemes]>)
// example
UnistylesRuntime.updateTheme('dynamic', {
colors: {
background: '#ccc',
primary: 'red'
}
}) It would merge the objects underneath with spread operator. Some notes:
Let me know what do think about it |
Beta Was this translation helpful? Give feedback.
Merged & released in 2.2.0