Skip to content
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

fix: 🐛 [JIRA:0] TextInput form views matching UIKit side colors #707

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import SwiftUI

struct KeyValueFormViewExample: View {
var key1: AttributedString {
var aString = AttributedString("Key 1")
let aString = AttributedString("Key 1")
return aString
}

var key1Long: AttributedString {
var aString = AttributedString("Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 ")
let aString = AttributedString("Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 Long Key 1 ")
return aString
}

@State var valueText1: String = "1234567890 12345678"

var key2: AttributedString {
var aString = AttributedString("Key 2")
let aString = AttributedString("Key 2")
return aString
}

@State var valueText2: String = "This is a test"

var key3: AttributedString {
var aString = AttributedString("Key 3")
let aString = AttributedString("Key 3")
return aString
}

Expand Down Expand Up @@ -65,8 +65,13 @@ struct KeyValueFormViewExample: View {
Toggle("Mandatory Field", isOn: self.$isRequired)
.padding(.leading, 16)
.padding(.trailing, 16)
Button("Dismiss Keyboard") {
hideKeyboard()
}
.padding(.leading, 16)
.padding(.trailing, 16)

Text("Default KeyValueFormView")
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")
Expand Down Expand Up @@ -104,6 +109,14 @@ struct KeyValueFormViewExample: View {
}
}

#if canImport(UIKit)
extension View {
func hideKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
#endif

// #Preview {
// KeyValueFormViewExample()
// }
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ struct NoteFormViewExample: View {
Toggle("Hides Read-Only Hint", isOn: self.$hidesReadonlyHint)
.padding(.leading, 16)
.padding(.trailing, 16)
Button("Dismiss Keyboard") {
hideKeyboard()
}
.padding(.leading, 16)
.padding(.trailing, 16)

Text("Default NoteForm")
NoteFormView(text: self.$valueText1, placeholder: "NoteFormView", errorMessage: self.getErrorMessage(), maxTextLength: self.getMaxTextLength(), hintText: self.getHintText(), isCharCountEnabled: self.showsCharCount, allowsBeyondLimit: self.allowsBeyondLimit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ struct TextFieldFormViewExample: View {
Toggle("Mandatory Field", isOn: self.$isRequired)
.padding(.leading, 16)
.padding(.trailing, 16)
Button("Dismiss Keyboard") {
hideKeyboard()
}
.padding(.leading, 16)
.padding(.trailing, 16)

Text("Default TitleForm")
TextFieldFormView(title: self.key1, text: self.$valueText1, placeholder: "TextFieldFormView", errorMessage: self.getErrorMessage(), maxTextLength: self.getMaxTextLength(), hintText: self.getHintText(), isCharCountEnabled: self.showsCharCount, allowsBeyondLimit: self.allowsBeyondLimit, isRequired: self.isRequired, actionIcon: self.getActionIcon(), action: self.getAction())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,25 @@ public struct KeyValueFormViewBaseStyle: KeyValueFormViewStyle {
// Default fiori styles
extension KeyValueFormViewFioriStyle {
struct ContentFioriStyle: KeyValueFormViewStyle {
@FocusState var isFocused: Bool
func makeBody(_ configuration: KeyValueFormViewConfiguration) -> some View {
KeyValueFormView(configuration)
.titleStyle { titleConf in
Title(titleConf)
.foregroundStyle(self.getTitleColor(configuration))
.font(.fiori(forTextStyle: .subheadline, weight: .semibold))
}
.focused(self.$isFocused)
}

private func getTitleColor(_ configuration: KeyValueFormViewConfiguration) -> Color {
TextInputFormViewConfiguration(configuration, isFocused: self.isFocused).getTitleColor()
}
}

struct TitleFioriStyle: TitleStyle {
let keyValueFormViewConfiguration: KeyValueFormViewConfiguration

func makeBody(_ configuration: TitleConfiguration) -> some View {
Title(configuration)
.foregroundStyle(self.getTitleColor(self.keyValueFormViewConfiguration))
Expand All @@ -38,10 +49,7 @@ extension KeyValueFormViewFioriStyle {
}

private func getTitleColor(_ configuration: KeyValueFormViewConfiguration) -> Color {
guard !(configuration.controlState == .disabled) else {
return .preferredColor(.separator)
}
return .preferredColor(.primaryLabel)
TextInputFormViewConfiguration(configuration, isFocused: false).getTitleColor()
}

private func isDisabled(_ configuration: KeyValueFormViewConfiguration) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public struct PlaceholderTextFieldBaseStyle: PlaceholderTextFieldStyle {
Button(action: {
configuration.text = ""
}) {
Image(systemName: "xmark.circle.fill")
Image(systemName: "xmark.circle")
.font(.fiori(forTextStyle: .body))
.foregroundColor(.preferredColor(.tertiaryLabel))
.padding(.trailing, 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ extension TextFieldFormViewFioriStyle {
}

func getTitleColor(_ configuration: TextFieldFormViewConfiguration) -> Color {
guard !self.isDisabled(configuration) else {
return .preferredColor(.separator)
}
return .preferredColor(.primaryLabel)
TextInputFormViewConfiguration(configuration, isFocused: self.isFocused).getTitleColor()
}

func getTextColor(_ configuration: TextFieldFormViewConfiguration) -> Color {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension TextInputInfoViewFioriStyle {
struct ContentFioriStyle: TextInputInfoViewStyle {
func makeBody(_ configuration: TextInputInfoViewConfiguration) -> some View {
TextInputInfoView(configuration)
.foregroundColor(.preferredColor(.primaryLabel))
.foregroundColor(.preferredColor(.tertiaryLabel))
}
}

Expand All @@ -31,7 +31,7 @@ extension TextInputInfoViewFioriStyle {

func makeBody(_ configuration: IconConfiguration) -> some View {
Icon(configuration)
.foregroundStyle(Color.preferredColor(.primaryLabel))
.foregroundStyle(Color.preferredColor(.tertiaryLabel))
.font(.fiori(forTextStyle: .footnote))
}
}
Expand All @@ -41,7 +41,7 @@ extension TextInputInfoViewFioriStyle {

func makeBody(_ configuration: DescriptionConfiguration) -> some View {
Description(configuration)
.foregroundStyle(Color.preferredColor(.primaryLabel))
.foregroundStyle(Color.preferredColor(.tertiaryLabel))
.font(.fiori(forTextStyle: .footnote))
}
}
Expand All @@ -51,6 +51,7 @@ extension TextInputInfoViewFioriStyle {

func makeBody(_ configuration: CounterConfiguration) -> some View {
Counter(configuration)
.foregroundStyle(Color.preferredColor(.tertiaryLabel))
.font(.fiori(forTextStyle: .footnote))
}
}
Expand Down Expand Up @@ -142,15 +143,15 @@ struct TextInputInfoViewInformationalStyle: TextInputInfoViewStyle {
.iconStyle(content: { IconConfiguration in
if IconConfiguration.icon.isEmpty {
Image(systemName: "info.circle")
.foregroundStyle(Color.preferredColor(.primaryLabel))
.foregroundStyle(Color.preferredColor(.tertiaryLabel))
} else {
IconConfiguration.icon
.foregroundStyle(Color.preferredColor(.primaryLabel))
.foregroundStyle(Color.preferredColor(.tertiaryLabel))
}
})
.descriptionStyle(content: { descriptionConfiguration in
descriptionConfiguration.description
.foregroundStyle(Color.preferredColor(.primaryLabel))
.foregroundStyle(Color.preferredColor(.tertiaryLabel))
})
}
}
Expand Down Expand Up @@ -312,7 +313,7 @@ struct TextInputFormViewConfiguration {
charCountString.foregroundColor = .preferredColor(.tintColor)
}
var limitString = AttributedString("/\(limit)")
limitString.foregroundColor = .preferredColor(.primaryLabel)
limitString.foregroundColor = .preferredColor(.tertiaryLabel)
var counterString = charCountString + limitString
counterString.font = .fiori(forTextStyle: .footnote)
return counterString
Expand Down Expand Up @@ -451,6 +452,15 @@ struct TextInputFormViewConfiguration {
}
return false
}

func getTitleColor() -> Color {
switch self.getControlState() {
case .disabled:
return .preferredColor(.quaternaryLabel)
default:
return self.isFocused ? .preferredColor(.tintColor) : .preferredColor(.primaryLabel)
}
}
}

#Preview(body: {
Expand Down
Loading