stitchesjs / stitches

[Not Actively Maintained] CSS-in-JS with near-zero runtime, SSR, multi-variant support, and a best-in-class developer experience.
https://stitches.dev
MIT License
7.73k stars 249 forks source link

Cannot import globalStyles in Storybook preview.jsx #1065

Closed kazuyaseki closed 1 year ago

kazuyaseki commented 2 years ago

Bug report

I'm sorry if this is a dumb question, but when I try to use globalStyles of stitches in storybook, it throws an error as follows

Describe the bug

TypeError: (0 , _src_styles_reset_css__WEBPACK_IMPORTED_MODULE_0__.default) is not a function
    at decorators (http://localhost:6006/main.iframe.bundle.js:32:68)
    at http://localhost:6006/vendors-node_modules_storybook_addon-actions_preview_js-generated-config-entry_js-node_module-671d6f.iframe.bundle.js:4064:21
    at http://localhost:6006/vendors-node_modules_storybook_addon-actions_preview_js-generated-config-entry_js-node_module-671d6f.iframe.bundle.js:19420:12
    at http://localhost:6006/vendors-node_modules_storybook_addon-actions_preview_js-generated-config-entry_js-node_module-671d6f.iframe.bundle.js:19478:12
    at http://localhost:6006/vendors-node_modules_storybook_addon-actions_preview_js-generated-config-entry_js-node_module-671d6f.iframe.bundle.js:4094:20
    at unboundStoryFn (http://localhost:6006/vendors-node_modules_storybook_addon-actions_preview_js-generated-config-entry_js-node_module-671d6f.iframe.bundle.js:19120:12)
    at renderWithHooks (http://localhost:6006/vendors-node_modules_storybook_addon-actions_preview_js-generated-config-entry_js-node_module-671d6f.iframe.bundle.js:77520:18)
    at mountIndeterminateComponent (http://localhost:6006/vendors-node_modules_storybook_addon-actions_preview_js-generated-config-entry_js-node_module-671d6f.iframe.bundle.js:81284:13)
    at beginWork (http://localhost:6006/vendors-node_modules_storybook_addon-actions_preview_js-generated-config-entry_js-node_module-671d6f.iframe.bundle.js:82797:16)
    at beginWork$1 (http://localhost:6006/vendors-node_modules_storybook_addon-actions_preview_js-generated-config-entry_js-node_module-671d6f.iframe.bundle.js:88636:14)

To Reproduce

I have preview.jsx like this

import resetStyles from "../src/styles/reset.css";

export const parameters = {
  actions: { argTypesRegex: "^on[A-Z].*" },
  controls: {
    matchers: {
      color: /(background|color)$/i,
      date: /Date$/,
    },
  },
};

export const decorators = [
  (Story) => {
    resetStyles();
    return <Story />;
  },
];

where resetStyles are defined as follows

import { globalCss } from './stitches.config';

export const resetStyles = globalCss({
  ...
});

Expected behavior

I want to know how to apply globalStyles of stitches to storybook without error

Screenshots

スクリーンショット 2022-07-21 1 09 32

System information

ygorluiz commented 2 years ago

@kazuyaseki import it from stitches.config

import {globalStyles } from "../stitches.config"

export const decorators = [
    (Story) => {
        globalStyles();
        return (
            <div>
                <Story />
            </div>
        );
    },
];

stitches.config.ts

export const globalStyles = globalCss({ ... })

kazuyaseki commented 1 year ago

It worked thanks!!