mistcss icon indicating copy to clipboard operation
mistcss copied to clipboard

[Feature] : Pass the prop directly to the TailwindCSS

Open alamenai opened this issue 10 months ago • 5 comments

Hi @typicode ,

Thank you for this new library.

I like the idea of generating components from CSS instead of integrating CSS in JS.

Honestly, adding CSS to JS is kind of a mess.

I already started using the library (or tool), however, while I was trying to discover the syntax, an idea came to me and I wanted to share it if it is possible to implement it.

@scope (.button) {
  button:scope {
    /* Default style */
    @apply text-base rounded-sm;

    &[data-size='lg'] {
      @apply text-lg;
    }

    &[data-size='sm'] {
      @apply text-sm;
    }

    &[data-danger] {
      @apply bg-red-700 text-white;
    }
  }
}

In the code above, yu see that we repeating the prop checking to apply the TailwidCSS, is it possible to make it like this :

@scope (.button) {
  button:scope {
    /* Default style */
    @apply text-base rounded-sm;
    &[data-size]{
     @apply text-[data-size]
     }  
  }
}

alamenai avatar Mar 30 '24 22:03 alamenai

Not currently possible @alamenai as text-[sm] doesn't work as far as I am aware in Tailwind. As Tailwind would treat sm as a custom value and add that to the styles.

The-Code-Monkey avatar Mar 31 '24 11:03 The-Code-Monkey

@alamenai I will take a look into this as playing with tailwind v4 the apply directive is deprecated so i will have to see if there is a better solution.

The-Code-Monkey avatar Apr 01 '24 07:04 The-Code-Monkey

Hi @alamenai

That's quite smart :+1: However, one of the design goal of MistCSS that I'd like to keep is not have to transform CSS, just pure CSS.

Regarding @apply, they're recommending theme() instead AFAIK

https://github.com/tailwindlabs/tailwindcss/discussions/13064

.card {
  background-color: theme(colors.white);
  border-radius: theme(borderRadius.lg);
  padding: theme(spacing.6);
  box-shadow: theme(boxShadow.xl);
}

It would be great if the Tailwind example in the doc could be updated though. https://github.com/typicode/mistcss/blob/main/docs/getting-started.md

typicode avatar Apr 01 '24 09:04 typicode

Yeah I agree with what @typicode said I completely forgot they added theme, I will write a v4 section into the tailwind docs,

In regards to dynamic stuff like that I would say it should be done using the classname param rather than adding some complex dynamics into the renderer.

The-Code-Monkey avatar Apr 01 '24 10:04 The-Code-Monkey

@typicode @alamenai I believe I have just come across the same need for this functionality, I also think I may have come up with a possible solution, I will open a separate ticket as my solution currently has another limitation.

The-Code-Monkey avatar Apr 03 '24 07:04 The-Code-Monkey