TTBaseSUITextField

SwiftUI Core

SwiftUI text field with 4 border types (DEFAULT, NO_BORDER, ONLY_BOTTOM, NO_PADDING), secure/password mode, disabled state, placeholder styling, and real-time text change handler. Mirrors the UIKit TTBaseUITextField API in SwiftUI idiom.


🎨 Types

public enum TYPE {
    case DEFAULT      // Rounded rect border
    case NO_BORDER    // No visible border
    case ONLY_BOTTOM  // Bottom underline only
    case NO_PADDING   // Zero padding, no border
}
TypeAppearanceUse Case
.DEFAULTRounded borderStandard form fields
.NO_BORDERNo borderFields inside custom containers
.ONLY_BOTTOMBottom lineFlat/modern style
.NO_PADDINGMinimalTight layouts

🚀 Usage

// Standard text field with binding
@State private var name = ""

TTBaseSUITextField(
    text: $name,
    placeholder: "Enter your name"
)

// Secure password field
@State private var password = ""
TTBaseSUITextField(
    text: $password,
    placeholder: "Password",
    isSecure: true
)

// Bottom-line style (flat form)
TTBaseSUITextField(
    text: $email,
    placeholder: "Email address",
    type: .ONLY_BOTTOM
)
.keyboardType(.emailAddress)
.textContentType(.emailAddress)

// Disabled field (read-only display)
TTBaseSUITextField(
    text: $userId,
    placeholder: "",
    isDisabled: true
)

// Real-time text change handler
TTBaseSUITextField(text: $query, placeholder: "Search...")
    .onChange(of: query) { newValue in
        viewModel.search(newValue)
    }

🏗 In a Login Form

struct LoginView: View {
    @State private var email = ""
    @State private var password = ""

    var body: some View {
        VStack(spacing: 16) {
            TTBaseSUITextField(
                text: $email,
                placeholder: "Email",
                type: .ONLY_BOTTOM
            )
            .keyboardType(.emailAddress)
            .textContentType(.emailAddress)

            TTBaseSUITextField(
                text: $password,
                placeholder: "Password",
                type: .ONLY_BOTTOM,
                isSecure: true
            )
            .textContentType(.password)

            TTBaseSUIButton(text: "Sign In") {
                login(email: email, password: password)
            }
        }
        .padding()
    }
}

📖 Initializer Parameters

ParameterTypeDefaultDescription
textBinding<String>Two-way text binding
placeholderString""Placeholder text
typeTYPE.DEFAULTBorder style
isSecureBoolfalseEnable password masking
isDisabledBoolfalseMake field read-only/grayed
Pro Tip: For a password toggle (show/hide), layer TTBaseSUITextField(isSecure: !showPassword) with a Button toggling showPassword using SwiftUI's native overlay API.