Skip to content

Commit e8765cc

Browse files
committed
[*] Calendar: support for selecting a date range
1 parent 39b30b5 commit e8765cc

File tree

4 files changed

+495
-49
lines changed

4 files changed

+495
-49
lines changed

preview/src/components/calendar/component.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use dioxus::prelude::*;
22
use dioxus_primitives::calendar::{
3-
self, CalendarGridProps, CalendarHeaderProps, CalendarMonthTitleProps, CalendarNavigationProps,
4-
CalendarProps, CalendarSelectMonthProps, CalendarSelectYearProps,
3+
self, CalendarDayProps, CalendarGridProps, CalendarHeaderProps, CalendarMonthTitleProps,
4+
CalendarNavigationProps, CalendarProps, CalendarSelectMonthProps, CalendarSelectYearProps,
5+
RangeCalendarProps,
56
};
67

78
#[component]
@@ -28,6 +29,30 @@ pub fn Calendar(props: CalendarProps) -> Element {
2829
}
2930
}
3031

32+
#[component]
33+
pub fn RangeCalendar(props: RangeCalendarProps) -> Element {
34+
rsx! {
35+
document::Link { rel: "stylesheet", href: asset!("./style.css") }
36+
div { class: "calendar",
37+
calendar::RangeCalendar {
38+
selected_range: props.selected_range,
39+
on_range_change: props.on_range_change,
40+
on_format_weekday: props.on_format_weekday,
41+
on_format_month: props.on_format_month,
42+
view_date: props.view_date,
43+
today: props.today,
44+
on_view_change: props.on_view_change,
45+
disabled: props.disabled,
46+
first_day_of_week: props.first_day_of_week,
47+
min_date: props.min_date,
48+
max_date: props.max_date,
49+
attributes: props.attributes,
50+
{props.children}
51+
}
52+
}
53+
}
54+
}
55+
3156
#[component]
3257
pub fn CalendarHeader(props: CalendarHeaderProps) -> Element {
3358
rsx! {
@@ -104,3 +129,8 @@ pub fn CalendarGrid(props: CalendarGridProps) -> Element {
104129
pub fn CalendarMonthTitle(props: CalendarMonthTitleProps) -> Element {
105130
calendar::CalendarMonthTitle(props)
106131
}
132+
133+
#[component]
134+
pub fn RangeCalendarDay(props: CalendarDayProps) -> Element {
135+
calendar::RangeCalendarDay(props)
136+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use super::super::component::*;
2+
use dioxus::prelude::*;
3+
use time::{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+
let mut view_date = use_signal(|| UtcDateTime::now().date());
11+
rsx! {
12+
div { class: "calendar-example", style: "padding: 20px;",
13+
RangeCalendar {
14+
selected_range: selected_range(),
15+
on_range_change: move |range| {
16+
tracing::info!("Selected range: {:?}", range);
17+
selected_range.set(range);
18+
},
19+
view_date: view_date(),
20+
on_view_change: move |new_view: Date| {
21+
tracing::info!("View changed to: {}-{}", new_view.year(), new_view.month());
22+
view_date.set(new_view);
23+
},
24+
min_date: date!(1995 - 07 - 21),
25+
max_date: date!(2035 - 09 - 11),
26+
CalendarHeader {
27+
CalendarNavigation {
28+
CalendarPreviousMonthButton {}
29+
CalendarSelectMonth {}
30+
CalendarSelectYear {}
31+
CalendarNextMonthButton {}
32+
}
33+
}
34+
CalendarGrid {
35+
render_day: Callback::new(|date: Date| {
36+
rsx! { RangeCalendarDay { date } }
37+
})
38+
}
39+
}
40+
}
41+
}
42+
}

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],
65+
calendar[simple, internationalized, range],
6666
checkbox,
6767
collapsible,
6868
context_menu,

0 commit comments

Comments
 (0)