-
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.
Merge pull request #36 from payan-app/search-field
feat: add search box component
- Loading branch information
Showing
9 changed files
with
126 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
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,19 @@ | ||
// | ||
// SearchExample.swift | ||
// PuraceDemo | ||
// | ||
// Created by Juan Hurtado on 11/12/22. | ||
// | ||
|
||
import SwiftUI | ||
import Purace | ||
|
||
struct SearchExample: View { | ||
@State var text = "" | ||
|
||
var body: some View { | ||
PuraceSearchBox("Buscar...", text: $text) | ||
.padding(16) | ||
Spacer() | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
Sources/Purace/Resources/Media.xcassets/close.imageset/Contents.json
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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "close.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Sources/Purace/Resources/Media.xcassets/close.imageset/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
Sources/Purace/Resources/Media.xcassets/search.imageset/Contents.json
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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "search.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Sources/Purace/Resources/Media.xcassets/search.imageset/search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
68 changes: 68 additions & 0 deletions
68
Sources/Purace/Views/Basic/SearchBox/PuraceSearchBox.swift
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,68 @@ | ||
// | ||
// PuraceSearchBox.swift | ||
// | ||
// | ||
// Created by Juan Hurtado on 11/12/22. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct PuraceSearchBox: View { | ||
var placeholder: String | ||
@Binding var text: String | ||
|
||
public init(_ placeholder: String, text: Binding<String>) { | ||
self.placeholder = placeholder | ||
_text = text | ||
} | ||
|
||
public var body: some View { | ||
TextField(placeholder, text: $text, onCommit: { | ||
print("asdf?") | ||
}) | ||
.textFieldStyle(.plain) | ||
.padding(.horizontal, 12) | ||
.frame(height: 35) | ||
.font(PuraceStyle.Font.get(size: 12)) | ||
.foregroundColor(PuraceStyle.Color.N1) | ||
.modifier(ClearButton(text: $text)) | ||
.modifier(LeadingSearchIcon()) | ||
.background( | ||
RoundedRectangle(cornerRadius: 20) | ||
.fill(PuraceStyle.Color.F1) | ||
) | ||
} | ||
} | ||
|
||
|
||
struct ClearButton: ViewModifier { | ||
@Binding var text: String | ||
|
||
init(text: Binding<String>) { | ||
self._text = text | ||
} | ||
|
||
func body(content: Content) -> some View { | ||
HStack(spacing: 0) { | ||
content | ||
Spacer(minLength: 0) | ||
Image("close", bundle: Bundle.module) | ||
.foregroundColor(.secondary) | ||
.opacity(text == "" ? 0 : 1) | ||
.onTapGesture { self.text = "" } | ||
.padding(.trailing, 15) | ||
} | ||
} | ||
} | ||
|
||
struct LeadingSearchIcon: ViewModifier { | ||
func body(content: Content) -> some View { | ||
HStack(spacing: 0) { | ||
Image("search", bundle: Bundle.module) | ||
.foregroundColor(.secondary) | ||
.padding(.leading, 15) | ||
Spacer(minLength: 0) | ||
content | ||
} | ||
} | ||
} |