mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-24 04:03:03 -04:00
Add keyboard shortcut and toggle
This commit is contained in:
parent
35c8b8c956
commit
98a3573640
@ -20,24 +20,61 @@ struct ContentSearchBar: View {
|
|||||||
|
|
||||||
@Binding private var searchText: String
|
@Binding private var searchText: String
|
||||||
|
|
||||||
|
@State private var isActivated: Bool = false
|
||||||
|
@FocusState private var focusedState: Bool
|
||||||
|
|
||||||
init(text: Binding<String>) {
|
init(text: Binding<String>) {
|
||||||
_searchText = text
|
_searchText = text
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
searchBar
|
if isActivated {
|
||||||
|
field
|
||||||
|
.focused($focusedState)
|
||||||
|
} else {
|
||||||
|
button
|
||||||
|
.keyboardShortcut("f")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var searchBar: some View {
|
private var button: some View {
|
||||||
|
Button {
|
||||||
|
isActivated = true
|
||||||
|
focusedState = true
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "magnifyingglass")
|
||||||
|
.font(.system(size: 18))
|
||||||
|
}
|
||||||
|
.buttonStyle(PlainButtonStyle())
|
||||||
|
.padding(32)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var field: some View {
|
||||||
HStack {
|
HStack {
|
||||||
Image(systemName: "magnifyingglass").foregroundColor(.primary)
|
searchImage
|
||||||
TextField("common.search".localized, text: $searchText)
|
TextField("common.search".localized, text: $searchText)
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
|
closeButton
|
||||||
}
|
}
|
||||||
.padding(8)
|
.padding(8)
|
||||||
.background(Color.background)
|
.background(Color.background)
|
||||||
.cornerRadius(16)
|
|
||||||
.padding(16)
|
.padding(16)
|
||||||
|
.cornerRadius(16)
|
||||||
.frame(maxWidth: 320)
|
.frame(maxWidth: 320)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var searchImage: some View {
|
||||||
|
Image(systemName: "magnifyingglass")
|
||||||
|
.foregroundColor(.primary)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var closeButton: some View {
|
||||||
|
Button {
|
||||||
|
searchText = ""
|
||||||
|
isActivated = false
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "xmark.circle.fill").foregroundColor(.primary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user