From 516eab95355c6207b95e570af6270155b9babce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=8B=A0=EB=AF=BC=ED=98=B8?= <68156836+alsh0807@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:45:29 +0900 Subject: [PATCH] feat: TextField --- .../Component/TextField/SopoSearchField.swift | 56 +++++++++++++++ .../Component/TextField/SopoTextField.swift | 71 +++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 Sources/SDS/Component/TextField/SopoSearchField.swift create mode 100644 Sources/SDS/Component/TextField/SopoTextField.swift diff --git a/Sources/SDS/Component/TextField/SopoSearchField.swift b/Sources/SDS/Component/TextField/SopoSearchField.swift new file mode 100644 index 0000000..aaea5b3 --- /dev/null +++ b/Sources/SDS/Component/TextField/SopoSearchField.swift @@ -0,0 +1,56 @@ +import SwiftUI + +public struct SopoSearchField: View { + + @Binding var text: String + let prompt: String + let onSearch: (() -> ())? + + public init(text: Binding, prompt: String, onSearch: (() -> ())? = nil) { + self._text = text + self.prompt = prompt + self.onSearch = onSearch + } + + public var body: some View { + RoundedRectangle(cornerRadius: 16) + .strokeBorder(Color.primary(.normal), lineWidth: 1.5) + .background(Color.common(.w100) + .clipShape(RoundedRectangle(cornerRadius: 16))) + .frame(height: 40) + .overlay { + HStack { + TextField( + "searchField", + text: $text, + prompt: Text(prompt) + .foregroundColor(.label(.disable)) + ) + + .autocorrectionDisabled() + #if os(iOS) + .textInputAutocapitalization(.never) + #endif + .font(.label(.bold)) + .foregroundStyle(Color.label(.normal)) + .onSubmit { + if let onSearch = onSearch { + onSearch() + } + } + + Button { + if let onSearch = onSearch { + onSearch() + } + } label: { + SopoIcon.search.image + .foregroundStyle(Color.primary(.normal)) + } + + } + .padding(.horizontal, 16) + + } + } +} diff --git a/Sources/SDS/Component/TextField/SopoTextField.swift b/Sources/SDS/Component/TextField/SopoTextField.swift new file mode 100644 index 0000000..c57d0a2 --- /dev/null +++ b/Sources/SDS/Component/TextField/SopoTextField.swift @@ -0,0 +1,71 @@ +import SwiftUI + +struct SopoTextField: View { + + @Binding var text: String + let prompt: String + let isSecure: Bool + let inputType: NSTextContentType? + let trailing: AnyView? + + init(text: Binding, prompt: String, isSecure: Bool = false, inputType: NSTextContentType? = .none, trailing: @escaping () -> some View) { + self._text = text + self.prompt = prompt + self.isSecure = isSecure + self.inputType = inputType + self.trailing = AnyView(trailing()) + } + + init(text: Binding, prompt: String, isSecure: Bool = false, inputType: NSTextContentType? = .none) { + self._text = text + self.prompt = prompt + self.isSecure = isSecure + self.inputType = inputType + self.trailing = nil + } + + + var body: some View { + RoundedRectangle(cornerRadius: 12) + .strokeBorder(Color.label(.disable)) + .background(Color.common(.w100).clipShape(RoundedRectangle(cornerRadius: 12))) + .frame(height: 48) + .overlay { + HStack(spacing: 10) { + Group { + if isSecure { + SecureField( + "sopoSecureField", + text: $text, + prompt: Text(prompt) + .foregroundColor(.label(.disable)) + ) + + } + else { + TextField( + "sopoField", + text: $text, + prompt: Text(prompt) + .foregroundColor(.label(.disable)) + ) + } + } + .autocorrectionDisabled() + .textContentType(inputType) + #if os(iOS) + .textInputAutocapitalization(.never) + #endif + .font(.label(.bold)) + .foregroundStyle(Color.label(.normal)) + + + if let trailing = trailing { + trailing + } + } + .padding(.leading, 10) + .padding(.trailing, 20) + } + } +}