-
Notifications
You must be signed in to change notification settings - Fork 4
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
dynamic css property name can't generate expected css #20
Comments
hey @await-ovo thanks for your feedback! right now dynamic property values are using css variables under the hood. so for example const Title = styled.h1`
font-size: 1.5em;
text-align: center;
color: #BF4F74;
height: ${someValue}
`; is compiled to the following static css: .generated-class-name {
font-size: 1.5em;
text-align: center;
color: #BF4F74;
height: var(--some-value);
} Unfortunately css does allows dynamic properties only for values but not for names. So for now the only work around is: const Title = styled.h1`
font-size: 1.5em;
text-align: center;
color: #BF4F74;
${property === "height" ? css`height: 40px` : css`width: 40px`}
`; |
@await-ovo we might add a way to allow this feature - could you please give a more realistic example? :) |
Sorry, I don't have a real use case for this at the moment, I was just curious if next-yak could support this pattern. But I do have a real use case that may not be related to the above ( whick is called component selector in styled components.):
|
apologies for the delay in getting back to you! first off, thanks for bringing up a real use case :) one approach you can consider is using unique identifiers or class names for your components and then targeting them in your yak styles. panda actually recommends this way however, we understand that this might not be the most developer-friendly experience. in fact, we weren't completely satisfied with this approach, so we ventured into finding an alternative solution good news: we managed to allow targeting components inside the same file - see pr #33. cross-file targeting is a bit trickier due to module resolution, side effects, and barrel files so we excluded it (at least for now). import { Link } from "./some/other/file";
const CustomLink = styled(Link)``;
const Icon = styled.svg`
flex: none;
transition: fill 0.25s;
width: 48px;
height: 48px;
${CustomLink}:hover & {
fill: rebeccapurple;
}
`;
export const Demo = () => (
<CustomLink>
<Icon />
</CustomLink>
); if you have more questions or if there's anything else we can help you with let us know :) |
Thank you for such a detailed response, this looks fantastic! |
Released with next-yak 0.0.17 https://stackblitz.com/edit/stackblitz-starters-m1vwbv?file=app%2FLogo.tsx |
Let's say we have a styled component like following:
it seems that it will generate css uncorrectly:
I'm not sure if this usage is supported(It's true that this usage should be relatively rare), in styled-components it's ok
The text was updated successfully, but these errors were encountered: