Skip to content

Commit

Permalink
Merge branch 'main' into main2
Browse files Browse the repository at this point in the history
  • Loading branch information
janhuachu authored Sep 9, 2024
2 parents 5dbc06e + a9fd5d1 commit b7471ff
Show file tree
Hide file tree
Showing 21 changed files with 678 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Apps/Examples/Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
3C180C282B858CF6007CE79A /* IllustratedMessageExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C180C272B858CF6007CE79A /* IllustratedMessageExample.swift */; };
6432FFA02C5164F8008ECE89 /* SegmentedControlExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6432FF9F2C5164F8008ECE89 /* SegmentedControlExample.swift */; };
64905D072C6D13E20062AAD4 /* SwitchExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64905D062C6D13E20062AAD4 /* SwitchExample.swift */; };
64905D092C7693970062AAD4 /* DateTimePickerExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64905D082C7693970062AAD4 /* DateTimePickerExample.swift */; };
691DE21925F2A30B00094D4A /* KPIViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 691DE21825F2A30B00094D4A /* KPIViewExample.swift */; };
692F338B26556A6A009B98DA /* SideBarExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 692F338A26556A6A009B98DA /* SideBarExample.swift */; };
69B2B5D9268A333C009AC6B3 /* KPIProgressViewExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69B2B5D8268A333C009AC6B3 /* KPIProgressViewExample.swift */; };
Expand Down Expand Up @@ -234,6 +235,7 @@
3C180C272B858CF6007CE79A /* IllustratedMessageExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IllustratedMessageExample.swift; sourceTree = "<group>"; };
6432FF9F2C5164F8008ECE89 /* SegmentedControlExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentedControlExample.swift; sourceTree = "<group>"; };
64905D062C6D13E20062AAD4 /* SwitchExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchExample.swift; sourceTree = "<group>"; };
64905D082C7693970062AAD4 /* DateTimePickerExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateTimePickerExample.swift; sourceTree = "<group>"; };
691DE21825F2A30B00094D4A /* KPIViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KPIViewExample.swift; sourceTree = "<group>"; };
692F338A26556A6A009B98DA /* SideBarExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideBarExample.swift; sourceTree = "<group>"; };
69B2B5D8268A333C009AC6B3 /* KPIProgressViewExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KPIProgressViewExample.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -799,6 +801,7 @@
children = (
B1D41B1F291A2D97004E64A5 /* DurationPickerExample.swift */,
6432FF9F2C5164F8008ECE89 /* SegmentedControlExample.swift */,
64905D082C7693970062AAD4 /* DateTimePickerExample.swift */,
);
path = Picker;
sourceTree = "<group>";
Expand Down Expand Up @@ -1059,6 +1062,7 @@
108E43D5292DAB7C006532F3 /* EmptyStateViewExample.swift in Sources */,
B13408922B01FA0700600331 /* NavigationBarExample.swift in Sources */,
B84D24F22652F343007F2373 /* ObjectHeaderDeveloperExample.swift in Sources */,
64905D092C7693970062AAD4 /* DateTimePickerExample.swift in Sources */,
B80DA9C2260D04FB00C0B2E9 /* SingleActionLongFollowButton.swift in Sources */,
8A6D64BA25AE714100D2D76C /* ExampleHighlightingStyle.swift in Sources */,
99942D572616980A001912C5 /* OnboardingExamples.swift in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions Apps/Examples/Examples/FioriSwiftUICore/CoreContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ struct CoreContentView: View {
{
Text("SegmentedControlPicker")
}

NavigationLink(
destination: DateTimePickerExample())
{
Text("DateTimePicker")
}
}

Section(header: Text("Onboarding")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import FioriSwiftUICore
import SwiftUI

struct KeyValueFormViewExample: View {
@State var isPresented: Bool = false
var key1: AttributedString {
let aString = AttributedString("Key 1")
return aString
Expand Down Expand Up @@ -42,11 +43,40 @@ struct KeyValueFormViewExample: View {
@State var allowsBeyondLimit = false
@State var hidesReadonlyHint = false
@State var isRequired = false
@State var showList = true

var body: some View {
VStack {
Text("KeyValueFormViewExample")
List {
if !self.showList {
KeyValueFormView(title: "KeyValueFormView", text: self.$valueText1, placeholder: "KeyValueFormView", errorMessage: "", hintText: self.getHintText(), isCharCountEnabled: self.showsCharCount, allowsBeyondLimit: self.allowsBeyondLimit, isRequired: self.isRequired)
.padding(.horizontal, 10)
} else {
Text("KeyValueFormViewExample")
List {
Text("Default KeyValueForm")
KeyValueFormView(title: self.key1, text: self.$valueText1, placeholder: "KeyValueFormView", errorMessage: self.getErrorMessage(), maxTextLength: self.getMaxTextLength(), hintText: self.getHintText(), isCharCountEnabled: self.showsCharCount, allowsBeyondLimit: self.allowsBeyondLimit, isRequired: self.isRequired)

Text("Existing Text")
.italic()
KeyValueFormView(title: self.key2, text: self.$valueText2, placeholder: "KeyValueFormView", errorMessage: self.getErrorMessage(), maxTextLength: self.getMaxTextLength(), hintText: self.getHintText(), isCharCountEnabled: self.showsCharCount, allowsBeyondLimit: self.allowsBeyondLimit, isRequired: self.isRequired)

Text("minHeight 50, maxHeight 200")
.italic()
KeyValueFormView(title: self.key3, text: self.$valueText3, placeholder: "Please enter something", errorMessage: self.getErrorMessage(), minTextEditorHeight: 50, maxTextEditorHeight: 200, hintText: self.getHintText(), allowsBeyondLimit: self.allowsBeyondLimit, isRequired: self.isRequired)

Text("Disabled")
KeyValueFormView(title: "Disabled", text: self.$disabledText, placeholder: "Disabled", controlState: .disabled, minTextEditorHeight: 50, maxTextEditorHeight: 200, isRequired: self.isRequired)

Text("Read-Only")
KeyValueFormView(title: "Read-Only", text: self.$readOnlyText, placeholder: "Read-Only", controlState: .readOnly, minTextEditorHeight: 50, maxTextLength: 200, hidesReadOnlyHint: self.hidesReadonlyHint, isRequired: self.isRequired)
}
#if !os(visionOS)
.scrollDismissesKeyboard(.immediately)
#endif
}
}
.sheet(isPresented: self.$isPresented, content: {
VStack {
Toggle("Shows Hint Text", isOn: self.$showsHintText)
.padding(.leading, 16)
.padding(.trailing, 16)
Expand All @@ -65,33 +95,21 @@ struct KeyValueFormViewExample: View {
Toggle("Mandatory Field", isOn: self.$isRequired)
.padding(.leading, 16)
.padding(.trailing, 16)
Toggle("Show on List", isOn: self.$showList)
.padding(.leading, 16)
.padding(.trailing, 16)
Button("Dismiss Keyboard") {
hideKeyboard()
}
.padding(.leading, 16)
.padding(.trailing, 16)

Text("Default KeyValueForm")
KeyValueFormView(title: self.key1, text: self.$valueText1, placeholder: "KeyValueFormView", errorMessage: self.getErrorMessage(), maxTextLength: self.getMaxTextLength(), hintText: self.getHintText(), isCharCountEnabled: self.showsCharCount, allowsBeyondLimit: self.allowsBeyondLimit, isRequired: self.isRequired)

Text("Existing Text")
.italic()
KeyValueFormView(title: self.key2, text: self.$valueText2, placeholder: "KeyValueFormView", errorMessage: self.getErrorMessage(), maxTextLength: self.getMaxTextLength(), hintText: self.getHintText(), isCharCountEnabled: self.showsCharCount, allowsBeyondLimit: self.allowsBeyondLimit, isRequired: self.isRequired)

Text("minHeight 50, maxHeight 200")
.italic()
KeyValueFormView(title: self.key3, text: self.$valueText3, placeholder: "Please enter something", errorMessage: self.getErrorMessage(), minTextEditorHeight: 50, maxTextEditorHeight: 200, hintText: self.getHintText(), allowsBeyondLimit: self.allowsBeyondLimit, isRequired: self.isRequired)

Text("Disabled")
KeyValueFormView(title: "Disabled", text: self.$disabledText, placeholder: "Disabled", controlState: .disabled, minTextEditorHeight: 50, maxTextEditorHeight: 200, isRequired: self.isRequired)

Text("Read-Only")
KeyValueFormView(title: "Read-Only", text: self.$readOnlyText, placeholder: "Read-Only", controlState: .readOnly, minTextEditorHeight: 50, maxTextLength: 200, hidesReadOnlyHint: self.hidesReadonlyHint, isRequired: self.isRequired)
}
#if !os(visionOS)
.scrollDismissesKeyboard(.immediately)
#endif
}
.padding()
.presentationDetents([.medium])
})
.toolbar(content: {
FioriButton(title: "Options") { _ in
self.isPresented = true
}
})
}

func getHintText() -> AttributedString? {
Expand Down
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,9 @@ protocol _OptionalTitleComponent {
// sourcery: defaultValue = ""
var optionalTitle: AttributedString? { get }
}

// sourcery: BaseComponent
protocol _ValueLabelComponent {
// sourcery: @ViewBuilder
var valueLabel: AttributedString? { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,12 @@ protocol _TimelinePreviewComponent: _OptionalTitleComponent, _ActionComponent {
/// ```
// sourcery: CompositeComponent
protocol _SwitchViewComponent: _TitleComponent, _SwitchComponent {}

// sourcery: CompositeComponent
protocol _DateTimePickerComponent: _TitleComponent, _ValueLabelComponent {
// sourcery: @Binding
var selectedDate: Date { get }

// sourcery: defaultValue = [.date, .hourAndMinute]
var pickerComponents: DatePicker.Components { get }
}
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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extension JouleWelcomeScreenFioriStyle {
func makeBody(_ configuration: TitleConfiguration) -> some View {
Title(configuration)
.foregroundStyle(Color.preferredColor(.baseWhite))
.font(.fiori(forTextStyle: .title1, weight: .bold))
.font(.fiori(forTextStyle: .largeTitle))
.lineLimit(2)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension MenuSelectionItemFioriStyle {

struct IconFioriStyle: IconStyle {
let menuSelectionItemConfiguration: MenuSelectionItemConfiguration
@ScaledMetric var width: CGFloat = 14
@ScaledMetric var width: CGFloat = 18

func makeBody(_ configuration: IconConfiguration) -> some View {
Icon(configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ extension NoteFormViewFioriStyle {
PlaceholderTextEditor(config)
.frame(minHeight: self.getMinHeight(configuration))
.frame(maxHeight: self.getMaxHeight(configuration))
.background(RoundedRectangle(cornerRadius: 8).stroke(self.getBorderColor(configuration), lineWidth: self.getBorderWidth(configuration)).background(self.getBackgroundColor(configuration)))
.background(self.getBackgroundColor(configuration))
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(self.getBorderColor(configuration), lineWidth: self.getBorderWidth(configuration))
)
.cornerRadius(8)
.onChange(of: configuration.text) { s in
self.checkCharCount(configuration, textString: s)
Expand Down
19 changes: 19 additions & 0 deletions Sources/FioriSwiftUICore/_FioriStyles/ValueLabelStyle.fiori.swift
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)
}
}
Loading

0 comments on commit b7471ff

Please sign in to comment.