Skip to content

Commit d446234

Browse files
Javid MuseyibliThasianX
Javid Museyibli
authored andcommitted
Add possibility to configure title, text, and today text colors
1 parent 333bd0c commit d446234

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

Sources/ElegantCalendar/Helpers/Extensions/EnvironmentKey+CalendarTheme.swift

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@ import SwiftUI
55
public struct CalendarTheme: Equatable, Hashable {
66

77
public let primary: Color
8-
public let todayColor: Color
8+
public let titleColor: Color
9+
public let textColor: Color
10+
public let todayTextColor: Color
11+
public let todayBackgroundColor: Color
912

10-
public init(primary: Color, todayColor: Color? = nil) {
13+
public init(primary: Color, titleColor: Color? = nil, textColor: Color? = nil, todayTextColor: Color? = nil, todayBackgroundColor: Color? = nil) {
1114
self.primary = primary
12-
if let todayColor = todayColor {
13-
self.todayColor = todayColor
14-
} else {
15-
self.todayColor = primary
16-
}
15+
16+
if let titleColor = titleColor { self.titleColor = titleColor } else { self.titleColor = primary }
17+
if let textColor = textColor { self.textColor = textColor } else { self.textColor = .primary }
18+
if let todayTextColor = todayTextColor { self.todayTextColor = todayTextColor } else { self.todayTextColor = primary }
19+
if let todayBackgroundColor = todayBackgroundColor { self.todayBackgroundColor = todayBackgroundColor } else { self.todayBackgroundColor = .primary }
1720
}
1821

1922
}

Sources/ElegantCalendar/Views/Monthly/DayView.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ struct DayView: View, MonthlyCalendarManagerDirectAccess {
5454

5555
private var foregroundColor: Color {
5656
if isDayToday {
57-
return theme.primary
57+
return theme.todayTextColor
5858
} else {
59-
return .primary
59+
return theme.textColor
6060
}
6161
}
6262

6363
private var backgroundColor: some View {
6464
Group {
6565
if isDayToday {
66-
theme.todayColor
66+
theme.todayBackgroundColor
6767
} else if isDaySelectableAndInRange {
6868
theme.primary
6969
.opacity(datasource?.calendar(backgroundColorOpacityForDate: day) ?? 1)

Sources/ElegantCalendar/Views/Monthly/MonthView.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ private extension MonthView {
5959
.font(.system(size: 26))
6060
.bold()
6161
.tracking(7)
62-
.foregroundColor(isWithinSameMonthAndYearAsToday ? theme.primary : .primary)
62+
.foregroundColor(isWithinSameMonthAndYearAsToday ? theme.titleColor : .primary)
6363
}
6464

6565
var yearText: some View {
6666
Text(month.year)
6767
.font(.system(size: 12))
6868
.tracking(2)
69-
.foregroundColor(isWithinSameMonthAndYearAsToday ? theme.primary : .gray)
69+
.foregroundColor(isWithinSameMonthAndYearAsToday ? theme.titleColor : .gray)
7070
.opacity(0.95)
7171
}
7272

0 commit comments

Comments
 (0)