fresh icon indicating copy to clipboard operation
fresh copied to clipboard

Tailwind classes in Components

Open sebilasse opened this issue 1 year ago • 2 comments

Hello, changed everything from twind to tailwind.

Maybe it could be documented that currently all classes in components need to be named explicitly.

Let's say I have an encoded link component for mailto: or tel: links and it has

interface {
  type?: 'mail'|'phone'
}

This will not work:

  <a class={`redaktor-link-${type}`}></a>

but this would

  <a class={type === 'phone' ? `redaktor-link-phone` : `redaktor-link-mail`}></a>

Not sure if this could be done with the reflection API or if there are better ideas :)

sebilasse avatar Aug 22 '24 09:08 sebilasse

Good point, compared to twind, tailwind analyses the source code instead of running it. It cannot detect split up tailwind class names. We should add a note for that in our docs.

marvinhagemeister avatar Aug 22 '24 10:08 marvinhagemeister

If we have more class-choices than just two, one can also create a plugin, see https://tailwindcss.com/docs/plugins#dynamic-utilities

Done that a lot, works fine, got e.g.: baseline solid typo and ui variants and all the colors and ActivityPub stuff. Will keep you updated :)

sebilasse avatar Aug 22 '24 15:08 sebilasse