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

Theme values gets stripped down #55

Closed
Ptichi opened this issue Mar 22, 2022 · 2 comments
Closed

Theme values gets stripped down #55

Ptichi opened this issue Mar 22, 2022 · 2 comments

Comments

@Ptichi
Copy link

Ptichi commented Mar 22, 2022

We're using themes according to styled-system theme specification: https://styled-system.com/theme-specification#scale-aliases

For example, we define fields like this, which combines numeric indexes with string keys as aliases:

theme.fontSizes = ['12', '16,' '20'];
theme.fontSizes.sm = theme.fontSizes[0];
theme.fontSizes.md = theme.fontSizes[1];
theme.fontSizes.lg = theme.fontSizes[2];

This works in regular usages, but on Storybook (with the addon) the aliases keys are stripped down and all we're getting is the numeric indexes:

['12', '16,' '20'];

When debugging, I saw that initially, we have those aliases, but on rerender (on the 2nd hit of the debugger, which occurs immediately) the aliases disappear.

Any idea why this is happening?

@usulpro
Copy link
Member

usulpro commented Apr 16, 2022

@Ptichi I didn't clearly get the problem. ['12', '16,' '20']; - isn't this what you expected to get?
Try to consider that the theme object you see in the theme panel is serialized when passing between theme provider and panel. You can lost some fields on serialization. In general, the best way to solve the issues like this is to pass to addon only a plain JS object and then reconstruct a theme via a custom providerFn function. See https://github.com/react-theming/storybook-addon#using-with-material-ui example

@Ptichi
Copy link
Author

Ptichi commented Apr 17, 2022

@usulpro
The serialization is probably causing those fields to disappear.
I was able to fix that by providing a providerFn as you suggested.
Thanks!

@Ptichi Ptichi closed this as completed Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants