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

compound variant in action for function component #4

Open
kEND opened this issue Jul 26, 2023 · 2 comments
Open

compound variant in action for function component #4

kEND opened this issue Jul 26, 2023 · 2 comments

Comments

@kEND
Copy link

kEND commented Jul 26, 2023

I've been following the docs and been unable to get a compound variant to work. It seems that there may be a level missing or, more likely, I'm complete misunderstanding them.

Any examples you can point to would be great.

Here's what we're doing. We've defined an intent variant on button/1 with several values, e.g. primary, secondary, etc. We've defined a color variant. Our app has two main areas and we differentiate them, in part, based on color.

So, I want a primary red button, I can do <.button intent="primary" color="red" ... My understanding of a compound variant would allow us to specify primary_red in some manner to include classes from both intent="primary" and color="red".

How do we indicate in the instance of the function component that we want a compound variant?

@benvp
Copy link
Owner

benvp commented Jul 28, 2023

If I understand you correctly, that's not quite how compound variants work.

As in the example of the docs, a compound variant will look for already defined variants and apply classes if all other variants match.

 variant :intent, [
      primary: "bg-cyan-600",
      secondary: "bg-gray-200"
    ],
    default: :secondary

  variant :color, [
      red: "text-red-500",
      blue: "text-blue-400"
    ],
    default: :red

  compound_variant "uppercase", intent: :primary, color: :red

This will apply the class uppercase to all components which have the primary intent and the color red.

<.button intent="primary" color="red">Click<./button>
# -> This will add the class `uppercase`

If you just want a red primary button, the way how you are using it is fully correct.

@kEND
Copy link
Author

kEND commented Jul 28, 2023

Awesome! Thank you for clarifying this. I was definitely misunderstanding how the compound variants work.

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

No branches or pull requests

2 participants