leuchtturm-dev / turboprop

MIT License
54 stars 4 forks source link

Variants not picked correctly in some cases #29

Open sezaru opened 3 months ago

sezaru commented 3 months ago

I have the following variant:

  def button do
    [
      slots: [
        base: """
        focus:ring-2 font-medium
        """,
        left_icon: "text-white me-2 block"
      ],
      variants: [
        loading?: [
          true: "SOME_CLASS"
        ]
      ],
      default_variants: [
        loading?: false
      ]
    ]
  end

When I run:

 Turboprop.Variants.variant(UI.Button.button(), slot: :base, loading?: true)

I correctly get:

"focus:ring-2 font-medium SOME_CLASS"

But, if i try to do the same with the :left_icon slot, the SOME_CLASS will not be present:

Turboprop.Variants.variant(UI.Button.button(), slot: :left_icon, loading?: true)
"text-white me-2 block"

Now, if I change the loading? variant to this:

        loading?: [
          true: [
            base: "SOME_CLASS",
            left_icon: "SOME_OTHER_CLASS"
          ]
        ]

Now the :base slot will not contain the loading? variant:

Turboprop.Variants.variant(UI.Button.button(), slot: :base, loading?: true)
"focus:ring-2 font-medium"

And the :left_icon slot will contain it:

Turboprop.Variants.variant(UI.Button.button(), slot: :left_icon, loading?: true)
"text-white me-2 block SOME_OTHER_CLASS"

I expect that in both cases, the loading? variant would be present in both slots.