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

wrong sequence when generate storybook styles #37

Closed
Jasenpan1987 opened this issue Nov 9, 2021 · 4 comments
Closed

wrong sequence when generate storybook styles #37

Jasenpan1987 opened this issue Nov 9, 2021 · 4 comments

Comments

@Jasenpan1987
Copy link

Jasenpan1987 commented Nov 9, 2021

we are using tss-react to work with storybook,

this is the preview.js file

import React from "react";
import { ThemeProvider } from "@mui/material/styles";
import { ThemeProvider as Emotion10ThemeProvider } from "emotion-theming";
import { Themes } from "../src/theme";
import { CssBaseline } from "@mui/material";

export const parameters = {
  actions: { argTypesRegex: "^on[A-Z].*" },
  controls: {
    matchers: {
      color: /(background|color)$/i,
      date: /Date$/i
    }
  },
  docs: {
    source: { type: "dynamic", excludeDecorators: true },
    inlineStories: false,
    iframeHeight: "700px"
  }
};

const withThemeProvider = (Story, context) => {
  return (
    <Emotion10ThemeProvider theme={Themes.Default}>
      <ThemeProvider theme={Themes.Default}>
        <CssBaseline />
        <Story {...context} />
      </ThemeProvider>
    </Emotion10ThemeProvider>
  );
};

export const decorators = [withThemeProvider];

in one of the component I override the chip style like this

const useStyles = makeStyles()(
  ({ palette }) => ({
    root: {
      border: "0.1rem solid",
      textAlign: "center",
      padding: "0 0.5rem",
      borderRadius: "0.2rem",
      whiteSpace: "nowrap",
      borderColor: "#ff0000",
      backgroundColor: "#ffffff",
      color: "#ff0000"
    }
  })
);

const CustomChip = ({
  text,
}: {
  text: string;
}) => {
  const { classes, cx } = useStyles();

  return (
    <Typography variant="body2" className={classes.root}>
      {text}
    </Typography>
  );
};

when it builds I got two css classes for that element:

.css-1vjo9lu {
    margin: 0px;
    font-size: 1.4rem;
    line-height: 1.71;
    color: rgb(38, 50, 56);
    letter-spacing: normal;
    font-weight: 400;
    font-family: "Cera Pro", sans-serif;
}

.tss-1ev1aua {
    border: 0.1rem
    solid rgb(0, 104, 200);
    text-align: center;
    padding: 0px 0.5rem;
    border-radius: 0.2rem;
    white-space: nowrap;
    background-color: rgb(255, 255, 255);
    color: rgb(0, 104, 200);
}

The first css class was the mui typography override and the second one was the makestyle override in the component.
The issue is the color should be the one in makestyle but it takes the typography color.

Please let me know where we did it wrong or this is a bug in storybook or tss-react.

Many thanks.

@garronej
Copy link
Owner

garronej commented Nov 9, 2021

Hi @Jasenpan1987,

Have you see this note in the REAMDE:

image

@garronej
Copy link
Owner

garronej commented Nov 9, 2021

There is a working setup here if it can help.

@Jasenpan1987
Copy link
Author

Thanks a lot @garronej
we follow the setup step by step, and it works

@garronej
Copy link
Owner

Storybook is often a pain to get working properly

gitbook-com bot pushed a commit that referenced this issue Jan 26, 2022
gitbook-com bot pushed a commit that referenced this issue Oct 2, 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