Schedule-ICTIS/Schedule ICTIS/Main/Views/Fields/SubjectFieldView.swift
2025-01-29 19:04:37 +03:00

66 lines
2.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Field.swift
// Schedule ICTIS
//
// Created by G412 on 16.12.2024.
// КТбо2-6
import SwiftUI
struct SubjectFieldView: View {
@Binding var text: String
@Binding var isShowingSubjectFieldRed: Bool
@Binding var labelForField: String
@FocusState var isFocused: Bool
var body: some View {
HStack(spacing: 0) {
Image(systemName: "book")
.foregroundColor(Color.gray)
.padding(.leading, 12)
.padding(.trailing, 9)
TextField(labelForField, text: $text)
.font(.custom("Montserrat-Regular", size: 18))
.disableAutocorrection(true)
.submitLabel(.done)
.focused($isFocused)
.onChange(of: isFocused, initial: false) { oldValue, newValue in
if newValue {
self.isShowingSubjectFieldRed = false
self.labelForField = "Предмет"
}
}
.background {
Group {
if isShowingSubjectFieldRed {
Text("Поле должно быть заполнено!")
.font(.custom("Montserrat-Regular", size: 18))
.foregroundColor(.red)
.frame(width: 290)
.padding(.leading, -42)
}
}
}
if isFocused {
Button {
self.text = ""
self.isFocused = false
} label: {
Image(systemName: "xmark.circle.fill")
.padding(.trailing, 20)
.offset(x: 10)
.foregroundColor(.gray)
}
}
}
.frame(height: 40)
.background(
RoundedRectangle(cornerRadius: 10)
.fill(.white)
)
}
}
#Preview {
SubjectFieldView(text: .constant(""), isShowingSubjectFieldRed: .constant(false), labelForField: .constant("Предмет"))
}