Skip to content

Commit a72148f

Browse files
committed
[*] Calendar: add support for disabled ranges
1 parent 05ff535 commit a72148f

File tree

7 files changed

+207
-66
lines changed

7 files changed

+207
-66
lines changed

Cargo.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ We're still in the early days - Many components are still being created and stab
4343
- [x] Checkbox
4444
- [x] Collapsible
4545
- [x] Context Menu
46-
- [ ] Date Picker
46+
- [x] Date Picker
4747
- [x] Dialog
4848
- [x] Dropdown Menu
4949
- [x] Hover Card

preview/src/components/calendar/component.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub fn Calendar(props: CalendarProps) -> Element {
2222
first_day_of_week: props.first_day_of_week,
2323
min_date: props.min_date,
2424
max_date: props.max_date,
25+
disabled_ranges: props.disabled_ranges,
2526
attributes: props.attributes,
2627
{props.children}
2728
}
@@ -46,6 +47,7 @@ pub fn RangeCalendar(props: RangeCalendarProps) -> Element {
4647
first_day_of_week: props.first_day_of_week,
4748
min_date: props.min_date,
4849
max_date: props.max_date,
50+
disabled_ranges: props.disabled_ranges,
4951
attributes: props.attributes,
5052
{props.children}
5153
}

preview/src/components/calendar/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@
114114
color: var(--primary-color);
115115
}
116116

117+
.calendar-grid-cell[data-month="current"][date-unavailable="true"] {
118+
color: var(--secondary-color-6);
119+
text-decoration: line-through;
120+
cursor: not-allowed;
121+
}
122+
117123
.calendar-grid-cell[date-selection-start="true"] {
118124
border-top-right-radius: 0;
119125
border-bottom-right-radius: 0;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use super::super::component::*;
2+
use dioxus::prelude::*;
3+
use time::{ext::NumericalDuration, macros::date, Date, UtcDateTime};
4+
5+
use dioxus_primitives::calendar::DateRange;
6+
7+
#[component]
8+
pub fn Demo() -> Element {
9+
let mut selected_range = use_signal(|| None::<DateRange>);
10+
11+
let now = UtcDateTime::now().date();
12+
let mut view_date = use_signal(|| now);
13+
14+
let disabled_ranges = use_signal(|| {
15+
vec![
16+
DateRange::new(now, now.saturating_add(3.days())),
17+
DateRange::new(now.saturating_add(15.days()), now.saturating_add(18.days())),
18+
DateRange::new(now.saturating_add(22.days()), now.saturating_add(23.days())),
19+
]
20+
});
21+
22+
rsx! {
23+
div { class: "calendar-example", style: "padding: 20px;",
24+
RangeCalendar {
25+
selected_range: selected_range(),
26+
on_range_change: move |range| {
27+
tracing::info!("Selected range: {:?}", range);
28+
selected_range.set(range);
29+
},
30+
view_date: view_date(),
31+
on_view_change: move |new_view: Date| {
32+
tracing::info!("View changed to: {}-{}", new_view.year(), new_view.month());
33+
view_date.set(new_view);
34+
},
35+
min_date: date!(1995 - 07 - 21),
36+
max_date: date!(2035 - 09 - 11),
37+
disabled_ranges: disabled_ranges(),
38+
CalendarHeader {
39+
CalendarNavigation {
40+
CalendarPreviousMonthButton {}
41+
CalendarSelectMonth {}
42+
CalendarSelectYear {}
43+
CalendarNextMonthButton {}
44+
}
45+
}
46+
CalendarGrid {
47+
render_day: Callback::new(|date: Date| {
48+
rsx! { RangeCalendarDay { date } }
49+
})
50+
}
51+
}
52+
}
53+
}
54+
}

preview/src/components/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ examples!(
6262
aspect_ratio,
6363
avatar,
6464
button,
65-
calendar[simple, internationalized, range],
65+
calendar[simple, internationalized, range, unavailable_dates],
6666
checkbox,
6767
collapsible,
6868
context_menu,

0 commit comments

Comments
 (0)