Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PBIOS-552] Typeahead view more buttons #461

Merged
merged 42 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
90ea3e6
fix colors for pill kit
RachelRadford21 Jun 24, 2024
6244830
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Jun 27, 2024
2d26fe6
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Jul 1, 2024
30185d4
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Jul 11, 2024
0ce7f96
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Jul 19, 2024
4d691ae
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Jul 31, 2024
fba282c
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Aug 2, 2024
3f7f99c
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Aug 7, 2024
03ffde2
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Aug 12, 2024
b88c77c
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Aug 14, 2024
8645719
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Aug 26, 2024
2764aeb
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Aug 29, 2024
d1cfd33
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Sep 4, 2024
60d92a1
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Sep 20, 2024
9d7e62c
Merge remote-tracking branch 'refs/remotes/origin/main'
RachelRadford21 Sep 30, 2024
119e5a1
add no options to dropdown
RachelRadford21 Oct 2, 2024
f63e123
commit to allow user no options text
RachelRadford21 Oct 8, 2024
9daaed4
no message
isismsilva Oct 9, 2024
5e57925
converted data
isismsilva Oct 15, 2024
dda8321
fix pbuser
isismsilva Oct 15, 2024
8ce8fb7
add view more section button
isismsilva Oct 16, 2024
c39e497
resolved conflicts
isismsilva Oct 17, 2024
434ebcf
fix macos version
isismsilva Oct 17, 2024
b1bbdcb
Merge commit 'b44fa1e3dbb91840c64fe180fd9ef9dc7d0d7625' into PBIOS-56…
isismsilva Oct 17, 2024
b8495bd
Merge branch 'PBIOS-569-typeahead-section-list' into typeahead-sectio…
isismsilva Oct 17, 2024
43be5ef
Merge branch 'main' into PBIOS-569-typeahead-section-list
isismsilva Oct 25, 2024
dd99c3c
Merge branch 'PBIOS-569-typeahead-section-list' into typeahead-sectio…
isismsilva Oct 28, 2024
3378cee
Merge branch 'main' into typeahead-section-buttons
isismsilva Dec 10, 2024
ff48760
removed warnings
isismsilva Dec 10, 2024
ac41531
turn data flat
isismsilva Dec 11, 2024
60c6a3f
removed duplicated code
isismsilva Dec 11, 2024
21f31ad
removed section from hover index
isismsilva Dec 11, 2024
5c08e05
wip
isismsilva Dec 16, 2024
de7694a
Fix show typeahead popover
isismsilva Dec 17, 2024
2a4d1e3
code polishes
isismsilva Dec 17, 2024
c065bc3
wip
isismsilva Dec 17, 2024
6e3a658
add list expanding logic.
isismsilva Dec 18, 2024
c570508
Release
isismsilva Dec 18, 2024
fd695fd
[PBIOS-569] Typeahead section list (#459)
isismsilva Jan 6, 2025
ad2edb9
conform to equatable
isismsilva Jan 6, 2025
5522497
Merge branch 'main' of github.com:powerhome/playbook-swift
isismsilva Jan 6, 2025
370980f
Merge branch 'main' into typeahead-section-buttons
isismsilva Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 13 additions & 29 deletions Sources/Playbook/Components/Typeahead/PBTypeahead.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public struct PBTypeahead<Content: View>: View {
private let popoverManager = PopoverManager()
private let onSelection: (([Option]) -> Void)?
private let clearAction: (() -> Void)?
@State private var listOptions: [Option] = []
@State private var showList: Bool = false
@State private var isCollapsed = false
@State private var hoveringIndex: Int?
@State private var hoveringOption: Option?
@State private var isHovering: Bool = false
Expand Down Expand Up @@ -89,12 +89,8 @@ public struct PBTypeahead<Content: View>: View {
isFocused = false
}
}
.onChange(of: options.count) { _ in
listOptions = options
}
.onAppear {
focused = isFocused
listOptions = options
if debounce.numberOfCharacters == 0 {
showList = isFocused
}
Expand All @@ -109,7 +105,7 @@ public struct PBTypeahead<Content: View>: View {
_ = searchResults
reloadList
}
.onChange(of: listOptions.count) { _ in
.onChange(of: searchResults.count) { _ in
reloadList
}
.onChange(of: contentSize) { _ in
Expand Down Expand Up @@ -162,28 +158,22 @@ private extension PBTypeahead {
.fixedSize(horizontal: false, vertical: true)
}
.frame(maxWidth: .infinity, alignment: .top)
.transition(.opacity)
}

var searchResults: [Option] {
switch selection{
case .multiple:
return searchText.isEmpty && debounce.numberOfCharacters == 0 ? listOptions : listOptions.filter {
if let text = $0.1?.0 {
text.localizedCaseInsensitiveContains(searchText)
} else {
$0.0.localizedCaseInsensitiveContains(searchText)
}
}
case .single:
return searchText.isEmpty && debounce.numberOfCharacters == 0 ? options : options.filter {
let filteredOptions = searchText.isEmpty && debounce.numberOfCharacters == 0 ? options : options.filter {
if let text = $0.1?.0 {
text.localizedCaseInsensitiveContains(searchText)
return text.localizedCaseInsensitiveContains(searchText)
} else {
$0.0.localizedCaseInsensitiveContains(searchText)
return $0.0.localizedCaseInsensitiveContains(searchText)
}
}
}
}
let selectedIds = Set(selectedOptions.map { $0.0 })
let filteredSelectedOptions = filteredOptions.filter { !selectedIds.contains($0.0) }
switch selection{
case .multiple: return filteredSelectedOptions
case .single: return filteredOptions
}
}

var optionsSelected: GridInputField.Selection {
Expand All @@ -210,7 +200,6 @@ private extension PBTypeahead {
searchText = ""
selectedOptions.removeAll()
onSelection?([])
listOptions = options
selectedIndex = nil
hoveringIndex = nil
showList = false
Expand Down Expand Up @@ -270,9 +259,6 @@ private extension PBTypeahead {
var reloadList: Void {
if showList {
isHovering.toggle()
Timer.scheduledTimer(withTimeInterval: 0.001, repeats: false) { _ in
isHovering.toggle()
}
}
}

Expand Down Expand Up @@ -300,16 +286,14 @@ private extension PBTypeahead {
func onMultipleSelection(_ option: Option) {
selectedOptions.append(option)
onSelection?(selectedOptions)
listOptions.removeAll(where: { $0.0 == option.0 })
hoveringIndex = nil
selectedIndex = nil
}

func removeSelected(_ index: Int) {
if let selectedElementIndex = selectedOptions.indices.first(where: { $0 == index }) {
let selectedElement = selectedOptions.remove(at: selectedElementIndex)
let _ = selectedOptions.remove(at: selectedElementIndex)
onSelection?(selectedOptions)
listOptions.append(selectedElement)
selectedIndex = nil
}
}
Expand Down
Loading