Skip to content

Commit

Permalink
fix: labeled text field UI
Browse files Browse the repository at this point in the history
  • Loading branch information
El-Fitz committed Jan 17, 2025
1 parent e5b5f1c commit f2dba29
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 37 deletions.
2 changes: 1 addition & 1 deletion WireUI/Sources/WireAuthenticationUI/Components/Logo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct Logo: View {
Image(ImageResource(name: "logo", bundle: .module))
.resizable()
.scaledToFit()
.padding(.all, min(geometry.size.height, geometry.size.width) / 2.97)
.padding(.all, min(geometry.size.height, geometry.size.width) / 3)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ package struct AuthenticationIdentityInputView: View {
Text(L10n.Authentication.Identity.Input.body)
.wireTextStyle(.body1)
LabeledTextField(
isMandatory: true,
isMandatory: false,
placeholder: L10n.Authentication.Identity.Input.Field.placeholder,
title: L10n.Authentication.Identity.Input.Field.title,
string: $identity
Expand Down
4 changes: 4 additions & 0 deletions WireUI/Sources/WireDesign/Colors/ColorTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public enum ColorTheme {
public static let secondaryText = UIColor(light: .gray70, dark: .gray60)

public static let requiredField = UIColor(light: .red500Light, dark: .red500Dark)

public static let labelTitle = UIColor(light: .gray80, dark: .gray50)
public static let onDisabled = UIColor(light: .gray80, dark: .gray50)
}

public enum Backgrounds {
Expand Down Expand Up @@ -145,6 +148,7 @@ public enum ColorTheme {
public enum Strokes {

public static let outline = UIColor(light: .gray40, dark: .gray90)
public static let disabledOutline = UIColor(light: .gray50, dark: .gray80)
public static let dividersOutlineVariant = UIColor(light: .gray20, dark: .gray100)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,29 @@ import WireDesign
import WireFoundation

public struct LabeledTextField: View {
@Environment(\.isEnabled) private var isEnabled

private let isMandatory: Bool
private let placeholder: String?
private let title: String?

@FocusState var isFocused: Bool
@Binding private var string: String

public init(isMandatory: Bool = false, placeholder: String?, title: String?, string: Binding<String>) {
public init(
isMandatory: Bool = false,
placeholder: String?,
title: String?,
string: Binding<String>
) {
self.isMandatory = isMandatory
self.placeholder = placeholder
self.title = title
self._string = string
}

public var body: some View {
VStack(alignment: .leading) {
VStack(alignment: .leading, spacing: 2) {
if let title {
(
isMandatory ? (
Expand All @@ -45,12 +52,74 @@ public struct LabeledTextField: View {
.foregroundColor(ColorTheme.Base.requiredField.color)
) : Text(title)
)
.wireTextStyle(.h4)
.foregroundStyle(Self.titleColor(isEnabled: isEnabled, isFocused: isFocused))
.wireTextStyle(.subline1)
}
TextField(placeholder ?? "", text: $string)
.textFieldStyle(.roundedBorder)
.wireTextStyle(.body1)
HStack(spacing: 0) {
TextField(placeholder ?? "", text: $string)
.wireTextStyle(.body1)
.focused($isFocused)
.foregroundStyle(Self.labelColor(isEnabled: isEnabled))
.padding(.vertical, 12)
if !string.isEmpty && isEnabled {

Check warning on line 64 in WireUI/Sources/WireReusableUIComponents/LabeledTextField/LabeledTextField.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Prefer comma over && in if, guard or while conditions. (andOperator)
Button(action: {
string = ""
}, label: {
Image(systemName: "xmark.circle.fill")
.foregroundStyle(.black)
.frame(width: 16, height: 16)
.padding(19)
})
}
}
.padding(.leading, 16)
.background {
if #available(iOS 17.0, *) {
RoundedRectangle(cornerRadius: 12)
.fill(Self.labelBackgroundColor(isEnabled: isEnabled))
.stroke(Self.labelBorderColor(isEnabled: isEnabled, isFocused: isFocused), lineWidth: 1)
} else {
RoundedRectangle(cornerRadius: 12)
.stroke(Self.labelBorderColor(isEnabled: isEnabled, isFocused: isFocused), lineWidth: 1)
.background(Self.labelBackgroundColor(isEnabled: isEnabled))
.cornerRadius(12)
}
}
}
}

static func titleColor(isEnabled: Bool, isFocused: Bool) -> Color {
if isEnabled && isFocused {

Check warning on line 92 in WireUI/Sources/WireReusableUIComponents/LabeledTextField/LabeledTextField.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Prefer comma over && in if, guard or while conditions. (andOperator)
return ColorTheme.Base.onPrimaryVariant.color
}
if isEnabled {
return ColorTheme.Base.labelTitle.color
}
return ColorTheme.Base.labelTitle.color
}

static func labelColor(isEnabled: Bool) -> Color {
if isEnabled {
return .primaryText
}
return ColorTheme.Base.onDisabled.color
}

static func labelBackgroundColor(isEnabled: Bool) -> Color {
if isEnabled {
return .clear
}
return ColorTheme.Backgrounds.background.color
}

static func labelBorderColor(isEnabled: Bool, isFocused: Bool) -> Color {
if isEnabled && isFocused {

Check warning on line 116 in WireUI/Sources/WireReusableUIComponents/LabeledTextField/LabeledTextField.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Prefer comma over && in if, guard or while conditions. (andOperator)
return ColorTheme.Base.onPrimaryVariant.color
}
if isEnabled {
return ColorTheme.Strokes.outline.color
}
return ColorTheme.Strokes.outline.color
}
}

Expand All @@ -61,22 +130,34 @@ public struct LabeledTextField: View {
title: nil,
string: .constant("")
)
.padding()
LabeledTextField(
isMandatory: false,
placeholder: "Placeholder",
title: "Some Title",
string: .constant("")
)
.padding()
LabeledTextField(
isMandatory: true,
placeholder: "Placeholder",
title: "Some Title",
string: .constant("")
)
.padding()
LabeledTextField(
isMandatory: true,
placeholder: "Placeholder",
title: "Some Title",
string: .constant("Lorem ipsum dolor sit amet, consectetur [...]")
)
.padding()
LabeledTextField(
isMandatory: true,
placeholder: "Placeholder",
title: "Some Title",
string: .constant("Lorem ipsum sic amet [...]")
string: .constant("Lorem ipsum dolor sit amet, consectetur [...]")
)
.padding()
.disabled(true)
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f2dba29

Please sign in to comment.