Skip to content

Commit

Permalink
Merge pull request #36 from payan-app/search-field
Browse files Browse the repository at this point in the history
feat: add search box component
  • Loading branch information
juandahurt authored Dec 11, 2022
2 parents 6c903d3 + ca04dbc commit ba37278
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 0 deletions.
4 changes: 4 additions & 0 deletions PuraceDemo/PuraceDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
2F6267AE2857B6960063A630 /* AccordionExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F6267AD2857B6960063A630 /* AccordionExample.swift */; };
2F77A234283C4AC700F143FB /* ImageExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F77A233283C4AC700F143FB /* ImageExample.swift */; };
2F7EC3C72867656200D5DDC6 /* ImageViewerExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F7EC3C62867656200D5DDC6 /* ImageViewerExample.swift */; };
2F8272CF2946831300783DE6 /* SearchExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F8272CE2946831300783DE6 /* SearchExample.swift */; };
2F9321B3282EE49E003DA929 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F9321B2282EE49E003DA929 /* AppDelegate.swift */; };
2F9321B5282EE49E003DA929 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F9321B4282EE49E003DA929 /* SceneDelegate.swift */; };
2F9321B7282EE49E003DA929 /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F9321B6282EE49E003DA929 /* MenuView.swift */; };
Expand All @@ -43,6 +44,7 @@
2F6267AD2857B6960063A630 /* AccordionExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccordionExample.swift; sourceTree = "<group>"; };
2F77A233283C4AC700F143FB /* ImageExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageExample.swift; sourceTree = "<group>"; };
2F7EC3C62867656200D5DDC6 /* ImageViewerExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewerExample.swift; sourceTree = "<group>"; };
2F8272CE2946831300783DE6 /* SearchExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchExample.swift; sourceTree = "<group>"; };
2F9321AF282EE49E003DA929 /* PuraceDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PuraceDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
2F9321B2282EE49E003DA929 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2F9321B4282EE49E003DA929 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -89,6 +91,7 @@
2F6267AD2857B6960063A630 /* AccordionExample.swift */,
2F569938285FB93500F2D4D3 /* ModalExample.swift */,
2FD5447928720B810098468D /* TextFieldExample.swift */,
2F8272CE2946831300783DE6 /* SearchExample.swift */,
);
path = Basic;
sourceTree = "<group>";
Expand Down Expand Up @@ -225,6 +228,7 @@
2FC004092831AC250037EF10 /* StoryExample.swift in Sources */,
2F1F7D7128317E0700AA30DB /* CollectionCardExample.swift in Sources */,
2F1F7D7328318D9900AA30DB /* TextExample.swift in Sources */,
2F8272CF2946831300783DE6 /* SearchExample.swift in Sources */,
2F9321B7282EE49E003DA929 /* MenuView.swift in Sources */,
2F7EC3C72867656200D5DDC6 /* ImageViewerExample.swift in Sources */,
2F9321B3282EE49E003DA929 /* AppDelegate.swift in Sources */,
Expand Down
19 changes: 19 additions & 0 deletions PuraceDemo/PuraceDemo/Examples/Basic/SearchExample.swift
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()
}
}
3 changes: 3 additions & 0 deletions PuraceDemo/PuraceDemo/MenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ struct MenuView: View {
NavigationLink("Text Field") {
TextFieldExample()
}
NavigationLink("Search box") {
SearchExample()
}
}
Section(header: Text("Complex")) {
NavigationLink("Collection card") {
Expand Down
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Sources/Purace/Styles/PuraceStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public struct PuraceStyle {

public static let R1 = SwiftUI.Color(hex: "E24649") ?? .red

public static let F1 = SwiftUI.Color(hex: "F5F5F5") ?? .gray

public static let allSkeletons: [SwiftUI.Color] = [Color.S1, Color.S2, Color.S3, Color.S4, Color.S5, Color.S6, Color.S7, Color.S8]
}

Expand Down
68 changes: 68 additions & 0 deletions Sources/Purace/Views/Basic/SearchBox/PuraceSearchBox.swift
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
}
}
}

0 comments on commit ba37278

Please sign in to comment.