Skip to content

Commit

Permalink
feat: TextField
Browse files Browse the repository at this point in the history
  • Loading branch information
alsh0807 committed Jul 24, 2024
1 parent 6ac146f commit 516eab9
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Sources/SDS/Component/TextField/SopoSearchField.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import SwiftUI

public struct SopoSearchField: View {

@Binding var text: String
let prompt: String
let onSearch: (() -> ())?

public init(text: Binding<String>, 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)

}
}
}
71 changes: 71 additions & 0 deletions Sources/SDS/Component/TextField/SopoTextField.swift
Original file line number Diff line number Diff line change
@@ -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<String>, 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<String>, 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)
}
}
}

0 comments on commit 516eab9

Please sign in to comment.