gaucho-labs / tailwind-fuse

Fuse Tailwind classes and create composite styles

Home Page:https://tailwind-fuse.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Review Variants Macro API

nicoburniske opened this issue · comments

Right now you can only add class attributes, and all errors are propagated via panic! calls to notify the user of invalid setup of the #[TailwindVariant] macro. Take at look at alternative ways to show errors.

https://stackoverflow.com/questions/54392702/how-to-report-errors-in-a-procedural-macro-using-the-quote-macro

Think of how to make this cleaner? Any good features that would be included? Is there anything in class variance authority that isn't possible in this model?

Top of mind, do we need anything more than class? Why is class different between TailwindClass and TailwindVariant?

maybe #[tw(class = "flex flex-col")] would be nicer and more extensible?

#[derive(TailwindClass)]
#[class = "flex items-center"]
struct Btn {
    size: BtnSize,
    color: BtnColor,
}

#[derive(TailwindVariant)]
enum BtnSize {
    #[default]
    #[class("h-9 px-4 py-2")]
    Default,
    #[class("h-8 rounded-md px-3 text-xs")]
    Sm,
    #[class("h-10 rounded-md px-8")]
    Lg,
}

#[derive(TailwindVariant)]
enum BtnColor {
    #[default]
    #[class("bg-blue-500 text-white")]
    Default,
    #[class("bg-red-500 text-white")]
    Red,
}

Use https://github.com/TedDriggs/darling for attribute macro parsing