Skip to content

Commit 747811b

Browse files
committed
updated docs and added custom type example
1 parent f84cf7b commit 747811b

File tree

17 files changed

+263
-62
lines changed

17 files changed

+263
-62
lines changed

.idea/leptos-struct-table.iml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom_renderers_svg/src/renderers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn SvgRowRenderer<Row>(
2020
on_change: EventHandler<ChangeEvent<Row>>,
2121
) -> impl IntoView
2222
where
23-
Row: RowRenderer + Clone + 'static,
23+
Row: TableRow + Clone + 'static,
2424
{
2525
let transform = format!("translate(0, {})", (index + 1) * ROW_HEIGHT);
2626

examples/custom_type/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "custom_type"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
leptos = { version = "0.6", features = ["nightly", "csr"] }
8+
leptos-struct-table = { path = "../..", features = ["chrono"] }
9+
chrono = { version = "0.4", features = ["serde"] }
10+
console_error_panic_hook = "0.1"
11+
console_log = "1"
12+
log = "0.4"
13+
async-trait = "0.1"
14+
derive_more = { version = "0.99" }
15+
16+
[dev-dependencies]
17+
wasm-bindgen = "0.2"
18+
wasm-bindgen-test = "0.3.0"
19+
web-sys = "0.3"

examples/custom_type/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
A table example with custom local data stored as `Vec<Rc<Book>>`.
2+
3+
If you don't have it installed already, install [Trunk](https://trunkrs.dev/)
4+
as well as the nightly toolchain for Rust and the wasm32-unknown-unknown target:
5+
6+
```bash
7+
cargo install trunk
8+
rustup toolchain install nightly
9+
rustup target add wasm32-unknown-unknown
10+
```
11+
12+
Then, to run this example, execute in a terminal:
13+
14+
```bash
15+
trunk serve --open
16+
```

examples/custom_type/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head></head>
4+
<body></body>
5+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "nightly"

examples/custom_type/src/main.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#![deny(missing_docs)]
2+
//! Simple showcase example.
3+
4+
use chrono::NaiveDate;
5+
use derive_more::{Deref, DerefMut};
6+
use leptos::*;
7+
use leptos_struct_table::*;
8+
use std::rc::Rc;
9+
10+
/// This generates the component BookTable
11+
#[derive(TableRow)]
12+
#[table(sortable, impl_vec_data_provider, row_type = "RcBook")]
13+
pub struct Book {
14+
/// Title of the book.
15+
pub title: String,
16+
/// Author of the book.
17+
pub author: String,
18+
/// Date when book has been published.
19+
pub publish_date: Option<NaiveDate>,
20+
/// Description of the book. Optional.
21+
#[table(none_value = "-")]
22+
pub description: Option<String>,
23+
}
24+
25+
/// New-type pattern because otherwise the impl TableRow doesn't work because of orphan rules.
26+
#[derive(Deref, DerefMut, Clone)]
27+
pub struct RcBook(Rc<Book>);
28+
29+
fn main() {
30+
_ = console_log::init_with_level(log::Level::Debug);
31+
console_error_panic_hook::set_once();
32+
33+
mount_to_body(|| {
34+
let rows = vec![
35+
RcBook(Rc::new(Book {
36+
title: "The Great Gatsby".to_string(),
37+
author: "F. Scott Fitzgerald".to_string(),
38+
publish_date: Some(NaiveDate::from_ymd_opt(1925, 4, 10).unwrap()),
39+
description: Some(
40+
"A story of wealth, love, and the American Dream in the 1920s.".to_string(),
41+
),
42+
})),
43+
RcBook(Rc::new(Book {
44+
title: "The Grapes of Wrath".to_string(),
45+
author: "John Steinbeck".to_string(),
46+
publish_date: Some(NaiveDate::from_ymd_opt(1939, 4, 14).unwrap()),
47+
description: None,
48+
})),
49+
RcBook(Rc::new(Book {
50+
title: "Nineteen Eighty-Four".to_string(),
51+
author: "George Orwell".to_string(),
52+
publish_date: Some(NaiveDate::from_ymd_opt(1949, 6, 8).unwrap()),
53+
description: None,
54+
})),
55+
RcBook(Rc::new(Book {
56+
title: "Ulysses".to_string(),
57+
author: "James Joyce".to_string(),
58+
publish_date: Some(NaiveDate::from_ymd_opt(1922, 2, 2).unwrap()),
59+
description: None,
60+
})),
61+
];
62+
63+
view! {
64+
<table>
65+
<TableContent rows/>
66+
</table>
67+
}
68+
})
69+
}

src/class_providers/bootstrap.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ impl TableClassesProvider for BootstrapClassesPreset {
1313

1414
format!("{} {}", active, template_classes)
1515
}
16+
17+
// TODO : skeleton loading
1618
}

src/class_providers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub trait TableClassesProvider {
6161
prop_class.to_string()
6262
}
6363

64+
#[allow(unused_variables)]
6465
/// Get the classes for the elements inside of the cells of rows that are currently
6566
/// being loaded. Usually this will be some loading indicator like a sceleton bar.
6667
/// The `prop_class` parameter contains the classes specified in the

src/components/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ macro_rules! wrapper_render_fn {
2222
/// Default
2323
#[$doc_name]
2424
/// renderer. Please note that this is **NOT** a `#[component]`.
25+
///
26+
/// # Arguments
27+
///
28+
/// * `content` - The content of the renderer. It's like the children of this view.
29+
/// * `class` - The class attribute that is passed to the root element
2530
$(#[$additional_doc])*
2631
#[allow(non_snake_case)]
2732
pub fn $name(content: View, class: Signal<String>) -> impl IntoView {

0 commit comments

Comments
 (0)