macaron-css / macaron

Compiler-augmented typesafe CSS-in-JS with zero runtime, colocation, maximum safety and productivity
https://macaron.js.org/
MIT License
749 stars 16 forks source link

[Documentation] Lack of docs for compoundVariants option #53

Closed dhutaryan closed 6 months ago

dhutaryan commented 6 months ago

Hello, I'm trying yo use compoundVariants option because it's very useful in my case. I guess it should work the similar as in stitches but I didn't find any examples in documentation. Could you add some?

Mokshit06 commented 6 months ago

Hi! compoundVariants do indeed work very similar to how they do in stitches. The docs still need some work with more examples, but there's one on the home page itself https://macaron.js.org/

const Button = styled('button', {
  base: {
    borderRadius: 6,
  },
  variants: {
    color: {
      neutral: { background: 'whitesmoke' },
      accent: { background: 'slateblue' },
    },
    rounded: {
      true: { borderRadius: 999 },
    },
  },
  compoundVariants: [
    {
      variants: {
        color: 'neutral',
        rounded: true,
      },
      style: { background: 'ghostwhite' },
    },
  ],
  defaultVariants: {
    color: 'accent',
  },
});

So here when the variants color=neutral and rounded=true are applied at the same time, the background color would get set to ghostwhite :)