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

[Feature] : Pass the prop directly to the TailwindCSS #36

Closed
alamenai opened this issue Mar 30, 2024 · 6 comments
Closed

[Feature] : Pass the prop directly to the TailwindCSS #36

alamenai opened this issue Mar 30, 2024 · 6 comments

Comments

@alamenai
Copy link

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]
     }  
  }
}
@The-Code-Monkey
Copy link
Contributor

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
Copy link
Contributor

@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.

@typicode
Copy link
Owner

typicode commented Apr 1, 2024

Hi @alamenai

That's quite smart 👍 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

tailwindlabs/tailwindcss#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

@The-Code-Monkey
Copy link
Contributor

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
Copy link
Contributor

@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.

@typicode
Copy link
Owner

typicode commented Nov 1, 2024

Closing as v1 is quite different. I'm not sure with the current state of CSS that it's possible to do.

@typicode typicode closed this as completed Nov 1, 2024
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

Successfully merging a pull request may close this issue.

3 participants