Skip to content

Commit d79243d

Browse files
committed
updated main docs
1 parent 747811b commit d79243d

File tree

7 files changed

+63
-66
lines changed

7 files changed

+63
-66
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "leptos-struct-table"
3-
version = "0.6.0"
3+
version = "0.7.0"
44
edition = "2021"
55
authors = ["Marc-Stefan Cassola"]
66
categories = ["gui", "web-programming"]
@@ -22,6 +22,7 @@ serde = "1"
2222
uuid = { version = "1", optional = true, features = ["v4", "js", "serde"] }
2323
thiserror = "1"
2424
web-sys = "0.3.67"
25+
wasm-bindgen = "0.2"
2526

2627
[features]
2728
chrono = ["dep:chrono", "dep:paste"]

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,5 @@ All contributions are welcome. Please open an issue or a pull request if you hav
301301
|---------------|---------------------------|
302302
| <= 0.2 | 0.3 |
303303
| 0.3 | 0.4 |
304-
| 0.4 | 0.5 |
304+
| 0.4, 0.5, 0.6 | 0.5 |
305+
| 0.7 | 0.6 |

examples/custom_renderers_svg/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use leptos_struct_table::*;
77

88
// This generates the component BookTable
99
#[derive(TableRow, Clone)]
10-
#[table(head_cell_renderer = "SvgHeadCellRenderer", impl_vec_data_provider)]
10+
#[table(thead_cell_renderer = "SvgHeadCellRenderer", impl_vec_data_provider)]
1111
pub struct Form {
1212
#[table(renderer = "SvgTextCellRenderer")]
1313
pub name: String,

src/components/table_content.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::{
99
ReloadController, ScrollContainer, SelectionChangeEvent, TableClassesProvider,
1010
TableDataProvider, TableHeadEvent,
1111
};
12-
use leptos::wasm_bindgen::JsCast;
1312
use leptos::*;
1413
use leptos_use::{
1514
use_debounce_fn, use_element_size_with_options, use_scroll_with_options, UseElementSizeOptions,
@@ -19,6 +18,7 @@ use std::cell::RefCell;
1918
use std::collections::{HashSet, VecDeque};
2019
use std::ops::Range;
2120
use std::rc::Rc;
21+
use wasm_bindgen::JsCast;
2222
use web_sys::Element;
2323

2424
renderer_fn!(
@@ -120,7 +120,7 @@ pub fn TableContent<Row, DataP, ClsP>(
120120
/// This is used in place of rows that are not shown
121121
/// before and after the currently visible rows.
122122
#[prop(optional, into)]
123-
row_placeholder_renderer_fn: RowPlaceholderRendererFn,
123+
row_placeholder_renderer: RowPlaceholderRendererFn,
124124

125125
/// Additional classes to add to rows
126126
#[prop(optional, into)]
@@ -431,7 +431,7 @@ where
431431
let thead_content = Row::render_head_row(sorting.into(), on_head_click).into_view();
432432

433433
let tbody_content = view! {
434-
{row_placeholder_renderer_fn.run(placeholder_height_before.into())}
434+
{row_placeholder_renderer.run(placeholder_height_before.into())}
435435

436436
{move || {
437437
let row_renderer = row_renderer.clone();
@@ -525,7 +525,7 @@ where
525525

526526
}}
527527

528-
{row_placeholder_renderer_fn.run(placeholder_height_after.into())}
528+
{row_placeholder_renderer.run(placeholder_height_after.into())}
529529
}.into_view();
530530

531531
let tbody = tbody_renderer.run(tbody_content, tbody_class);

src/components/thead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ wrapper_render_fn!(
2121
/// </th>
2222
/// ```
2323
#[component]
24-
pub fn DefaultTableHeaderRenderer<F>(
24+
pub fn DefaultTableHeaderCellRenderer<F>(
2525
/// The class attribute for the head element. Generated by the classes provider.
2626
#[prop(into)]
2727
class: Signal<String>,

src/lib.rs

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@
6060
//! - **`head_cell_renderer`** - Specifies the name of the header cell renderer component. Used to customize the rendering of header cells. Defaults to [`DefaultTableHeaderRenderer`]. See the [custom_renderers_svg example](https://github.com/Synphonyte/leptos-struct-table/blob/master/examples/custom_renderers_svg/src/main.rs) for more information.
6161
//! - **`impl_vec_data_provider`** - If given, then [`TableDataProvider`] is automatically implemented for `Vec<ThisStruct>` to allow
6262
//! for easy local data use. See the [simple example](https://github.com/synphonyte/leptos-struct-table/blob/master/examples/simple/src/main.rs) for more information.
63-
//! - **`row_type`** - Specifies the type of the rows in the table. Defaults to the struct that this is applied to.
63+
//! - **`row_type`** - Specifies the type of the rows in the table. Defaults to the struct that this is applied to. See the [custom_type example](https://github.com/synphonyte/leptos-struct-table/blob/master/examples/custom_type/src/main.rs) for more information.
6464
//!
6565
//! ## Field attributes
6666
//!
6767
//! These attributes can be applied to any field in the struct.
6868
//!
69-
//! - **`key`** - Specifies the field that is used as the key for each row. This is required on exactly one field.
7069
//! - **`class`** - Specifies the classes that are applied to each cell (head and body) in the field's column. Can be used in conjuction with `classes_provider` to customize the classes.
7170
//! - **`head_class`** - Specifies the classes that are applied to the header cell in the field's column. Can be used in conjuction with `classes_provider` to customize the classes.
7271
//! - **`cell_class`** - Specifies the classes that are applied to the body cells in the field's column. Can be used in conjuction with `classes_provider` to customize the classes.
7372
//! - **`skip`** - Specifies that the field should be skipped. This is useful for fields that are not displayed in the table.
7473
//! - **`skip_sort`** - Only applies if `sortable` is set on the struct. Specifies that the field should not be used for sorting. Clicking it's header will not do anything.
74+
//! - **`skip_header`** - Makes the title of the field not be displayed in the head row.
7575
//! - **`title`** - Specifies the title that is displayed in the header cell. Defaults to the field name converted to title case (`this_field` becomes `"This Field"`).
7676
//! - **`renderer`** - Specifies the name of the cell renderer component. Used to customize the rendering of cells.
7777
//! Defaults to [`DefaultNumberTableCellRenderer`] for number types and [`DefaultTableCellRenderer`] for anything else.
@@ -97,13 +97,10 @@ Example:
9797
```
9898
# use leptos::*;
9999
# use leptos_struct_table::*;
100-
# use serde::{Deserialize, Serialize};
101-
# use async_trait::async_trait;
102100
# use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
103-
#[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
101+
#
102+
#[derive(TableRow, Clone)]
104103
pub struct TemperatureMeasurement {
105-
#[table(key)]
106-
id: u32,
107104
#[table(title = "Temperature (°C)", format(precision = 2))]
108105
temperature: f32,
109106
#[table(format(string = "%m.%d.%Y"))]
@@ -124,12 +121,10 @@ pub struct TemperatureMeasurement {
124121
//! ```
125122
//! # use leptos::*;
126123
//! # use leptos_struct_table::*;
127-
//! # use serde::{Deserialize, Serialize};
128-
//! # use async_trait::async_trait;
129-
//! #[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
124+
//! #
125+
//! #[derive(TableRow, Clone)]
130126
//! #[table(classes_provider = "TailwindClassesPreset")]
131127
//! pub struct Book {
132-
//! #[table(key)]
133128
//! id: u32,
134129
//! title: String,
135130
//! }
@@ -148,10 +143,10 @@ pub struct TemperatureMeasurement {
148143
//! # use leptos_struct_table::*;
149144
//! # use serde::{Deserialize, Serialize};
150145
//! # use async_trait::async_trait;
151-
//! #[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
146+
//! #
147+
//! #[derive(TableRow, Clone)]
152148
//! #[table(classes_provider = "TailwindClassesPreset")]
153149
//! pub struct Book {
154-
//! #[table(key)]
155150
//! id: u32,
156151
//! title: String,
157152
//! author: String,
@@ -173,14 +168,10 @@ pub struct TemperatureMeasurement {
173168
//! ```
174169
//! # use leptos::*;
175170
//! # use leptos_struct_table::*;
176-
//! # use serde::{Deserialize, Serialize};
177-
//! # use async_trait::async_trait;
178-
//! #[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
171+
//! #
172+
//! #[derive(TableRow, Clone)]
179173
//! #[table(classes_provider = "TailwindClassesPreset")]
180174
//! pub struct Book {
181-
//! #[table(key)]
182-
//! id: u32,
183-
//!
184175
//! // this tells the macro that you're going to provide a method called `get_title` that returns a `String`
185176
//! #[table(getter = "get_title")]
186177
//! title: String,
@@ -205,15 +196,21 @@ pub struct TemperatureMeasurement {
205196
//! # Custom Renderers
206197
//!
207198
//! Custom renderers can be used to customize almost every aspect of the table.
208-
//! They are specified by using the various `...renderer` attributes on the struct or fields.
199+
//! They are specified by using the various `...renderer` attributes on the struct or fields or props of the [`TableContent`] component.
209200
//! To implement a custom renderer please have a look at the default renderers listed below.
210201
//!
211-
//! On the struct level you can use these attributes:
212-
//! - **`row_renderer`** - Defaults to [`DefaultTableRowRenderer`].
213-
//! - **`head_row_renderer`** - Defaults to the tag `tr`. This only takes a `class` attribute.
214-
//! - **`head_cell_renderer`** - Defaults to [`DefaultTableHeaderRenderer`].
215-
//! - **`thead_renderer`** - Defaults to the tag `thead`. Takes no attributes.
202+
//! On the struct level you can use this attribute:
203+
//! - **`thead_cell_renderer`** - Defaults to [`DefaultTableHeaderCellRenderer`] which renders `<th><span>Title</span></th>`
204+
//! together with sorting functionality (if enabled).
205+
//!
206+
//! As props of the [`TableContent`] component you can use the following:
207+
//! - **`thead_renderer`** - Defaults to [`DefaultTableHeadRenderer`] which just renders the tag `thead`.
208+
//! - **`thead_row_renderer`** - Defaults to [`DefaultTableHeadRowRenderer`] which just renders the tag `tr`.
216209
//! - **`tbody_renderer`** - Defaults to the tag `tbody`. Takes no attributes.
210+
//! - **`row_renderer`** - Defaults to [`DefaultTableRowRenderer`].
211+
//! - **`loading_row_renderer`** - Defaults to [`DefaultLoadingRowRenderer`].
212+
//! - **`error_row_renderer`** - Defaults to [`DefaultErrorRowRenderer`].
213+
//! - **`row_placeholder_renderer`** - Defaults to [`DefaultRowPlaceholderRenderer`].
217214
//!
218215
//! On the field level you can use the **`renderer`** attribute.
219216
//!
@@ -227,12 +224,9 @@ pub struct TemperatureMeasurement {
227224
//! ```
228225
//! # use leptos::*;
229226
//! # use leptos_struct_table::*;
230-
//! # use serde::{Deserialize, Serialize};
231-
//! # use async_trait::async_trait;
232-
//! #[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
227+
//! #
228+
//! #[derive(TableRow, Clone)]
233229
//! pub struct Book {
234-
//! #[table(key)]
235-
//! id: u32,
236230
//! title: String,
237231
//! #[table(renderer = "ImageTableCellRenderer")]
238232
//! img: String,
@@ -241,7 +235,7 @@ pub struct TemperatureMeasurement {
241235
//! // Easy cell renderer that just displays an image from an URL.
242236
//! #[component]
243237
//! fn ImageTableCellRenderer<F>(
244-
//! #[prop(into)] class: MaybeSignal<String>,
238+
//! class: String,
245239
//! #[prop(into)] value: MaybeSignal<String>,
246240
//! on_change: F,
247241
//! index: usize,
@@ -257,10 +251,10 @@ pub struct TemperatureMeasurement {
257251
//! }
258252
//! ```
259253
//!
260-
//! For more detailed information please have a look at the `custom_renderers_svg` example for a complete customization.
254+
//! For more detailed information please have a look at the [custom_renderers_svg example](https://github.com/synphonyte/leptos-struct-table/blob/master/examples/custom_renderers_svg/src/main.rs) for a complete customization.
261255
//!
262256
//!
263-
//! ### Editable Cells
257+
//! ## Editable Cells
264258
//!
265259
//! You might have noticed the type parameter `F` in the custom cell renderer above. This can be used
266260
//! to emit an event when the cell is changed. In the simplest case you can use a cell renderer that
@@ -269,11 +263,10 @@ pub struct TemperatureMeasurement {
269263
//! ```
270264
//! # use leptos::*;
271265
//! # use leptos_struct_table::*;
272-
//! # use serde::{Deserialize, Serialize};
273-
//! # use async_trait::async_trait;
274-
//! #[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
266+
//! #
267+
//! #[derive(TableRow, Clone, Default, Debug)]
268+
//! #[table(impl_vec_data_provider)]
275269
//! pub struct Book {
276-
//! #[table(key)]
277270
//! id: u32,
278271
//! #[table(renderer = "InputCellRenderer")]
279272
//! title: String,
@@ -282,7 +275,7 @@ pub struct TemperatureMeasurement {
282275
//! // Easy input cell renderer that emits `on_change` when the input is changed.
283276
//! #[component]
284277
//! fn InputCellRenderer<F>(
285-
//! #[prop(into)] class: MaybeSignal<String>,
278+
//! class: String,
286279
//! #[prop(into)] value: MaybeSignal<String>,
287280
//! on_change: F,
288281
//! index: usize,
@@ -296,36 +289,38 @@ pub struct TemperatureMeasurement {
296289
//! </td>
297290
//! }
298291
//! }
299-
//! ```
300292
//!
301-
//! Then in the table component you can listen to the `on_change` event:
302-
//!
303-
//! ```
304-
//! # use leptos::*;
305-
//! # use leptos_struct_table::*;
306-
//! # use serde::{Deserialize, Serialize};
307-
//! # use async_trait::async_trait;
308-
//! # #[derive(TableComponent, Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
309-
//! # pub struct Book {
310-
//! # #[table(key)]
311-
//! # id: u32,
312-
//! # title: String,
313-
//! # }
293+
//! // Then in the table component you can listen to the `on_change` event:
314294
//!
315295
//! #[component]
316296
//! pub fn App() -> impl IntoView {
317-
//! # let items = create_rw_signal(vec![Book::default(), Book::default()]);
318-
//! let on_change = move |evt: ChangeEvent<Book, BookColumnName, BookColumnValue>| {
319-
//! // Do something
297+
//! let rows = vec![Book::default(), Book::default()];
298+
//!
299+
//! let on_change = move |evt: ChangeEvent<Book>| {
300+
//! logging::log!("Changed row at index {}:\n{:#?}", evt.row_index, evt.changed_row);
320301
//! };
321302
//!
322303
//! view! {
323-
//! <BookTable items=items on_change=on_change />
304+
//! <table>
305+
//! <TableContent rows on_change />
306+
//! </table>
324307
//! }
325308
//! }
326309
//! ```
327310
//!
328-
//! Please have a look at the `editable` example for fully working example.
311+
//! Please have a look at the [editable example](https://github.com/Synphonyte/leptos-struct-table/tree/master/examples/editable/src/main.rs) for fully working example.
312+
//!
313+
//! # Pagination / Virtualization / InfiniteScroll
314+
//!
315+
//! This table component supports different display acceleration strategies. You can set them through the `display_strategy` prop of
316+
//! the [`TableContent`] component.
317+
//!
318+
//! The following options are available. Check their docs for more details.
319+
//! - [`DisplayStrategy::Virtualization`] (default)
320+
//! - [`DisplayStrategy::InfiniteScroll`]
321+
//! - [`DisplayStrategy::Pagination`]
322+
//!
323+
//! Please have a look at the [pagination example](https://github.com/Synphonyte/leptos-struct-table/tree/master/examples/pagination/src/main.rs) for more information on how to use pagination.
329324
//!
330325
//! # Contribution
331326
//!

src/scroll_container.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use leptos::html::ElementDescriptor;
2-
use leptos::wasm_bindgen::JsCast;
32
use leptos::{NodeRef, Signal};
43
use leptos_use::core::ElementMaybeSignal;
54
use leptos_use::use_document;
5+
use wasm_bindgen::JsCast;
66

77
#[derive(Copy, Clone, Debug)]
88
pub struct ScrollContainer(Signal<Option<web_sys::Element>>);

0 commit comments

Comments
 (0)