-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DON-715] Whole month in single date selection #2113
Changes from all commits
ee8d330
7ec9b6b
f813e36
6efc852
8abe004
d969e74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Backpack - Skyscanner's Design System | ||
* | ||
* Copyright 2018 Skyscanner Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/// Create a whole-month configuration with given accessibility strings. | ||
/// - Parameters: | ||
/// - startSelectionState: The label provided to assistive technologies informing a user that a date is selected | ||
/// as the first date in the range. | ||
/// - endSelectionState: The label provided to assistive technologies informing a user that a date is selected | ||
/// as the second date in the range. | ||
/// - betweenSelectionState: The label provided to assistive technologies informing a user that a date lies | ||
/// between the first and second selected dates. | ||
public struct WholeMonthAccessibilityConfigurations { | ||
let startSelectionState: String | ||
let endSelectionState: String | ||
let betweenSelectionState: String | ||
|
||
public init( | ||
startSelectionState: String, | ||
endSelectionState: String, | ||
betweenSelectionState: String | ||
) { | ||
self.startSelectionState = startSelectionState | ||
self.endSelectionState = endSelectionState | ||
self.betweenSelectionState = betweenSelectionState | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Backpack - Skyscanner's Design System | ||
* | ||
* Copyright 2018 Skyscanner Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import Foundation | ||
|
||
/// The `CalendarSingleSelectionState` enum represents the different states of a single selection. | ||
public enum CalendarSingleSelectionState { | ||
/// The state, with single date selection | ||
case single(Date) | ||
|
||
/// The state the user has selected the whole month. | ||
case wholeMonth(ClosedRange<Date>, accessibilityConfig: WholeMonthAccessibilityConfigurations) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ import SwiftUI | |
import Backpack_SwiftUI | ||
|
||
struct CalendarExampleSingleView: View { | ||
@State var selectedDate: Date? | ||
@State var selection: CalendarSingleSelectionState? | ||
private var monthScroll: MonthScroll? | ||
|
||
let validRange: ClosedRange<Date> | ||
|
@@ -49,20 +49,22 @@ struct CalendarExampleSingleView: View { | |
self.monthScroll = .init(monthToScroll: date, animated: true) | ||
} | ||
|
||
_selectedDate = State(initialValue: date) | ||
_selection = State(initialValue: .single(date)) | ||
} | ||
|
||
var body: some View { | ||
VStack { | ||
HStack { | ||
BPKText("Selected date:", style: .caption) | ||
if let selectedDate { | ||
BPKText("\(formatter.string(from: selectedDate))", style: .caption) | ||
if case .single(let date) = selection { | ||
BPKText("\(formatter.string(from: date))", style: .caption) | ||
} else if case .wholeMonth(let month, _) = selection { | ||
BPKText("\(formatter.string(from: month.lowerBound))", style: .caption) | ||
} | ||
} | ||
BPKCalendar( | ||
selectionType: .single( | ||
selected: $selectedDate, | ||
selected: $selection, | ||
accessibilityConfigurations: SingleAccessibilityConfigurations( | ||
selectionHint: "Double tap to select date" | ||
) | ||
|
@@ -71,8 +73,24 @@ struct CalendarExampleSingleView: View { | |
validRange: validRange, | ||
initialMonthScroll: monthScroll | ||
) | ||
.monthAccessoryAction { _ in | ||
return CalendarMonthAccessoryAction( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if the accessibility setting for this should be here instead, to avoid being possible to send nil to that, when you do have an action. wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. 👍 I made this config as part whole month selection state. So if the consumer doesn't want to use the wholeMonth they don't have to provide this value. Removed this optional. ✅ |
||
title: "Select whole month", | ||
action: .wholeMonthSelection({ monthRange in | ||
selection = .wholeMonth(monthRange, accessibilityConfig: wholeMonthAccessibilityConfig()) | ||
}) | ||
) | ||
} | ||
} | ||
} | ||
|
||
private func wholeMonthAccessibilityConfig() -> WholeMonthAccessibilityConfigurations { | ||
return .init( | ||
startSelectionState: "Selected as departure date", | ||
endSelectionState: "Selected as return date", | ||
betweenSelectionState: "Between departure and return date" | ||
) | ||
} | ||
} | ||
|
||
struct CalendarExampleSingleView_Previews: PreviewProvider { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you appliy the above comment about optionality, I think this if let would be done on the selection itself, rather than the date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the optional, but we still need this statement to determine which date needs to be highlighted among other dates when a date has been selected
date == dayDate
.When the tap action happens, we change the state, and the change of state helps us to render the changes.