1+ use leptos:: html:: AnyElement ;
2+ use leptos:: svg:: G ;
13use leptos:: * ;
24use leptos_struct_table:: * ;
35
@@ -10,6 +12,18 @@ wrapper_render_fn!(
1012 g,
1113) ;
1214
15+ #[ allow( non_snake_case) ]
16+ pub fn SvgTbodyRenderer (
17+ content : Fragment ,
18+ class : Signal < String > ,
19+ node_ref : NodeRef < AnyElement > ,
20+ ) -> impl IntoView {
21+ let tbody_ref = create_node_ref :: < G > ( ) ;
22+ tbody_ref. on_load ( move |e| node_ref. load ( & e. into_any ( ) ) ) ;
23+
24+ view ! { <g class=class node_ref=tbody_ref>{ content} </g> }
25+ }
26+
1327#[ allow( unused_variables, non_snake_case) ]
1428pub fn SvgRowRenderer < Row > (
1529 class : Signal < String > ,
@@ -19,10 +33,10 @@ pub fn SvgRowRenderer<Row>(
1933 on_select : EventHandler < web_sys:: MouseEvent > ,
2034 on_change : EventHandler < ChangeEvent < Row > > ,
2135) -> impl IntoView
22- where
23- Row : TableRow + Clone + ' static ,
36+ where
37+ Row : TableRow + Clone + ' static ,
2438{
25- let transform = format ! ( "translate(0, {})" , ( index + 1 ) * ROW_HEIGHT ) ;
39+ let transform = y_transform_from_index ( index) ;
2640
2741 view ! {
2842 <g
4458 }
4559}
4660
61+ fn y_transform_from_index ( index : usize ) -> String {
62+ format ! ( "translate(0, {})" , ( index + 1 ) * ROW_HEIGHT )
63+ }
64+
4765#[ allow( non_snake_case) ]
4866pub fn SvgErrorRowRenderer ( err : String , index : usize , _col_count : usize ) -> impl IntoView {
49- let transform = transform_from_index ( index, 0 ) ;
67+ let transform = y_transform_from_index ( index) ;
5068
5169 view ! {
5270 <g transform=transform>
@@ -65,7 +83,7 @@ pub fn SvgLoadingRowRenderer(
6583 index : usize ,
6684 _col_count : usize ,
6785) -> impl IntoView {
68- let transform = transform_from_index ( index, 0 ) ;
86+ let transform = y_transform_from_index ( index) ;
6987
7088 view ! {
7189 <g class=class transform=transform>
@@ -96,8 +114,8 @@ pub fn SvgHeadCellRenderer<F>(
96114 on_click : F ,
97115 children : Children ,
98116) -> impl IntoView
99- where
100- F : Fn ( TableHeadEvent ) + ' static ,
117+ where
118+ F : Fn ( TableHeadEvent ) + ' static ,
101119{
102120 let style = move || {
103121 let sort = match sort_direction ( ) {
@@ -142,9 +160,9 @@ pub fn SvgTextCellRenderer<T, F>(
142160 on_change : F ,
143161 index : usize ,
144162) -> impl IntoView
145- where
146- T : IntoView + Clone + ' static ,
147- F : Fn ( T ) + ' static ,
163+ where
164+ T : IntoView + Clone + ' static ,
165+ F : Fn ( T ) + ' static ,
148166{
149167 let x = x_from_index ( index) ;
150168
@@ -163,8 +181,8 @@ pub fn SvgPathCellRenderer<F>(
163181 on_change : F ,
164182 index : usize ,
165183) -> impl IntoView
166- where
167- F : Fn ( String ) + ' static ,
184+ where
185+ F : Fn ( String ) + ' static ,
168186{
169187 let transform = transform_from_index ( index, 3 ) ;
170188
0 commit comments