Repository Public MIT
1import SwiftUI2import SPGlassKit34public struct GlassTextFieldExample: GlassExample {5 public static let componentID = "glass-text-field"6 @State private var name = ""7 @State private var email = ""8 @State private var handle = "taken"9 @State private var locked = "Read-only value"10 @FocusState private var emailFocused: Bool1112 public init() {}1314 public var body: some View {15 ScrollView {16 VStack(alignment: .leading, spacing: 20) {17 GlassTextField(18 "Full name",19 text: $name,20 prompt: "Ada Lovelace",21 validation: GlassFieldValidation(.required(), .minLength(2)),22 input: .name23 )24 .onSubmit { emailFocused = true }2526 GlassTextField(27 "Email",28 text: $email,29 prompt: "name@example.com",30 helper: "Used only for the receipt.",31 validation: GlassFieldValidation(.required(), .custom(message: "Enter an address such as name@example.com") { $0.contains("@") && $0.contains(".") }),32 input: .email,33 focus: $emailFocused34 )3536 GlassTextField(37 "Username",38 text: $handle,39 validation: GlassFieldValidation(.maxLength(12)),40 validateOn: .always,41 errorMessage: handle == "taken" ? "This username is already taken." : nil,42 input: .username43 )4445 GlassTextField("Account", text: $locked)46 .disabled(true)4748 Button("Focus the email field") { emailFocused = true }49 }50 .padding()51 }52 }53}5455#Preview("GlassTextField") { GlassTextFieldExample().glassTheme(.aurora) }56