leptos_struct_table/components/row.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
use crate::table_row::TableRow;
use crate::EventHandler;
use leptos::prelude::*;
/// The default table row renderer. Uses the `<tr>` element. Please note that this
/// is **NOT** a `#[component]`.
#[allow(unused_variables)]
pub fn DefaultTableRowRenderer<Row>(
// The class attribute for the row element. Generated by the classes provider.
class: Signal<String>,
// The row to render.
row: RwSignal<Row>,
// The index of the row. Starts at 0 for the first body row.
index: usize,
// The selected state of the row. True, when the row is selected.
selected: Signal<bool>,
// Event handler callback when this row is selected
on_select: EventHandler<web_sys::MouseEvent>,
) -> impl IntoView
where
Row: TableRow + 'static,
{
view! {
<tr class=class on:click=move |mouse_event| on_select.run(mouse_event)>
{TableRow::render_row(row, index)}
</tr>
}
}
/// The default row placeholder renderer which is just a div that is set to the
/// appropriate height. This is used in place of rows that are not shown
/// before and after the currently visible rows.
pub fn DefaultRowPlaceholderRenderer(height: Signal<f64>) -> impl IntoView {
view! { <tr style:height=move || format!("{}px", height.get()) style="display: block"></tr> }
}
/// The default error row renderer which just displays the error message when
/// a row fails to load, i.e. when [`TableDataProvider::get_rows`] returns an `Err(..)`.
#[allow(unused_variables)]
pub fn DefaultErrorRowRenderer(err: String, index: usize, col_count: usize) -> impl IntoView {
view! { <tr><td colspan=col_count>{err}</td></tr> }
}
/// The default loading row renderer which just displays a loading indicator.
#[allow(unused_variables, unstable_name_collisions)]
pub fn DefaultLoadingRowRenderer(
class: Signal<String>,
get_cell_class: Callback<(usize,), String>,
get_inner_cell_class: Callback<(usize,), String>,
index: usize,
col_count: usize,
) -> impl IntoView {
view! {
<tr class=class>
{
(0..col_count).map(|col_index| view! {
<td class=get_cell_class.run((col_index,))>
<div class=get_inner_cell_class.run((col_index,))></div>
" "
</td>
}).collect_view()
}
</tr>
}
}