diff --git a/Backpack-SwiftUI/Calendar/Classes/BPKCalendar.swift b/Backpack-SwiftUI/Calendar/Classes/BPKCalendar.swift index e09f254c6..a6dd94e13 100644 --- a/Backpack-SwiftUI/Calendar/Classes/BPKCalendar.swift +++ b/Backpack-SwiftUI/Calendar/Classes/BPKCalendar.swift @@ -40,7 +40,7 @@ public struct BPKCalendar: View { private var accessoryAction: ((Date) -> CalendarMonthAccessoryAction?)? private var initialMonthScroll: MonthScroll? private let monthHeaderDateFormatter: DateFormatter - + private let showFloatYearLabel: Bool private let dayAccessoryView: (Date) -> DayAccessoryView @State private var currentlyShownMonth: Date @@ -49,6 +49,7 @@ public struct BPKCalendar: View { calendar: Calendar, validRange: ClosedRange, initialMonthScroll: MonthScroll? = nil, + showFloatYearLabel: Bool = true, dayAccessoryView: @escaping (Date) -> DayAccessoryView = { _ in EmptyView() } ) { self.dayAccessoryView = dayAccessoryView @@ -57,6 +58,7 @@ public struct BPKCalendar: View { self.calendar = calendar self.selectionType = selectionType self.initialMonthScroll = initialMonthScroll + self.showFloatYearLabel = showFloatYearLabel monthHeaderDateFormatter = DateFormatter() monthHeaderDateFormatter.timeZone = calendar.timeZone @@ -90,7 +92,9 @@ public struct BPKCalendar: View { }, dayAccessoryView: dayAccessoryView ) - yearBadge + if showFloatYearLabel { + yearBadge + } } } } diff --git a/Backpack-SwiftUI/Calendar/README.md b/Backpack-SwiftUI/Calendar/README.md index 3c7ba1983..7ebcf4cc2 100644 --- a/Backpack-SwiftUI/Calendar/README.md +++ b/Backpack-SwiftUI/Calendar/README.md @@ -80,3 +80,16 @@ BPKCalendar( } ) ``` + +## Float year label + +There is a configurable option to hide/show a floating year label from the calendar view. Default option is to show the year. + +```swift +BPKCalendar( + selectionType: .range(selectedRange: $selectedDateRange), + calendar: .current, + validRange: validStartDate...validEndDate, + showFloatYearLabel: false +) +``` diff --git a/Backpack-SwiftUI/Tests/Calendar/BPKCalendarTests.swift b/Backpack-SwiftUI/Tests/Calendar/BPKCalendarTests.swift index b402f4a3b..211fe5018 100644 --- a/Backpack-SwiftUI/Tests/Calendar/BPKCalendarTests.swift +++ b/Backpack-SwiftUI/Tests/Calendar/BPKCalendarTests.swift @@ -140,4 +140,23 @@ class BPKCalendarTests: XCTestCase { .frame(width: 400) ) } + + func test_singleSelectionCalendarWithNoFloatYearLabel() { + let testDate = Calendar.current.date(from: DateComponents(year: 2020, month: 2, day: 5))! + + assertSnapshot( + BPKCalendar( + selectionType: .single( + selected: .constant(.single(testDate)), + accessibilityConfigurations: SingleAccessibilityConfigurations( + selectionHint: "" + ) + ), + calendar: Calendar.current, + validRange: validStart...validEnd, + showFloatYearLabel: false + ) + .frame(width: 320, height: 720) + ) + } } diff --git a/Backpack-SwiftUI/Tests/Calendar/__Snapshots__/BPKCalendarTests/test_singleSelectionCalendarWithNoFloatYearLabel.dark-mode.png b/Backpack-SwiftUI/Tests/Calendar/__Snapshots__/BPKCalendarTests/test_singleSelectionCalendarWithNoFloatYearLabel.dark-mode.png new file mode 100644 index 000000000..8d31630f1 Binary files /dev/null and b/Backpack-SwiftUI/Tests/Calendar/__Snapshots__/BPKCalendarTests/test_singleSelectionCalendarWithNoFloatYearLabel.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/Calendar/__Snapshots__/BPKCalendarTests/test_singleSelectionCalendarWithNoFloatYearLabel.light-mode.png b/Backpack-SwiftUI/Tests/Calendar/__Snapshots__/BPKCalendarTests/test_singleSelectionCalendarWithNoFloatYearLabel.light-mode.png new file mode 100644 index 000000000..6eebff56e Binary files /dev/null and b/Backpack-SwiftUI/Tests/Calendar/__Snapshots__/BPKCalendarTests/test_singleSelectionCalendarWithNoFloatYearLabel.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/Calendar/__Snapshots__/BPKCalendarTests/test_singleSelectionCalendarWithNoFloatYearLabel.rtl.png b/Backpack-SwiftUI/Tests/Calendar/__Snapshots__/BPKCalendarTests/test_singleSelectionCalendarWithNoFloatYearLabel.rtl.png new file mode 100644 index 000000000..86938397e Binary files /dev/null and b/Backpack-SwiftUI/Tests/Calendar/__Snapshots__/BPKCalendarTests/test_singleSelectionCalendarWithNoFloatYearLabel.rtl.png differ diff --git a/Example/Backpack/SwiftUI/Components/Calendar/CalendarExampleRangeView.swift b/Example/Backpack/SwiftUI/Components/Calendar/CalendarExampleRangeView.swift index 766077686..e64ee63c5 100644 --- a/Example/Backpack/SwiftUI/Components/Calendar/CalendarExampleRangeView.swift +++ b/Example/Backpack/SwiftUI/Components/Calendar/CalendarExampleRangeView.swift @@ -28,14 +28,16 @@ struct CalendarExampleRangeView: View { let calendar: Calendar let formatter: DateFormatter let showAccessoryViews: Bool + let showFloatYearLabel: Bool - init(showAccessoryViews: Bool, makeInitialMonthScroll: Bool = false) { + init(showAccessoryViews: Bool, showFloatYearLabel: Bool = true, makeInitialMonthScroll: Bool = false) { let calendar = Calendar.current let start = calendar.date(from: .init(year: 2023, month: 11, day: 6))! let end = calendar.date(from: .init(year: 2024, month: 11, day: 28))! self.validRange = start...end self.calendar = calendar + self.showFloatYearLabel = showFloatYearLabel let formatter = DateFormatter() formatter.dateStyle = .short @@ -96,6 +98,7 @@ struct CalendarExampleRangeView: View { ), calendar: calendar, validRange: validRange, + showFloatYearLabel: showFloatYearLabel, dayAccessoryView: { _ in BPKIconView(.search, size: .small) .foregroundColor(.accentColor) @@ -109,7 +112,8 @@ struct CalendarExampleRangeView: View { ), calendar: calendar, validRange: validRange, - initialMonthScroll: monthScroll + initialMonthScroll: monthScroll, + showFloatYearLabel: showFloatYearLabel ) } } diff --git a/Example/Backpack/Utils/FeatureStories/Groups/CalendarGroups.swift b/Example/Backpack/Utils/FeatureStories/Groups/CalendarGroups.swift index 5b350143b..175f7b85d 100644 --- a/Example/Backpack/Utils/FeatureStories/Groups/CalendarGroups.swift +++ b/Example/Backpack/Utils/FeatureStories/Groups/CalendarGroups.swift @@ -80,6 +80,10 @@ struct CalendarGroupsProvider { presentableCalendar("Range Selection", view: CalendarExampleRangeView(showAccessoryViews: false)), presentableCalendar("Single Selection", view: CalendarExampleSingleView()), presentableCalendar("With Accessory Views", view: CalendarExampleRangeView(showAccessoryViews: true)), + presentableCalendar( + "With No Float Year Labelst", + view: CalendarExampleRangeView(showAccessoryViews: false, showFloatYearLabel: false) + ), presentableCalendar("With Whole Month Selection", view: CalendarExampleWholeMonthView()), presentableCalendar( "With Initial Month Scrolling",