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) + } + } +}