-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
678 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
Apps/Examples/Examples/FioriSwiftUICore/Picker/DateTimePickerExample.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import FioriSwiftUICore | ||
import Foundation | ||
import SwiftUI | ||
|
||
struct DateTimePickerExample: View { | ||
@State var s1: Date = .init() | ||
@State var s2: Date = .init() | ||
@State var s3: Date = .init() | ||
@State var s4: Date = .init() | ||
|
||
struct CustomTitleStyle: TitleStyle { | ||
func makeBody(_ configuration: TitleConfiguration) -> some View { | ||
Title(configuration) | ||
.font(.fiori(forTextStyle: .title3)) | ||
.foregroundStyle(Color.preferredColor(.indigo7)) | ||
} | ||
} | ||
|
||
struct CustomValueLabelStyle: ValueLabelStyle { | ||
func makeBody(_ configuration: ValueLabelConfiguration) -> some View { | ||
ValueLabel(configuration) | ||
.font(.fiori(forTextStyle: .callout)) | ||
.foregroundStyle(Color.preferredColor(.green7)) | ||
} | ||
} | ||
|
||
var body: some View { | ||
VStack { | ||
DateTimePicker(title: "Default", selectedDate: self.$s1) | ||
DateTimePicker(title: "Date only", selectedDate: self.$s2, pickerComponents: [.date]) | ||
DateTimePicker(title: "Time only", selectedDate: self.$s3, pickerComponents: [.hourAndMinute]) | ||
DateTimePicker(title: "Custom Style", selectedDate: self.$s3) | ||
.titleStyle(CustomTitleStyle()) | ||
.valueLabelStyle(CustomValueLabelStyle()) | ||
} | ||
} | ||
} | ||
|
||
struct DateTimePickerExample_Previews: PreviewProvider { | ||
static var previews: some View { | ||
DateTimePickerExample() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
Sources/FioriSwiftUICore/_FioriStyles/DateTimePickerStyle.fiori.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import FioriThemeManager | ||
import Foundation | ||
import SwiftUI | ||
|
||
// Base Layout style | ||
public struct DateTimePickerBaseStyle: DateTimePickerStyle { | ||
@State var dateString: String = "No date selected" | ||
@State var pickerVisible: Bool = false | ||
|
||
public func makeBody(_ configuration: DateTimePickerConfiguration) -> some View { | ||
VStack { | ||
HStack { | ||
configuration.title | ||
Spacer() | ||
ValueLabel(valueLabel: AttributedString(self.dateString)) | ||
.foregroundStyle(Color.preferredColor(self.pickerVisible ? .tintColor : .primaryLabel)) | ||
.font(.fiori(forTextStyle: .body)) | ||
} | ||
.padding(EdgeInsets(top: 12, leading: 16, bottom: 12, trailing: 16)) | ||
.contentShape(Rectangle()) | ||
.onTapGesture(perform: { | ||
self.pickerVisible.toggle() | ||
}) | ||
if self.pickerVisible { | ||
Divider() | ||
.frame(height: 0.33) | ||
.foregroundStyle(Color.preferredColor(.separatorOpaque)) | ||
.padding(.leading, 16) | ||
self.showPicker(configuration) | ||
} | ||
} | ||
.accessibilityElement() | ||
} | ||
|
||
func showPicker(_ configuration: DateTimePickerConfiguration) -> some View { | ||
let picker = DatePicker("", selection: configuration.$selectedDate, displayedComponents: configuration.pickerComponents) | ||
.datePickerStyle(.graphical) | ||
.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)) | ||
.onChange(of: configuration.selectedDate, perform: { _ in | ||
self.formatDate(configuration) | ||
}) | ||
return picker | ||
} | ||
|
||
func formatDate(_ configuration: DateTimePickerConfiguration) { | ||
let formattedDate = configuration.selectedDate.formatted(date: .abbreviated, time: .omitted) | ||
let formattedTime = configuration.selectedDate.formatted(date: .omitted, time: .shortened) | ||
if configuration.pickerComponents == .date { | ||
self.dateString = formattedDate | ||
} else if configuration.pickerComponents == .hourAndMinute { | ||
self.dateString = formattedTime | ||
} else { | ||
self.dateString = formattedDate + " " + formattedTime | ||
} | ||
} | ||
} | ||
|
||
// Default fiori styles | ||
extension DateTimePickerFioriStyle { | ||
struct ContentFioriStyle: DateTimePickerStyle { | ||
func makeBody(_ configuration: DateTimePickerConfiguration) -> some View { | ||
DateTimePicker(configuration) | ||
} | ||
} | ||
|
||
struct TitleFioriStyle: TitleStyle { | ||
let dateTimePickerConfiguration: DateTimePickerConfiguration | ||
|
||
func makeBody(_ configuration: TitleConfiguration) -> some View { | ||
Title(configuration) | ||
.foregroundStyle(Color.preferredColor(.primaryLabel)) | ||
.font(.fiori(forTextStyle: .subheadline, weight: .semibold)) | ||
} | ||
} | ||
|
||
struct ValueLabelFioriStyle: ValueLabelStyle { | ||
let dateTimePickerConfiguration: DateTimePickerConfiguration | ||
|
||
func makeBody(_ configuration: ValueLabelConfiguration) -> some View { | ||
ValueLabel(configuration) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Sources/FioriSwiftUICore/_FioriStyles/ValueLabelStyle.fiori.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import FioriThemeManager | ||
import Foundation | ||
import SwiftUI | ||
|
||
// Base Layout style | ||
public struct ValueLabelBaseStyle: ValueLabelStyle { | ||
@ViewBuilder | ||
public func makeBody(_ configuration: ValueLabelConfiguration) -> some View { | ||
configuration.valueLabel | ||
} | ||
} | ||
|
||
// Default fiori styles | ||
public struct ValueLabelFioriStyle: ValueLabelStyle { | ||
@ViewBuilder | ||
public func makeBody(_ configuration: ValueLabelConfiguration) -> some View { | ||
ValueLabel(configuration) | ||
} | ||
} |
Oops, something went wrong.