63 lines
1.9 KiB
Swift
63 lines
1.9 KiB
Swift
//
|
|
// SwiftUIView.swift
|
|
// UIKitComponents
|
|
//
|
|
// Created by User on 26.05.2025.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
public struct SearchFieldView: View {
|
|
|
|
let titleKey: String //title key for textfield
|
|
@Binding var search: String //search text
|
|
@FocusState var isFocused: Bool // active field
|
|
|
|
public init(titleKey: String, search: Binding<String>) {
|
|
self.titleKey = titleKey
|
|
self._search = search
|
|
}
|
|
|
|
public var body: some View {
|
|
ZStack {
|
|
TextField("", text: $search)
|
|
.padding(.horizontal, 42)
|
|
.frame(maxWidth: .infinity)
|
|
.frame(height: 48)
|
|
.focused($isFocused)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 10)
|
|
.foregroundStyle(Color("hex#F5F5F9", bundle: .module))
|
|
.overlay(content: {
|
|
RoundedRectangle(cornerRadius: 10)
|
|
.stroke(lineWidth: 1)
|
|
.foregroundStyle(Color("hex#EBEBEB", bundle: .module))
|
|
})
|
|
)
|
|
HStack {
|
|
Image("Search", bundle: .module)
|
|
.padding(.leading, 14)
|
|
.padding(.trailing, 8)
|
|
if search.isEmpty {
|
|
Text(titleKey)
|
|
.robotoFlex(size: 16)
|
|
.foregroundStyle(Color("hex#939396", bundle: .module))
|
|
}
|
|
Spacer()
|
|
if isFocused {
|
|
Button {
|
|
search = ""
|
|
} label: {
|
|
Image("Icon=close", bundle: .module)
|
|
.padding(.trailing, 14)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
SearchFieldView(titleKey: "Искать описание", search: .constant(""))
|
|
}
|