Skip to content

Commit

Permalink
Add a SecureField kind to ListRow (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave authored Sep 17, 2024
1 parent 22f9d80 commit a927039
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Sources/Compound/List/ListRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public enum ListRowPadding {
leading: horizontal,
bottom: vertical,
trailing: horizontal)

public static let textFieldInsets = EdgeInsets(top: 11,
leading: horizontal,
bottom: 11,
trailing: horizontal)
}

public struct ListRow<Icon: View, DetailsIcon: View, CustomContent: View, SelectionValue: Hashable>: View {
Expand All @@ -41,6 +46,7 @@ public struct ListRow<Icon: View, DetailsIcon: View, CustomContent: View, Select
case selection(isSelected: Bool, action: () -> Void)
case multiSelection(isSelected: Bool, action: () -> Void)
case textField(text: Binding<String>, axis: Axis?)
case secureField(text: Binding<String>)

case custom(() -> CustomContent)

Expand Down Expand Up @@ -119,10 +125,15 @@ public struct ListRow<Icon: View, DetailsIcon: View, CustomContent: View, Select
}
.tint(.compound.iconAccentTertiary)
.foregroundStyle(isEnabled ? .compound.textPrimary : .compound.textDisabled)
.listRowInsets(EdgeInsets(top: 11,
leading: ListRowPadding.horizontal,
bottom: 11,
trailing: ListRowPadding.horizontal))
.listRowInsets(ListRowPadding.textFieldInsets)
case .secureField(let text):
SecureField(text: text) {
Text(label.title ?? "")
.compoundTextFieldPlaceholder()
}
.tint(.compound.iconAccentTertiary)
.foregroundStyle(isEnabled ? .compound.textPrimary : .compound.textDisabled)
.listRowInsets(ListRowPadding.textFieldInsets)

case .custom(let content):
content()
Expand Down Expand Up @@ -419,11 +430,13 @@ public struct ListRow_Previews: PreviewProvider, PrefireProvider {
.padding(.vertical, 20)
})
ListRow(label: .plain(title: "Placeholder"),
kind: .textField(text: .constant("This is a disabled text field"), axis: .vertical))
kind: .textField(text: .constant("This is a disabled text field")))
.disabled(true)
ListRow(label: .plain(title: "Placeholder"),
kind: .textField(text: .constant(""), axis: .vertical))
.lineLimit(4...)
ListRow(label: .plain(title: "Password"),
kind: .secureField(text: .constant("p4ssw0rd")))
}
}
}
Expand Down

0 comments on commit a927039

Please sign in to comment.