Colors, pages, post links

This commit is contained in:
Christoph Hagen
2024-11-20 13:53:44 +01:00
parent 943d8d962b
commit 8ae2a237cc
19 changed files with 466 additions and 46 deletions

View File

@ -0,0 +1,28 @@
import SwiftUI
// A reusable component to handle optional strings with a TextField
struct OptionalTextField: View {
let titleKey: LocalizedStringKey
// The optional text that will be passed in and out of the component
@Binding var text: String?
init(_ titleKey: LocalizedStringKey, text: Binding<String?>) {
self.titleKey = titleKey
self._text = text
}
var body: some View {
TextField(titleKey, text: Binding(
get: {
// Convert `nil` to an empty string for display
text ?? ""
},
set: { newValue in
// Convert an empty string to `nil`
text = newValue.isEmpty ? nil : newValue
}
))
}
}