cargo add chrono
use chrono::NaiveDate;
use fission::prelude::*;
use std::sync::Arc;
type ChangeRange =
Arc<dyn Fn(Option<NaiveDate>, Option<NaiveDate>) -> ActionEnvelope + Send + Sync>;
fission_component! {
pub ReportingRange<()> {
props {
start: Option<NaiveDate>,
end: Option<NaiveDate>,
start_open: bool,
end_open: bool,
change_range: ChangeRange,
toggle_start: ActionEnvelope,
toggle_end: ActionEnvelope,
close_start: ActionEnvelope,
close_end: ActionEnvelope,
}
}
view(range, _state, cx) =>
Column(
children: [
Text(cx.tr("report.date_range")),
DateRangePicker(
id_start: WidgetId::explicit("report.start"),
id_end: WidgetId::explicit("report.end"),
start: range.start,
end: range.end,
is_start_open: range.start_open,
is_end_open: range.end_open,
on_change: range.change_range.clone(),
on_toggle_start: range.toggle_start.clone(),
on_toggle_end: range.toggle_end.clone(),
on_close_start: range.close_start.clone(),
on_close_end: range.close_end.clone(),
),
],
)
}
Field | Type | Meaning | Notes / default behavior |
|---|---|---|---|
id_start | WidgetId | Stable identity for the start-date trigger. | Required. |
id_end | WidgetId | Stable identity for the end-date trigger. | Required. |
start | Option<NaiveDate> | Current start date. | Controlled by app state. |
end | Option<NaiveDate> | Current end date. | Controlled by app state. |
is_start_open | bool | Whether the start picker popup is open. | Controlled by app state. |
is_end_open | bool | Whether the end picker popup is open. | Controlled by app state. |
on_change | Option<Arc<dyn Fn(Option<NaiveDate>, Option<NaiveDate>) -> ActionEnvelope + Send + Sync>> | Closure that receives the updated pair. | Called when either side changes. |
on_toggle_start | Option<ActionEnvelope> | Action for opening or toggling the start picker. | Defaults to None. |
on_toggle_end | Option<ActionEnvelope> | Action for opening or toggling the end picker. | Defaults to None. |
on_close_start | Option<ActionEnvelope> | Explicit close action for the start picker. | Defaults to None. |
on_close_end | Option<ActionEnvelope> | Explicit close action for the end picker. | Defaults to None. |