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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! Support for [::jiff] crate.
use crate::*;
use ::jiff::{
Timestamp, Zoned,
civil::{Date, DateTime, Time},
};
use leptos::prelude::*;
#[derive(Clone, Default)]
pub struct RenderJiffOptions {
/// Specifies a format string, See [`::jiff::fmt::strtime`] for more information.
pub string: Option<String>,
}
macro_rules! jiff_cell_value_impl {
(
$(#[$outer:meta])*
$ty:ty
) => {
$(#[$outer])*
impl CellValue<$ty> for $ty {
type RenderOptions = RenderJiffOptions;
fn render_value(self, options: Self::RenderOptions) -> impl IntoView {
if let Some(value) = options.string.as_ref() {
self.strftime(value).to_string()
} else {
self.to_string()
}
}
}
};
}
jiff_cell_value_impl!(
/// Implementation for [`Date`] to work with the [`TableRow`] derive and the [`DefaultTableCellRenderer`]
/// ```
/// # use leptos_struct_table::*;
/// # use leptos::prelude::*;
/// # use ::jiff::civil::Date;
/// #[derive(TableRow, Clone)]
/// #[table]
/// struct SomeStruct {
/// #[table(format(string = "%Y-%m-%d"))]
/// my_field: Date
/// }
/// ```
Date
);
jiff_cell_value_impl!(
/// Implementation for [`Time`] to work with the [`TableRow`] derive and the [`DefaultTableCellRenderer`]
/// ```
/// # use leptos_struct_table::*;
/// # use leptos::prelude::*;
/// # use ::jiff::civil::Time;
/// #[derive(TableRow, Clone)]
/// #[table]
/// struct SomeStruct {
/// #[table(format(string = "%H:%M:%S"))]
/// my_field: Time
/// }
/// ```
Time
);
jiff_cell_value_impl!(
/// Implementation for [`DateTime`] to work with the [`TableRow`] derive and the [`DefaultTableCellRenderer`]
/// ```
/// # use leptos_struct_table::*;
/// # use leptos::prelude::*;
/// # use ::jiff::civil::DateTime;
/// #[derive(TableRow, Clone)]
/// #[table]
/// struct SomeStruct {
/// #[table(format(string = "%Y-%m-%d %H:%M:%S"))]
/// my_field: DateTime
/// }
/// ```
DateTime
);
jiff_cell_value_impl!(
/// Implementation for [`Timestamp`] to work with the [`TableRow`] derive and the [`DefaultTableCellRenderer`]
/// ```
/// # use leptos_struct_table::*;
/// # use leptos::prelude::*;
/// # use ::jiff::Timestamp;
/// #[derive(TableRow, Clone)]
/// #[table]
/// struct SomeStruct {
/// #[table(format(string = "%Y-%m-%dT%H:%M:%S%z"))]
/// my_field: Timestamp
/// }
/// ```
Timestamp
);
jiff_cell_value_impl!(
/// Implementation for [`Zoned`] to work with the [`TableRow`] derive and the [`DefaultTableCellRenderer`]
/// ```
/// # use leptos_struct_table::*;
/// # use leptos::prelude::*;
/// # use ::jiff::Zoned;
/// #[derive(TableRow, Clone)]
/// #[table]
/// struct SomeStruct {
/// #[table(format(string = "%Y-%m-%d %H:%M:%S %:Q"))]
/// my_field: Zoned
/// }
/// ```
Zoned
);