@@ -13,37 +13,68 @@ import SwiftUI
13
13
14
14
// MARK: - Calendar Configuration
15
15
public extension CalendarConfig {
16
+ /// Sets the start date of the calendar.
17
+ /// DEFAULT: Current month
16
18
func startMonth( _ value: Date ) -> Self { MCalendar . startDate = value. start ( of: . month) ; return self }
19
+
20
+ /// Sets the end date of the calendar.
21
+ /// DEFAULT: A date in 10 years
17
22
func endMonth( _ value: Date ) -> Self { MCalendar . endDate = value. end ( of: . month) ; return self }
23
+
24
+ /// Sets the first day of the week.
25
+ /// DEFAULT:: Monday
18
26
func firstWeekday( _ value: MWeekday ) -> Self { MCalendar . firstWeekday = value; return self }
27
+
28
+ /// Sets the locale of the calendar.
29
+ /// DEFAULT: AutoupdatingCurrent
19
30
func locale( _ value: Locale ) -> Self { MCalendar . locale = value; return self }
20
31
}
21
32
22
33
// MARK: - Distances Between Objects
23
34
public extension CalendarConfig {
35
+ /// Sets the top scroll padding in the view.
24
36
func monthsTopPadding( _ value: CGFloat ) -> Self { changing ( path: \. monthsPadding. top, to: value) }
37
+
38
+ /// Sets the bottom scroll padding in the view.
25
39
func monthsBottomPadding( _ value: CGFloat ) -> Self { changing ( path: \. monthsPadding. bottom, to: value) }
40
+
41
+ /// Sets the distance between the month label and the day cell in the view.
26
42
func monthLabelToDaysDistance( _ value: CGFloat ) -> Self { changing ( path: \. monthLabelDaysSpacing, to: value) }
43
+
44
+ /// Sets the spacing between months in the view.
27
45
func monthsSpacing( _ value: CGFloat ) -> Self { changing ( path: \. monthsSpacing, to: value) }
46
+
47
+ /// Sets the vertical spacing between day cells in the view.
28
48
func daysVerticalSpacing( _ value: CGFloat ) -> Self { changing ( path: \. daysSpacing. vertical, to: value) }
49
+
50
+ /// Sets the horizontal spacing between day cells in the view.
29
51
func daysHorizontalSpacing( _ value: CGFloat ) -> Self { changing ( path: \. daysSpacing. horizontal, to: value) }
30
52
}
31
53
32
- // MARK: - Custom Views
54
+ // MARK: - View Customisation
33
55
public extension CalendarConfig {
34
- func monthLabel( _ builder: @escaping ( Date ) -> some MonthLabel ) -> Self { changing ( path: \. monthLabel, to: builder) }
35
- func weekdaysView( _ builder: @escaping ( ) -> some WeekdaysView ) -> Self { changing ( path: \. weekdaysView, to: builder) }
36
- func dayView( _ builder: @escaping ( Date , Bool , Binding < Date ? > ? , Binding < MDateRange ? > ? ) -> some DayView ) -> Self { changing ( path: \. dayView, to: builder) }
56
+ /// Sets the background for the months view.
57
+ func monthsViewBackground( _ value: Color ) -> Self { changing ( path: \. monthsViewBackground, to: value) }
37
58
}
38
59
39
- // MARK: - View Customisation
60
+ // MARK: - Custom Views
40
61
public extension CalendarConfig {
41
- func monthsViewBackground( _ value: Color ) -> Self { changing ( path: \. monthsViewBackground, to: value) }
62
+ /// Replaces the default weekdays view with a selected implementation.
63
+ func weekdaysView( _ builder: @escaping ( ) -> some WeekdaysView ) -> Self { changing ( path: \. weekdaysView, to: builder) }
64
+
65
+ /// Replaces the default month label with a selected implementation.
66
+ func monthLabel( _ builder: @escaping ( Date ) -> some MonthLabel ) -> Self { changing ( path: \. monthLabel, to: builder) }
67
+
68
+ /// Replaces the default day view with a selected implementation.
69
+ func dayView( _ builder: @escaping ( Date , Bool , Binding < Date ? > ? , Binding < MDateRange ? > ? ) -> some DayView ) -> Self { changing ( path: \. dayView, to: builder) }
42
70
}
43
71
44
72
// MARK: - Modifiers
45
73
public extension CalendarConfig {
74
+ /// Scrolls the calendar to the selected date.
46
75
func scrollTo( date: Date ? ) -> Self { changing ( path: \. scrollDate, to: date) }
76
+
77
+ /// Triggers when a new month is about to be visible.
47
78
func onMonthChange( _ value: @escaping ( Date ) -> ( ) ) -> Self { changing ( path: \. onMonthChange, to: value) }
48
79
}
49
80
@@ -57,8 +88,8 @@ public struct CalendarConfig: Configurable { public init() {}
57
88
58
89
private( set) var monthsViewBackground : Color = . clear
59
90
60
- private( set) var monthLabel : ( Date ) -> any MonthLabel = DefaultMonthLabel . init
61
91
private( set) var weekdaysView : ( ) -> any WeekdaysView = DefaultWeekdaysView . init
92
+ private( set) var monthLabel : ( Date ) -> any MonthLabel = DefaultMonthLabel . init
62
93
private( set) var dayView : ( Date , Bool , Binding < Date ? > ? , Binding < MDateRange ? > ? ) -> any DayView = DefaultDayView . init
63
94
64
95
private( set) var scrollDate : Date ? = nil
0 commit comments