Skip to content

Function in theme break CSS properties#49

Description

@mikaelkarlsson-se

Hello there! 馃憢
I have a couple of functions in my theme and since installing this addon they unfortunately do not work within the Storybook context. My guess is that the addon can't handle functions and they are therefore not executed, in the end resulting in the CSS properties using the functions to be removed.
As example, one of my functions is theme.spacing() that is used to calculate values for paddings, margins etc but those CSS properties are no longer generated.

An example is my Button component that lack a gap property, resulting in no space between the text and arrow icon:
Screenshot 2022-02-09 at 14 43 01

// Some of the button styles
const buttonWithIcon = (theme: Theme) => css`
    display: grid;
    grid-auto-flow: column;
    gap: ${theme.spacing(2)}; // Works just fine then the addon isn't active
    justify-content: space-between;
    align-items: center;
// Simplified theme
const theme = {
  ...someProperties,
  spacing(factor) { return `${factor * 4}px` }
}
// preview.js in SB
const providerFn = ({ theme, children }) => (
    <ThemeProvider theme={theme}>
        {children}
    </ThemeProvider>
);

export const decorators = [withThemes(null, [{ name: "Default theme", ...defaultTheme }], { providerFn })];

I'm using SB 6.5 (still in alpha release), Emotion 11 and v1.1.5 of this addon.
I've tried to create a Codesandbox but not yet succeeded, will try to get back to you with one.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions