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

Enable conditional styling for the css prop #242

Merged
merged 4 commits into from
Dec 19, 2024
Merged

Conversation

Mad-Kat
Copy link
Collaborator

@Mad-Kat Mad-Kat commented Dec 18, 2024

This was noticed in #240

With our SWC plugin it should be possible to allow dynamic css properties to a certain extend.

So with this PR this works:

const show = Math.random() > 0.5;
<div
  css={css`
    ${() =>
      show &&
      css`
        padding: 20px;
      `}
  `}
/>

and also css variables:

const show = Math.random() > 0.5;
<div
  css={css`
    padding: ${() => show && '20px'};
  `}
/>

Whereas dynamic css props with their own properties still don't work:

<div
  css={css<{$show: boolean}>` // this won't work
    ${({$show}) =>
      show &&
      css`
        padding: 20px;
      `}
  `}
/>

and also css props that use mixins that define their own props aren't allowed either:

const myMixin = css<{$show: boolean}>`
  ${({$show}) =>
    show &&
    css`
      padding: 20px;
    `}
`;
<div
  css={css`
    ${myMixin} // this won't work
  `}
/>

Copy link

changeset-bot bot commented Dec 18, 2024

🦋 Changeset detected

Latest commit: 4cc9b58

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
next-yak Patch
yak-swc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

codspeed-hq bot commented Dec 18, 2024

CodSpeed Performance Report

Merging #242 will not alter performance

Comparing enable-dynamic-css-prop (4cc9b58) with main (5ce7f16)

Summary

✅ 2 untouched benchmarks

@Mad-Kat Mad-Kat marked this pull request as ready for review December 18, 2024 16:00
@Mad-Kat Mad-Kat requested a review from jantimon December 18, 2024 16:00
jantimon
jantimon previously approved these changes Dec 19, 2024
.changeset/red-rats-double.md Outdated Show resolved Hide resolved
@Mad-Kat Mad-Kat changed the title Enable dynamic css prop Enable conditional styling for the css prop Dec 19, 2024
@Mad-Kat Mad-Kat force-pushed the enable-dynamic-css-prop branch from 87ef4d2 to eca2b30 Compare December 19, 2024 14:37
@Mad-Kat Mad-Kat force-pushed the enable-dynamic-css-prop branch from eca2b30 to f996816 Compare December 19, 2024 14:50
@Mad-Kat Mad-Kat requested a review from jantimon December 19, 2024 14:56
@Mad-Kat Mad-Kat merged commit 2f0ba89 into main Dec 19, 2024
8 checks passed
@Mad-Kat Mad-Kat deleted the enable-dynamic-css-prop branch December 19, 2024 16:27
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 this pull request may close these issues.

2 participants