-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |