1
1
use dioxus:: prelude:: * ;
2
2
use dioxus_i18n:: tid;
3
3
use dioxus_primitives:: calendar:: {
4
- Calendar , CalendarContext , CalendarGrid , CalendarHeader , CalendarNavigation ,
5
- CalendarNextMonthButton , CalendarPreviousMonthButton ,
4
+ Calendar , CalendarGrid , CalendarHeader , CalendarNavigation , CalendarNextMonthButton ,
5
+ CalendarPreviousMonthButton , CalendarSelectMonth , CalendarSelectYear ,
6
6
} ;
7
7
8
8
use chrono:: { Datelike , Month , NaiveDate , Utc , Weekday } ;
@@ -30,6 +30,9 @@ pub fn Demo() -> Element {
30
30
view_date. set( new_view) ;
31
31
} ,
32
32
on_format_weekday: Callback :: new( |weekday: Weekday | tid!( & weekday. to_string( ) ) ) ,
33
+ on_format_month: Callback :: new( |month: Month | tid!( month. name( ) ) ) ,
34
+ min_date: NaiveDate :: from_ymd_opt( 1995 , 7 , 21 ) . unwrap( ) ,
35
+ max_date: NaiveDate :: from_ymd_opt( 2035 , 9 , 11 ) . unwrap( ) ,
33
36
CalendarHeader {
34
37
CalendarNavigation {
35
38
CalendarPreviousMonthButton {
@@ -40,7 +43,8 @@ pub fn Demo() -> Element {
40
43
polyline { points: "15 6 9 12 15 18" }
41
44
}
42
45
}
43
- MonthTitle { }
46
+ CalendarSelectMonth { }
47
+ CalendarSelectYear { }
44
48
CalendarNextMonthButton {
45
49
svg {
46
50
class: "calendar-next-month-icon" ,
@@ -56,73 +60,4 @@ pub fn Demo() -> Element {
56
60
}
57
61
}
58
62
}
59
- }
60
-
61
- #[ component]
62
- fn MonthTitle ( ) -> Element {
63
- let calendar: CalendarContext = use_context ( ) ;
64
- let view_date = calendar. view_date ( ) ;
65
- let month_name = Month :: try_from ( view_date. month ( ) as u8 ) . unwrap ( ) . name ( ) ;
66
- let year = view_date. year ( ) ;
67
- let months = ( 1 ..=12 ) . map ( |month_i| Month :: try_from ( month_i) . unwrap ( ) ) ;
68
-
69
- rsx ! {
70
- span { class: "calendar-month-select-container" ,
71
- select {
72
- class: "calendar-month-select" ,
73
- aria_label: "Month" ,
74
- onchange: move |e| {
75
- let mut view_date = calendar. view_date( ) ;
76
- let cur_month = e. value( ) . parse( ) . unwrap_or( view_date. month0( ) ) ;
77
- view_date = view_date. with_month0( cur_month) . unwrap_or( view_date) ;
78
- calendar. set_view_date( view_date) ;
79
- } ,
80
- for ( i , month) in months. enumerate( ) {
81
- option {
82
- value: i,
83
- selected: calendar. view_date( ) . month0( ) == i as u32 ,
84
- { tid!( month. name( ) ) }
85
- }
86
- }
87
- }
88
- span { class: "calendar-month-select-value" ,
89
- { tid!( month_name) }
90
- svg {
91
- class: "select-expand-icon" ,
92
- view_box: "0 0 24 24" ,
93
- xmlns: "http://www.w3.org/2000/svg" ,
94
- polyline { points: "6 9 12 15 18 9" }
95
- }
96
- }
97
- }
98
-
99
- span { class: "calendar-year-select-container" ,
100
- select {
101
- class: "calendar-year-select" ,
102
- aria_label: "Year" ,
103
- onchange: move |e| {
104
- let mut view_date = calendar. view_date( ) ;
105
- let year = e. value( ) . parse( ) . unwrap_or( view_date. year( ) ) ;
106
- view_date = view_date. with_year( year) . unwrap_or( view_date) ;
107
- calendar. set_view_date( view_date) ;
108
- } ,
109
- for year in 1925 ..=2050 {
110
- option {
111
- value: year,
112
- selected: calendar. view_date( ) . year( ) == year,
113
- "{year}"
114
- }
115
- }
116
- }
117
- span { class: "calendar-year-select-value" ,
118
- "{year}"
119
- svg {
120
- class: "select-expand-icon" ,
121
- view_box: "0 0 24 24" ,
122
- xmlns: "http://www.w3.org/2000/svg" ,
123
- polyline { points: "6 9 12 15 18 9" }
124
- }
125
- }
126
- }
127
- }
128
63
}
0 commit comments