@@ -3,7 +3,14 @@ mod menu_item;
3
3
pub use menu_item:: * ;
4
4
5
5
use crate :: ConfigInjection ;
6
- use leptos:: { context:: Provider , ev, html:: Div , leptos_dom:: helpers:: TimeoutHandle , prelude:: * } ;
6
+ use leptos:: {
7
+ context:: Provider ,
8
+ ev:: { self , on} ,
9
+ html:: Div ,
10
+ leptos_dom:: helpers:: TimeoutHandle ,
11
+ prelude:: * ,
12
+ tachys:: html:: { class:: class as tachys_class, node_ref:: node_ref} ,
13
+ } ;
7
14
use std:: time:: Duration ;
8
15
use thaw_components:: { Binder , CSSTransition , Follower , FollowerPlacement } ;
9
16
use thaw_utils:: {
@@ -12,17 +19,15 @@ use thaw_utils::{
12
19
} ;
13
20
14
21
#[ slot]
15
- pub struct MenuTrigger {
16
- #[ prop( optional, into) ]
17
- class : MaybeProp < String > ,
18
- children : Children ,
22
+ pub struct MenuTrigger < T > {
23
+ children : TypedChildren < T > ,
19
24
}
20
25
21
26
#[ component]
22
- pub fn Menu (
27
+ pub fn Menu < T > (
23
28
#[ prop( optional, into) ] class : MaybeProp < String > ,
24
29
/// The element or component that triggers menu.
25
- menu_trigger : MenuTrigger ,
30
+ menu_trigger : MenuTrigger < T > ,
26
31
/// Action that displays the menu.
27
32
#[ prop( optional) ]
28
33
trigger_type : MenuTriggerType ,
@@ -34,12 +39,15 @@ pub fn Menu(
34
39
on_select : BoxOneCallback < String > ,
35
40
#[ prop( optional, into) ] appearance : MaybeProp < MenuAppearance > ,
36
41
children : Children ,
37
- ) -> impl IntoView {
42
+ ) -> impl IntoView
43
+ where
44
+ T : AddAnyAttr + IntoView + Send + ' static ,
45
+ {
38
46
mount_style ( "menu" , include_str ! ( "./menu.css" ) ) ;
39
47
let config_provider = ConfigInjection :: expect_context ( ) ;
40
48
41
49
let menu_ref = NodeRef :: < Div > :: new ( ) ;
42
- let target_ref = NodeRef :: < Div > :: new ( ) ;
50
+ let target_ref = NodeRef :: < thaw_utils :: Element > :: new ( ) ;
43
51
let is_show_menu = RwSignal :: new ( false ) ;
44
52
let show_menu_handle = StoredValue :: new ( None :: < TimeoutHandle > ) ;
45
53
@@ -91,7 +99,6 @@ pub fn Menu(
91
99
} ) ;
92
100
93
101
let MenuTrigger {
94
- class : trigger_class,
95
102
children : trigger_children,
96
103
} = menu_trigger;
97
104
@@ -105,14 +112,13 @@ pub fn Menu(
105
112
106
113
view ! {
107
114
<Binder >
108
- <div
109
- class=class_list![ "thaw-menu-trigger" , trigger_class]
110
- node_ref=target_ref
111
- on: mouseenter=on_mouse_enter
112
- on: mouseleave=on_mouse_leave
113
- >
114
- { trigger_children( ) }
115
- </div>
115
+ { trigger_children
116
+ . into_inner( ) ( )
117
+ . into_inner( )
118
+ . add_any_attr( tachys_class( ( "thaw-menu-trigger" , true ) ) )
119
+ . add_any_attr( node_ref( target_ref) )
120
+ . add_any_attr( on( ev:: mouseenter, on_mouse_enter) )
121
+ . add_any_attr( on( ev:: mouseleave, on_mouse_leave) ) }
116
122
<Follower slot show=is_show_menu placement=position>
117
123
<Provider value=menu_injection>
118
124
<CSSTransition
0 commit comments