leptos-struct-table 0.18.0

Generate a complete batteries included leptos data table component from a struct definition.
Documentation
use crate::EventHandler;
use crate::table_row::TableRow;
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, Column>(
    // 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>,
    // Specifies which and where to render columns
    columns: RwSignal<Vec<Column>>,
) -> impl IntoView
where
    Row: TableRow<Column> + 'static,
    Column: Copy + Send + Sync + 'static,
{
    view! {
        <tr class=class on:click=move |mouse_event| on_select.run(mouse_event)>
            {TableRow::render_row(row, index, columns)}
        </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>
    }
}