dioxus_table/
row_renderers.rs1#![allow(non_snake_case)]
2
3use dioxus::events::MouseEvent;
4use dioxus::prelude::*;
5
6#[derive(Props)]
7pub struct DefaultTableRowProps<'a, T: 'a> {
8 #[props(default)]
9 pub class: &'a str,
10
11 pub children: Element<'a>,
12
13 #[props(default)]
14 pub is_head: bool,
15
16 pub index: usize,
17
18 pub item: Option<&'a T>,
19
20 #[props(default)]
21 pub onclick: EventHandler<'a, TableRowEvent<'a, T, MouseEvent>>,
22}
23
24pub struct TableRowEvent<'a, T, E> {
25 pub row_index: usize,
26 pub item: &'a T,
27 pub event: E,
28}
29
30pub fn DefaultTableRowRenderer<'a, T>(cx: Scope<'a, DefaultTableRowProps<'a, T>>) -> Element<'a> {
31 let class = cx.props.class.clone();
32
33 cx.render(rsx! {
34 tr {
35 class: "{class}",
36 onclick: move |evt| {
37 cx.props.onclick.call(TableRowEvent{
38 row_index: cx.props.index,
39 item: cx.props.item.expect("Every row should a have an item"),
40 event: evt,
41 })
42 },
43 &cx.props.children
44 }
45 })
46}