Skip to content

Commit a64e314

Browse files
[RANGR-1048] Add Custom No Options Text (#539)
**What does this PR do?** [RANGR-1048] Add Custom No Options Text ### Checklist - [x] **LABELS** - Add a label: `breaking`, `bug`, `improvement`, `documentation`, or `enhancement`. See [Labels](https://github.com/powerhome/playbook-apple/labels) for descriptions. - [x] **RELEASES** - Add the appropriate label: `Ready for Testing` / `Ready for Release` - [x] **TESTING** - Have you tested your story? --------- Co-authored-by: Ísis <[email protected]>
1 parent 3bfd3b5 commit a64e314

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

PlaybookShowcase/PlaybookShowcase/Components/Typeahead/TypeaheadCatalog.swift

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,36 @@ public struct TypeaheadCatalog: View {
1818

1919
private var assetsUsers = Mocks.assetesMultipleUsers
2020
@State private var searchTextUsers: String = ""
21-
@State private var selectedUsers: [PBTypeahead.Option] = [Mocks.assetesMultipleUsers[0], Mocks.assetesMultipleUsers[1]]
21+
@State private var selectedUsers: [PBTypeahead.Option] = [
22+
Mocks.assetesMultipleUsers[0],
23+
Mocks.assetesMultipleUsers[1]
24+
]
2225
@FocusState private var isFocusedUsers
2326

2427
@State private var searchTextDeselectedUsers: String = ""
25-
@State private var selectedUsersDeselected: [PBTypeahead.Option] = [Mocks.assetesMultipleUsers[0], Mocks.assetesMultipleUsers[1]]
28+
@State private var selectedUsersDeselected: [PBTypeahead.Option] = [
29+
Mocks.assetesMultipleUsers[0],
30+
Mocks.assetesMultipleUsers[1]
31+
]
2632
@State private var deselectedUsers: [PBTypeahead.Option] = []
2733
@FocusState private var isFocusedDeselectedUsers
2834

2935
@State private var searchTextHeight: String = ""
30-
@State private var selectedHeight: [PBTypeahead.Option] = [Mocks.assetesMultipleUsers[3], Mocks.assetesMultipleUsers[2]]
36+
@State private var selectedHeight: [PBTypeahead.Option] = [
37+
Mocks.assetesMultipleUsers[3],
38+
Mocks.assetesMultipleUsers[2]
39+
]
3140
@FocusState private var isFocusedHeight
3241

3342
private var assetsSection: [PBTypeahead.OptionType] = Mocks.assetsSectionUsers
3443
@State private var searchTextSections: String = ""
3544
@State private var selectedSections: [PBTypeahead.Option] = []
3645
@FocusState private var isFocusedSection
3746

47+
@State private var searchTextNoOptions: String = ""
48+
@State private var selectedNoOptions: [PBTypeahead.Option] = []
49+
@FocusState private var isFocusedNoOptions
50+
3851
@State private var presentDialog: Bool = false
3952
private var popoverManager = PopoverManager.shared
4053

@@ -48,6 +61,7 @@ public struct TypeaheadCatalog: View {
4861
#endif
4962
PBDoc(title: "Height Adjusted Dropdown", spacing: Spacing.small) { heightAdjusted }
5063
PBDoc(title: "Sections", spacing: Spacing.small) { sections }
64+
PBDoc(title: "No Options", spacing: Spacing.small) { noOptions }
5165
.padding(.bottom, 500)
5266
}
5367
.scrollDismissesKeyboard(.immediately)
@@ -136,6 +150,40 @@ extension TypeaheadCatalog {
136150
)
137151
}
138152

153+
var noOptions: some View {
154+
PBTypeahead(
155+
id: 5,
156+
title: "Users",
157+
placeholder: "type the name of a user",
158+
searchText: $searchTextNoOptions,
159+
options: assetsUsers,
160+
selection: .multiple(variant: .pill),
161+
isFocused: $isFocusedNoOptions,
162+
selectedOptions: $selectedNoOptions,
163+
noOptionsView: {
164+
customNoOptionsText
165+
}
166+
)
167+
}
168+
169+
var customNoOptionsText: some View {
170+
#if os(macOS)
171+
HStack(spacing: Spacing.none) {
172+
Text("No results found. Review user name for accuracy or ")
173+
PBButton(variant: .link, title: "add user name.")
174+
}
175+
.frame(maxWidth: .infinity, alignment: .center)
176+
.pbFont(.detail(false), color: .text(.light))
177+
#elseif os(iOS)
178+
VStack {
179+
Text("No results found. Review user name for accuracy or ")
180+
PBButton(variant: .link, title: "add user name.")
181+
}
182+
.fixedSize(horizontal: true, vertical: false)
183+
.pbFont(.detail(false), color: .text(.light))
184+
#endif
185+
}
186+
139187
var dialog: some View {
140188
PBButton(title: "Simple") {
141189
DialogCatalog.disableAnimation()
@@ -144,9 +192,9 @@ extension TypeaheadCatalog {
144192
.presentationMode(isPresented: $presentDialog) {
145193
DialogView(isPresented: $presentDialog)
146194
.popoverHandler(id: 6)
147-
#if os(macOS)
195+
#if os(macOS)
148196
.frame(minWidth: 500, minHeight: 390)
149-
#endif
197+
#endif
150198
}
151199
}
152200

Sources/Playbook/Components/Typeahead/PBTypeahead+View.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public extension PBTypeahead {
101101
var emptyView: some View {
102102
HStack {
103103
Spacer()
104-
Text(viewModel.noOptionsText)
104+
noOptionsView()
105105
.pbFont(.body, color: .text(.light))
106106
Spacer()
107107
}

Sources/Playbook/Components/Typeahead/PBTypeahead.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public struct PBTypeahead: View {
2929
@Binding internal var deselectedOptions: [PBTypeahead.Option]
3030
@Binding internal var searchText: String
3131
@FocusState.Binding internal var isFocused: Bool
32+
var noOptionsView: () -> AnyView?
3233

3334
#if os(macOS)
3435
@StateObject private var keyboardHandler = TypeaheadKeyboardHandler()
@@ -49,7 +50,11 @@ public struct PBTypeahead: View {
4950
deselectedOptions: Binding<[PBTypeahead.Option]> = .constant([]),
5051
clearAction: (() -> Void)? = nil,
5152
disableFiltering: Bool = false,
52-
disableKeyboardHandler: Bool = false
53+
disableKeyboardHandler: Bool = false,
54+
@ViewBuilder noOptionsView: @escaping () -> some View = {
55+
Text("No Options")
56+
.pbFont(.body, color: .text(.light))
57+
}
5358
) {
5459
self.id = id
5560
self.title = title
@@ -70,6 +75,7 @@ public struct PBTypeahead: View {
7075
))
7176
self._deselectedOptions = deselectedOptions
7277
self.disableKeyboardHandler = disableKeyboardHandler
78+
self.noOptionsView = { AnyView(noOptionsView()) }
7379
}
7480

7581
public var body: some View {

0 commit comments

Comments
 (0)