cargo add chrono
use chrono::NaiveDate;
use fission::prelude::*;
use std::sync::Arc;
fission_component! {
pub PublishDateField<()> {
props {
date: Option<NaiveDate>,
open: bool,
year: i32,
month: u32,
choose_date: Arc<dyn Fn(NaiveDate) -> ActionEnvelope + Send + Sync>,
change_month: Arc<dyn Fn(i32, u32) -> ActionEnvelope + Send + Sync>,
toggle_popup: ActionEnvelope,
close_popup: ActionEnvelope,
}
}
view(field, _state, cx) =>
FormControl(
label: Some(cx.tr("article.publish_date")),
child: DatePicker(
id: WidgetId::explicit("article.publish-date"),
value: field.date,
is_open: field.open,
view_year: field.year,
view_month: field.month,
on_navigate: field.change_month.clone(),
on_change: field.choose_date.clone(),
on_toggle: field.toggle_popup.clone(),
on_close: field.close_popup.clone(),
),
)
}
Field | Type | Meaning | Notes / default behavior |
|---|---|---|---|
id | WidgetId | Stable identity for the trigger and popover. | Required. |
value | Option<NaiveDate> | Currently selected date, or no date yet. | Controlled by app state. |
is_open | bool | Whether the popup calendar is visible. | Controlled by app state. |
width | Option<f32> | Preferred trigger width. | Defaults to 164.0, then clamps against the viewport when needed. |
view_year | Option<i32> | Calendar year currently shown in the popup. | Defaults to the selected date's year, or today. |
view_month | Option<u32> | Calendar month currently shown in the popup. | Defaults to the selected date's month, or today. |
on_navigate | Option<Arc<dyn Fn(i32, u32) -> ActionEnvelope + Send + Sync>> | Closure that creates the action for previous/next month navigation. | Use with view_year and view_month for controlled month state. |
on_change | Option<Arc<dyn Fn(NaiveDate) -> ActionEnvelope + Send + Sync>> | Closure that creates the action for a chosen day. | Called when the user selects a date. |
on_toggle | Option<ActionEnvelope> | Action for opening or toggling the popup. | Usually flips is_open. |
on_close | Option<ActionEnvelope> | Action for explicit popup dismissal. | Use this to close on outside click without overloading your toggle logic. |