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

automatically inject :global #53

Open
jantimon opened this issue Feb 1, 2024 · 1 comment
Open

automatically inject :global #53

jantimon opened this issue Feb 1, 2024 · 1 comment
Assignees

Comments

@jantimon
Copy link
Owner

jantimon commented Feb 1, 2024

next-yak automatically uses css modules behind the scenes and in nextjs css modules are local by default.
this means that selectors e.g. html.dark-mode will be scoped automatically to the component

for example

const StyledDiv = styled.div`
  background-color: #f0f0f0;
  html.dark-mode & {
    background-color: #000;
  }
`;

becomes

.StyledDiv-be2f45 {
  background-color: #f0f0f0;
  html.dark-mode-a4e345 & {
    background-color: #000;
  }
}

so although the user wrote html.dark-mode it would NOT match.

as this is unintuitive for most users and therefore next-yak should automatically inject :global

@jantimon
Copy link
Owner Author

I guess there are multiple cases:

  1. String - (should be global)
const Bar = styled.div`.Foo { ... }`
  1. Same file component - (should be local)
const Foo = styled.div``;
const Bar = styled.div`${Foo} { ... }`
  1. Constant - (should be global)
const darkMode = ".darkMode";
const Bar = styled.div`${darkMode} { ... }`

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

Successfully merging a pull request may close this issue.

2 participants