61 lines
1.3 KiB
Swift
61 lines
1.3 KiB
Swift
import SwiftUI
|
|
|
|
struct TextEntrySheet: View {
|
|
|
|
let title: String
|
|
|
|
@Binding
|
|
var text: String
|
|
|
|
@Binding
|
|
var isValid: Bool
|
|
|
|
@Environment(\.dismiss)
|
|
private var dismiss: DismissAction
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Text(title)
|
|
.foregroundStyle(.secondary)
|
|
TextField("Text", text: $text)
|
|
.textFieldStyle(RoundedBorderTextFieldStyle())
|
|
.overlay {
|
|
if isValid {
|
|
EmptyView()
|
|
} else {
|
|
RoundedRectangle(cornerRadius: 8)
|
|
.strokeBorder(lineWidth: 3)
|
|
.foregroundStyle(.red)
|
|
}
|
|
}
|
|
.frame(maxWidth: 300)
|
|
HStack {
|
|
Button(action: submit) {
|
|
Text("Submit")
|
|
}
|
|
.disabled(!isValid)
|
|
Button(role: .cancel, action: cancel) {
|
|
Text("Cancel")
|
|
}
|
|
}
|
|
}
|
|
.padding()
|
|
}
|
|
|
|
private func submit() {
|
|
dismiss()
|
|
}
|
|
|
|
private func cancel() {
|
|
text = ""
|
|
dismiss()
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
TextEntrySheet(
|
|
title: "Enter the id for the new post",
|
|
text: .constant("new"),
|
|
isValid: .constant(false))
|
|
}
|