@@ -4,39 +4,79 @@ use leptos_struct_table::*;
44const ROW_HEIGHT : usize = 30 ;
55const ROW_HEIGHT_HALF : usize = ROW_HEIGHT / 2 ;
66
7- #[ allow( unused_variables) ]
8- #[ component]
9- pub fn SvgRowRenderer < F , K > (
10- #[ prop( into) ] class : MaybeSignal < String > ,
11- #[ prop( into) ] key : K ,
7+ wrapper_render_fn ! (
8+ /// g
9+ GRenderer ,
10+ g,
11+ ) ;
12+
13+ #[ allow( unused_variables, non_snake_case) ]
14+ pub fn SvgRowRenderer < Row > (
15+ class : Signal < String > ,
16+ row : Row ,
1217 index : usize ,
13- # [ prop ( into ) ] selected : Signal < bool > ,
14- on_click : F ,
15- children : Children ,
18+ selected : Signal < bool > ,
19+ on_select : EventHandler < web_sys :: MouseEvent > ,
20+ on_change : EventHandler < ChangeEvent < Row > > ,
1621) -> impl IntoView
1722where
18- F : Fn ( TableRowEvent < K > ) + ' static ,
19- K : Clone + ' static ,
23+ Row : RowRenderer + Clone + ' static ,
2024{
2125 let transform = format ! ( "translate(0, {})" , ( index + 1 ) * ROW_HEIGHT ) ;
2226
2327 view ! {
24- <g class=class
28+ <g
29+ class=class
2530 transform=transform
26- on: click=move |mouse_event| on_click( TableRowEvent {
27- key: key. clone( ) ,
28- index,
29- mouse_event,
30- } )
31+ on: click=move |mouse_event| on_select. run( mouse_event)
3132 >
32- <line x1="5" y1="0" x2="150" y2="0" stroke-width="1px" stroke="black" opacity="0.1" />
33- { children( ) }
33+ <line
34+ x1="5"
35+ y1="0"
36+ x2="150"
37+ y2="0"
38+ stroke-width="1px"
39+ stroke="black"
40+ opacity="0.1"
41+ ></line>
42+ { row. render_row( index, on_change) }
43+ </g>
44+ }
45+ }
46+
47+ #[ allow( non_snake_case) ]
48+ pub fn SvgErrorRowRenderer ( err : String , index : usize , _col_count : usize ) -> impl IntoView {
49+ let transform = transform_from_index ( index, 0 ) ;
50+
51+ view ! {
52+ <g transform=transform>
53+ <text x="0" y=ROW_HEIGHT_HALF dominant-baseline="central" >
54+ { err}
55+ </text>
56+ </g>
57+ }
58+ }
59+
60+ #[ allow( non_snake_case) ]
61+ pub fn SvgLoadingRowRenderer (
62+ class : Signal < String > ,
63+ inner_class : Signal < String > ,
64+ index : usize ,
65+ _col_count : usize ,
66+ ) -> impl IntoView {
67+ let transform = transform_from_index ( index, 0 ) ;
68+
69+ view ! {
70+ <g class=class transform=transform>
71+ <text x="0" y=ROW_HEIGHT_HALF class=inner_class dominant-baseline="central" >
72+ Loading ...
73+ </text>
3474 </g>
3575 }
3676}
3777
3878#[ component]
39- pub fn SvgHeadCellRenderer < C , F > (
79+ pub fn SvgHeadCellRenderer < F > (
4080 /// The class attribute for the head element. Generated by the classes provider.
4181 #[ prop( into) ]
4282 class : Signal < String > ,
@@ -45,8 +85,6 @@ pub fn SvgHeadCellRenderer<C, F>(
4585 inner_class : String ,
4686 /// The index of the column. Starts at 0 for the first column. The order of the columns is the same as the order of the fields in the struct.
4787 index : usize ,
48- /// The column enum variant. It is auto generated from the struct.
49- column : C ,
5088 /// The sort priority of the column. `None` if the column is not sorted. `0` means the column is the primary sort column.
5189 #[ prop( into) ]
5290 sort_priority : Signal < Option < usize > > ,
@@ -58,8 +96,7 @@ pub fn SvgHeadCellRenderer<C, F>(
5896 children : Children ,
5997) -> impl IntoView
6098where
61- F : Fn ( TableHeadEvent < C > ) + ' static ,
62- C : ' static + Copy ,
99+ F : Fn ( TableHeadEvent ) + ' static ,
63100{
64101 let style = move || {
65102 let sort = match sort_direction ( ) {
@@ -79,13 +116,14 @@ where
79116 let transform = transform_from_index ( index, 0 ) ;
80117
81118 view ! {
82- <g class=class
119+ <g
120+ class=class
83121 transform=transform
84122 on: click=move |mouse_event| on_click( TableHeadEvent {
85123 index,
86- column,
87124 mouse_event,
88125 } )
126+
89127 style=style
90128 >
91129 <text x="0" y=ROW_HEIGHT_HALF class=inner_class dominant-baseline="central" >
@@ -98,26 +136,28 @@ where
98136#[ component]
99137#[ allow( unused_variables) ]
100138pub fn SvgTextCellRenderer < T , F > (
101- # [ prop ( into ) ] class : MaybeSignal < String > ,
139+ class : String ,
102140 #[ prop( into) ] value : MaybeSignal < T > ,
103141 on_change : F ,
104142 index : usize ,
105143) -> impl IntoView
106144where
107145 T : IntoView + Clone + ' static ,
108- F : Fn ( String ) + ' static ,
146+ F : Fn ( T ) + ' static ,
109147{
110148 let x = x_from_index ( index) ;
111149
112150 view ! {
113- <text x=x y=ROW_HEIGHT_HALF class=class dominant-baseline="central" >{ value} </text>
151+ <text x=x y=ROW_HEIGHT_HALF class=class dominant-baseline="central" >
152+ { value}
153+ </text>
114154 }
115155}
116156
117157#[ component]
118158#[ allow( unused_variables) ]
119159pub fn SvgPathCellRenderer < F > (
120- #[ prop( into) ] class : MaybeSignal < String > ,
160+ #[ prop( into) ] class : String ,
121161 #[ prop( into) ] value : MaybeSignal < String > ,
122162 on_change : F ,
123163 index : usize ,
@@ -127,9 +167,7 @@ where
127167{
128168 let transform = transform_from_index ( index, 3 ) ;
129169
130- view ! {
131- <path transform=transform class=class d=value />
132- }
170+ view ! { <path transform=transform class=class d=value></path> }
133171}
134172
135173fn transform_from_index ( index : usize , y : usize ) -> String {
0 commit comments