Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelHolec committed Aug 15, 2023
1 parent 84f29ba commit 5b9af39
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
38 changes: 28 additions & 10 deletions Sources/Orbit/Components/InputField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import UIKit
/// - Important: Component expands horizontally unless prevented by `fixedSize` modifier.
public struct InputField<Prefix: View, Suffix: View>: View, TextFieldBuildable {

@Environment(\.sizeCategory) private var sizeCategory
@Environment(\.iconColor) private var iconColor
@Environment(\.inputFieldBeginEditingAction) private var inputFieldBeginEditingAction
@Environment(\.inputFieldEndEditingAction) private var inputFieldEndEditingAction
@Environment(\.isEnabled) private var isEnabled
@Environment(\.sizeCategory) private var sizeCategory
@Environment(\.textColor) private var textColor

@State private var isEditing: Bool = false
@State private var isSecureTextRedacted: Bool = true
Expand Down Expand Up @@ -50,12 +52,17 @@ public struct InputField<Prefix: View, Suffix: View>: View, TextFieldBuildable {
isEditing: isEditing,
isPlaceholder: value.isEmpty
) {
HStack(alignment: .firstTextBaseline, spacing: .small) {
compactLabel
HStack(alignment: .firstTextBaseline, spacing: .xSmall) {
Text(compactLabel)
.textColor(compactLabelColor)
.padding(.leading, prefix.isEmpty ? .small : 0)

textField
}
} prefix: {
prefix
.iconColor(prefixIconColor)
.textColor(compactLabelColor)
.accessibility(.inputFieldPrefix)
.accessibility(hidden: true)
} suffix: {
Expand All @@ -76,12 +83,6 @@ public struct InputField<Prefix: View, Suffix: View>: View, TextFieldBuildable {
}
}

@ViewBuilder private var compactLabel: some View {
FieldLabel(compactFieldLabel)
.textColor(value.isEmpty ? .inkDark : .inkLight)
.padding(.leading, prefix.isEmpty ? .small : 0)
}

@ViewBuilder private var textField: some View {
TextField(
value: $value,
Expand Down Expand Up @@ -124,13 +125,21 @@ public struct InputField<Prefix: View, Suffix: View>: View, TextFieldBuildable {
}
}

private var compactFieldLabel: String {
private var compactLabel: String {
switch labelStyle {
case .default: return ""
case .compact: return label
}
}

private var compactLabelColor: Color {
textColor ?? .inkNormal
}

private var prefixIconColor: Color? {
iconColor ?? (compactLabel.isEmpty ? .inkDark : nil)
}

private var textFieldLeadingPadding: CGFloat {
prefix.isEmpty && labelStyle == .default
? .small
Expand Down Expand Up @@ -293,6 +302,15 @@ struct InputFieldPreviews: PreviewProvider {
StateWrapper(value) { state in
InputField("Compact", value: state, prefix: .grid, prompt: prompt, state: .default, labelStyle: .compact)
}
StateWrapper(value) { state in
InputField("Compact", value: state, prefix: .grid, prompt: prompt, state: .default, labelStyle: .compact)
}
.textColor(.blueNormal)
StateWrapper(value) { state in
InputField("Compact", value: state, prefix: .grid, prompt: prompt, state: .default, labelStyle: .compact)
}
.iconColor(.redNormal)
.textColor(.blueNormal)
StateWrapper("") { state in
InputField("Compact", value: state, prefix: .grid, prompt: prompt, state: .default, labelStyle: .compact)
}
Expand Down
29 changes: 19 additions & 10 deletions Sources/Orbit/Components/Select.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ public struct Select<Prefix: View, Suffix: View>: View {

public let verticalTextPadding: CGFloat = .small // = 44 @ normal text size

@Environment(\.isEnabled) private var isEnabled: Bool
@Environment(\.iconColor) private var iconColor
@Environment(\.isEnabled) private var isEnabled
@Environment(\.isHapticsEnabled) private var isHapticsEnabled
@Environment(\.textColor) private var textColor

@Binding private var messageHeight: CGFloat

Expand Down Expand Up @@ -38,12 +40,12 @@ public struct Select<Prefix: View, Suffix: View>: View {
action()
},
label: {
HStack(alignment: .firstTextBaseline, spacing: .small) {
FieldLabel(compactFieldLabel)
.textColor(value == nil ? .inkDark : .inkLight)
HStack(alignment: .firstTextBaseline, spacing: .xSmall) {
Text(compactLabel)
.textColor(compactLabelColor)

Text(inputLabel)
.textColor(textColor)
Text(value ?? prompt)
.textColor(valueColor)
.accessibility(.selectValue)
}
.padding(.vertical, verticalTextPadding)
Expand All @@ -58,6 +60,8 @@ public struct Select<Prefix: View, Suffix: View>: View {
isPlaceholder: value == nil
) {
prefix
.iconColor(prefixIconColor)
.textColor(compactLabelColor)
.accessibility(.selectPrefix)
} suffix: {
suffix
Expand All @@ -79,18 +83,18 @@ public struct Select<Prefix: View, Suffix: View>: View {
}
}

private var compactFieldLabel: String {
private var compactLabel: String {
switch labelStyle {
case .default: return ""
case .compact: return label
}
}

private var inputLabel: String {
value ?? prompt
private var compactLabelColor: Color {
textColor ?? .inkNormal
}

private var textColor: Color {
private var valueColor: Color {
if isEnabled {
return value == nil
? state.placeholderColor
Expand All @@ -100,6 +104,10 @@ public struct Select<Prefix: View, Suffix: View>: View {
}
}

private var prefixIconColor: Color? {
iconColor ?? (compactLabel.isEmpty ? .inkDark : nil)
}

private var messageDescription: String {
message?.description ?? ""
}
Expand Down Expand Up @@ -143,6 +151,7 @@ public extension Select {
Icon(prefix)
} suffix: {
Icon(suffix)
.iconColor(.inkNormal)
}
}

Expand Down

0 comments on commit 5b9af39

Please sign in to comment.