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

Duplicated styles within dynamic classes #546

Open
RainArroDev opened this issue May 13, 2023 · 0 comments
Open

Duplicated styles within dynamic classes #546

RainArroDev opened this issue May 13, 2023 · 0 comments

Comments

@RainArroDev
Copy link

RainArroDev commented May 13, 2023

Can this type of syntax be written differently so the outputted classes would not have duplicated content?
In the example font-size: 16px; is duplicated between classes.

Input

const ButtonTheme = (theme: Colors) => {
  const _theme = useTheme();

  return {
    primary: `
      background: ${_theme.colors.primary};
      &:hover {
        color: red;
      }
    `,
    secondary: `
      background: ${_theme.colors.secondary};
    `,
  }[theme];
};

export const ButtonBase = (props: { theme?: Colors }) => {
  return css`
    font-size: 16px;
    ${ButtonTheme(props.theme || 'primary')}
  `;
};

Output

<style id="_goober">
            .go1767598017 {
                font-size: 16px;
                background: #0066ff;
            }

            .go1767598017:hover {
                color: red;
            }

            .go1138492251 {
                font-size: 16px;
                background: #43aa8b;
            }
 </style>    
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

1 participant