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

Cross reference using classNames #201

Closed
alexrah opened this issue Nov 6, 2024 · 5 comments
Closed

Cross reference using classNames #201

alexrah opened this issue Nov 6, 2024 · 5 comments

Comments

@alexrah
Copy link

alexrah commented Nov 6, 2024

in styled-component
ref: Pseudoelements, pseudoselectors, and nesting

the following code is valid:

const HeadingLiteral = styled.h2`
  &.solid-variant {
  font-weight: bold;
  }
  
  & .child-item {
    color: red;
  }  
`

but it doesn't seem to work in next-yak

demo repo

Do you have any plan of adding this feature?

@Mad-Kat
Copy link
Collaborator

Mad-Kat commented Nov 6, 2024

Hey @alexrah

Thank you so much for your time to investigate and opening an issue. I had a quick look and it looks like you want to mix classes outside of next-yak with component styles managed by yak. As next-yak compiles the CSS under the hood to css-modules, you would need to specify the selectors the same way as you would do it in css-modules (related documentation from css-modules).

For your case that would mean that you would have to write it like this:

const Heading = styled.h2`
  background-color: cyan;

  &:global(.solid-variant) {
    color: purple;
  }

  & :global(.child-item) {
    color: red;
  }
`;

We definitely need to add this to our documentation! I will keep the issue open until that is merged

@alexrah
Copy link
Author

alexrah commented Nov 6, 2024

Thanks for your explanation, I didn't play with CSS modules enough to know about it.

@jantimon
Copy link
Collaborator

jantimon commented Nov 7, 2024

@alexrah I guess you directly stumbled across a tricky problem - we have an issue to inject :global automatically: #53

However it is not that easy to do it correctly so we put in hold for now

Feel free to ask any further questions here - is it okay for you to close this issue?

@alexrah
Copy link
Author

alexrah commented Nov 7, 2024

No problem at all for me, but I think would be better to highlight this pattern in the documentation, perhaps in Migration from styled-components considering [#53] I don't see an easy path to solve this neither by codemod once during migration or by automatic injection.

@jantimon jantimon closed this as completed Nov 8, 2024
@jantimon
Copy link
Collaborator

jantimon commented Nov 8, 2024

Thanks we will update the documentation soon

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

No branches or pull requests

3 participants