waterui_form/picker/
multi_date.rs

1//! A data structure that represents a sorted set of dates.
2//!
3//! It uses a `BTreeSet` internally to store the dates, which guarantees that the dates are always sorted.
4//! This is useful for scenarios where you need to iterate over the dates in a specific order or perform range queries.
5//!
6//! The `MultiDate` struct provides methods for adding, removing, and checking the existence of dates in the set.
7//! It also supports operations like finding the minimum and maximum dates, as well as iterating over the dates in the set.
8use alloc::collections::BTreeSet;
9
10use nami::Binding;
11use time::Date;
12use waterui_core::{AnyView, View, configurable};
13#[derive(Debug)]
14#[non_exhaustive]
15/// Configuration for the `MultiDatePicker` component.
16pub struct MultiDatePickerConfig {
17    /// The label to display for the multi-date picker.
18    pub label: AnyView,
19    /// The binding to the set of selected dates.
20    pub value: Binding<BTreeSet<Date>>,
21}
22
23configurable!(
24    #[doc = "A picker for managing selections of multiple calendar dates."]
25    MultiDatePicker,
26    MultiDatePickerConfig
27);
28
29impl MultiDatePicker {
30    /// Creates a new `MultiDatePicker` with the given binding for selected dates.
31    #[must_use]
32    pub fn new(date: &Binding<BTreeSet<Date>>) -> Self {
33        Self(MultiDatePickerConfig {
34            label: AnyView::default(),
35            value: date.clone(),
36        })
37    }
38
39    /// Sets the label for the multi-date picker.
40    #[must_use]
41    pub fn label(mut self, label: impl View) -> Self {
42        self.0.label = AnyView::new(label);
43        self
44    }
45}