11use components_core:: { BASE_CLASS , concat} ;
2- use leptos:: prelude:: * ;
2+ use leptos:: { ev :: MouseEvent , prelude:: * } ;
33
44#[ derive( Default , Debug , PartialEq ) ]
55pub enum Variant {
@@ -10,20 +10,25 @@ pub enum Variant {
1010 Icon ,
1111}
1212
13- #[ component( transparent ) ]
13+ #[ component]
1414pub fn Button (
1515 #[ prop( into, optional) ] variant : Variant ,
16- #[ prop( into, optional) ] label : String ,
1716 #[ prop( into, optional) ] class : String ,
18- icon : View < impl IntoView + Send + Sync > ,
17+ on_click : impl FnMut ( MouseEvent ) + ' static ,
18+ #[ prop( into, optional) ] icon : Option < AnyView > ,
19+ #[ prop( into, optional) ] label : Option < String >
1920) -> impl IntoView {
20- let var = format ! ( "{}{variant:?}" , concat!( BASE_CLASS , "-button" , "--" ) ) ;
21+ let var = format ! (
22+ "{}{}" ,
23+ concat!( BASE_CLASS , "-button" , "--" ) ,
24+ format!( "{variant:?}" ) . to_lowercase( )
25+ ) ;
2126 let class = crate :: tw!( "text-button" , var, concat!( BASE_CLASS , "-button" ) , class) ;
2227
2328 view ! {
24- <button class={ class} >
29+ <button class={ class} on : click=on_click >
2530 { ( variant != Variant :: Icon ) . then_some( label) }
26- { ( variant == Variant :: Icon ) . then ( || icon. into_view( ) ) }
31+ { icon. into_view( ) }
2732 </button>
2833 }
2934}
0 commit comments