31 lines
826 B
Swift
31 lines
826 B
Swift
//
|
|
// https://mczachurski.dev
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
// Licensed under the Apache License 2.0.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
struct TextInputField: View {
|
|
private var title: String
|
|
@Binding private var text: String
|
|
|
|
init(_ title: String, text: Binding<String>) {
|
|
self.title = title
|
|
self._text = text
|
|
}
|
|
|
|
var body: some View {
|
|
ZStack(alignment: .leading) {
|
|
Text(title)
|
|
.foregroundColor(text.isEmpty ? Color(.placeholderText) : .accentColor)
|
|
.offset(y: text.isEmpty ? 0 : -25)
|
|
.scaleEffect(text.isEmpty ? 1: 0.8, anchor: .leading)
|
|
TextField("", text: $text)
|
|
}
|
|
.padding(.top, 15)
|
|
.animation(.default, value: text)
|
|
}
|
|
}
|