Closed SleeplessOne1917 closed 9 months ago
Here is what you need to do:
The icon!
macro expands the argument, for example ChMenuHamburger
into Icon::from(ChMenu::ChMenuHamburger
.
So in your import statement, just import it like this:
use leptos_icons::{icon, ChIcon, Icon};
and in the macro pass this as an argument:
<Icon icon=icon!(ChMenuHamburger)/>
This should make the macro work. Note that you can take a look at the examples in the example directory.
FYI: This issue totally made me realize that this macro is useless if we export the Enum
variants. Just like how we don't need to write Option::None
, we would not need to write BsIcon::Bs{...}
. When releasing 0.1, (when leptos 0.5) comes out, I will most likely get rid of the macro, and the notation Icon::from({your icon})
instead of having to qualify the enum variant.
I sort of figured out the issue I was having with the icon macro earlier. Suppose I am importing from this library like so:
I try to use an icon like this:
When I run
cargo leptos build
, I get this compiler error:If I import like this:
and use the icon like this:
I get a different compiler error along with an odd warning:
Unused import? I'm using it right there!
I managed to get it to compile by importing like this:
and writing the component like this:
Oddly enough, I still get the unused import warning for ChMenuHamburger.
I doubt this is the way the library is supposed to work, and it will definitely trip up consumers. It certainly confused me.