tailwindcss icon indicating copy to clipboard operation
tailwindcss copied to clipboard

Update Types to allow an array of CSSRuleObjects

Open moshie opened this issue 1 year ago • 1 comments

When generating tailwind css to js using prejss it combines sections in an array which tailwind's types are not happy with.

"@supports (color: oklch(0% 0 0))": [
      {
        ".btn": {
          "backgroundColor": "var(--btn-color, var(--zui-primary-button))",
          "borderColor": "var(--btn-color, var(--zui-primary-button))"
        }
      },
      {
        ".btn-primary": {
          "-BtnColor": "var(--primary-button)"
        }
      }
    ],

I propose we update the type to allow for CSSRuleObjects[]

related to: #14054

moshie avatar Sep 04 '24 20:09 moshie

Thoughts?

moshie avatar Sep 09 '24 07:09 moshie

Hey!

While this works, I would recommend to use 2 sibling rules instead of the array syntax. We allow the array syntax at "runtime" for backwards compatibility reasons, but the proper way to do this is to use normal objects:

addComponents({
  '@supports (color: oklch(0% 0 0))': {
    '.btn': {
      backgroundColor: 'var(--btn-color, var(--zui-primary-button))',
      borderColor: 'var(--btn-color, var(--zui-primary-button))',
    },
    '.btn-primary': {
      '--btn-color': 'var(--primary-button)',
    },
  },
})

Example: https://play.tailwindcss.com/SYZAmHUI8p?file=config

Going to close this for now because there are better solutions, but I appreciate the PR!

Thanks!

RobinMalfait avatar Jan 28 '25 15:01 RobinMalfait