Skip to content

Commit

Permalink
Add possibility to configure title, text, and today text colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Javid Museyibli authored and ThasianX committed Sep 22, 2021
1 parent 333bd0c commit d446234
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import SwiftUI
public struct CalendarTheme: Equatable, Hashable {

public let primary: Color
public let todayColor: Color
public let titleColor: Color
public let textColor: Color
public let todayTextColor: Color
public let todayBackgroundColor: Color

public init(primary: Color, todayColor: Color? = nil) {
public init(primary: Color, titleColor: Color? = nil, textColor: Color? = nil, todayTextColor: Color? = nil, todayBackgroundColor: Color? = nil) {
self.primary = primary
if let todayColor = todayColor {
self.todayColor = todayColor
} else {
self.todayColor = primary
}

if let titleColor = titleColor { self.titleColor = titleColor } else { self.titleColor = primary }
if let textColor = textColor { self.textColor = textColor } else { self.textColor = .primary }
if let todayTextColor = todayTextColor { self.todayTextColor = todayTextColor } else { self.todayTextColor = primary }
if let todayBackgroundColor = todayBackgroundColor { self.todayBackgroundColor = todayBackgroundColor } else { self.todayBackgroundColor = .primary }
}

}
Expand Down
6 changes: 3 additions & 3 deletions Sources/ElegantCalendar/Views/Monthly/DayView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ struct DayView: View, MonthlyCalendarManagerDirectAccess {

private var foregroundColor: Color {
if isDayToday {
return theme.primary
return theme.todayTextColor
} else {
return .primary
return theme.textColor
}
}

private var backgroundColor: some View {
Group {
if isDayToday {
theme.todayColor
theme.todayBackgroundColor
} else if isDaySelectableAndInRange {
theme.primary
.opacity(datasource?.calendar(backgroundColorOpacityForDate: day) ?? 1)
Expand Down
4 changes: 2 additions & 2 deletions Sources/ElegantCalendar/Views/Monthly/MonthView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ private extension MonthView {
.font(.system(size: 26))
.bold()
.tracking(7)
.foregroundColor(isWithinSameMonthAndYearAsToday ? theme.primary : .primary)
.foregroundColor(isWithinSameMonthAndYearAsToday ? theme.titleColor : .primary)
}

var yearText: some View {
Text(month.year)
.font(.system(size: 12))
.tracking(2)
.foregroundColor(isWithinSameMonthAndYearAsToday ? theme.primary : .gray)
.foregroundColor(isWithinSameMonthAndYearAsToday ? theme.titleColor : .gray)
.opacity(0.95)
}

Expand Down

0 comments on commit d446234

Please sign in to comment.