Impressia/Vernissage/Widgets/TextInputField.swift

31 lines
819 B
Swift
Raw Normal View History

2023-02-17 17:10:09 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
// Licensed under the MIT License.
//
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)
}
}