ben-rogerson / twin.macro

🦹‍♂️ Twin blends the magic of Tailwind with the flexibility of css-in-js (emotion, styled-components, solid-styled-components, stitches and goober) at build time.
MIT License
7.92k stars 183 forks source link

Fix spreadVariantGroups regex #702

Closed mohammadsiyou closed 2 years ago

mohammadsiyou commented 2 years ago

Typically Tailwind detects '!' before class name and after all variants.

The ! always goes at the beginning of the utility name, after any variants, but before any prefix:

<div class="sm:hover:!tw-font-bold">

But twin just detect '!' at the end of class name.So lets compare the output of two same twin classes:

input:

tw`sm:block! sm:hover:block`

output:

({
  "@media (min-width: 640px)": {
    "display": "block !important",
    ":hover": {
      "display": "block"
    }
  }
});

and

input:

tw`sm:!block sm:hover:block`

output:

({
  "@media (min-width: 640px)": {
    "display": "block !important",
    "@media (min-width: 640px)": {
      ":hover": {
        "display": "block"
      }
    }
  }
});

so in order to twin works in both situation we must change regex at spreadVariantGroups a little bit!

ben-rogerson commented 2 years ago

Nice work finding and fixing this - it's going in!

ben-rogerson commented 2 years ago

Nice work finding and fixing this - it's going in!