From 13805f3da7d49e22882d6f87e28296f73385543c Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Tue, 6 Aug 2024 14:48:13 -0400 Subject: [PATCH 01/13] Release --- .../PlaybookShowcase.xcodeproj/project.pbxproj | 8 ++++---- project.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PlaybookShowcase/PlaybookShowcase.xcodeproj/project.pbxproj b/PlaybookShowcase/PlaybookShowcase.xcodeproj/project.pbxproj index 297a0a068..ae5b9d845 100644 --- a/PlaybookShowcase/PlaybookShowcase.xcodeproj/project.pbxproj +++ b/PlaybookShowcase/PlaybookShowcase.xcodeproj/project.pbxproj @@ -298,7 +298,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 6.0.2; + MARKETING_VERSION = ; PRODUCT_BUNDLE_IDENTIFIER = com.powerhrg.PlaybookShowcase; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -336,7 +336,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 6.0.2; + MARKETING_VERSION = ; PRODUCT_BUNDLE_IDENTIFIER = com.powerhrg.PlaybookShowcase; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = "Playbook In House"; @@ -376,7 +376,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.3; - MARKETING_VERSION = 6.0.2; + MARKETING_VERSION = ; PRODUCT_BUNDLE_IDENTIFIER = com.powerhrg.PlaybookShowcase; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -411,7 +411,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 13.3; - MARKETING_VERSION = 6.0.2; + MARKETING_VERSION = ; PRODUCT_BUNDLE_IDENTIFIER = com.powerhrg.PlaybookShowcase; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = "Playbook Showcase Dev ID"; diff --git a/project.yml b/project.yml index c60d1f7b0..67759995f 100644 --- a/project.yml +++ b/project.yml @@ -22,7 +22,7 @@ targets: GENERATE_INFOPLIST_FILE: false PRODUCT_BUNDLE_IDENTIFIER: com.powerhrg.PlaybookShowcase CURRENT_PROJECT_VERSION: 1 - MARKETING_VERSION: 6.0.2 + MARKETING_VERSION: "" Playbook-macOS: type: application platform: macOS @@ -35,4 +35,4 @@ targets: GENERATE_INFOPLIST_FILE: false PRODUCT_BUNDLE_IDENTIFIER: com.powerhrg.PlaybookShowcase CURRENT_PROJECT_VERSION: 1 - MARKETING_VERSION: 6.0.2 + MARKETING_VERSION: "" From a119d21037e9b495de7ef8ca7bed1db117f18c5c Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Tue, 20 Aug 2024 16:59:44 -0400 Subject: [PATCH 02/13] fix typeahead data update --- .../Components/Typeahead/PBTypeahead.swift | 19 +++++++++++----- .../Typeahead/TypeaheadCatalog.swift | 6 ++--- .../Resources/Helper Files/Mocks.swift | 22 +++++++++---------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift index 6abe12c05..8b35d8e28 100644 --- a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift +++ b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift @@ -10,14 +10,14 @@ import SwiftUI public struct PBTypeahead: View { - public typealias Option = (String, (() -> Content?)) + public typealias Option = (String, Content?) private let id: Int private let title: String private let placeholder: String - private let options: [Option] private let selection: Selection private let debounce: (time: TimeInterval, numberOfCharacters: Int) private let dropdownMaxHeight: CGFloat? + private let listOffset: (x: CGFloat, y: CGFloat) private let popoverManager = PopoverManager() private let onSelection: (([Option]) -> Void)? private let clearAction: (() -> Void)? @@ -30,6 +30,7 @@ public struct PBTypeahead: View { @State private var selectedIndex: Int? @State private var selectedOptions: [Option] = [] @State private var focused: Bool = false + @Binding var options: [Option] @Binding var searchText: String @FocusState.Binding private var isFocused: Bool @@ -38,10 +39,11 @@ public struct PBTypeahead: View { title: String, placeholder: String = "Select", searchText: Binding, + options: Binding<[Option]>, selection: Selection, - options: [Option], debounce: (time: TimeInterval, numberOfCharacters: Int) = (0, 0), dropdownMaxHeight: CGFloat? = nil, + listOffset: (x: CGFloat, y: CGFloat) = (0, 0), isFocused: FocusState.Binding, onSelection: @escaping (([Option]) -> Void), clearAction: (() -> Void)? = nil @@ -51,9 +53,10 @@ public struct PBTypeahead: View { self.placeholder = placeholder self._searchText = searchText self.selection = selection - self.options = options + self._options = options self.debounce = debounce self.dropdownMaxHeight = dropdownMaxHeight + self.listOffset = listOffset self._isFocused = isFocused self.clearAction = clearAction self.onSelection = onSelection @@ -76,6 +79,7 @@ public struct PBTypeahead: View { .pbPopover( isPresented: $showList, id: id, + position: .bottom(listOffset.x, listOffset.y), variant: .dropdown, refreshView: $isHovering ) { @@ -85,6 +89,9 @@ public struct PBTypeahead: View { isFocused = false } } + .onChange(of: options.count) { _ in + listOptions = options + } .onAppear { focused = isFocused listOptions = options @@ -128,7 +135,7 @@ private extension PBTypeahead { VStack(spacing: 0) { ForEach(Array(zip(searchResults.indices, searchResults)), id: \.0) { index, result in HStack { - if let customView = result.1() { + if let customView = result.1 { customView } else { Text(result.0) @@ -156,7 +163,7 @@ private extension PBTypeahead { .frame(maxWidth: .infinity, alignment: .top) .transition(.opacity) } - + var searchResults: [Option] { switch selection{ case .multiple: diff --git a/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift b/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift index 3d5c869d9..e00e7ad4c 100644 --- a/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift +++ b/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift @@ -49,8 +49,8 @@ extension TypeaheadCatalog { id: 1, title: "Colors", searchText: $searchTextColors, + options: $assetsColors, selection: .single, - options: assetsColors, isFocused: $isFocused1 ) {_ in } } @@ -61,8 +61,8 @@ extension TypeaheadCatalog { title: "Users", placeholder: "type the name of a user", searchText: $searchTextUsers, + options: $assetsUsers, selection: .multiple(variant: .pill), - options: assetsUsers, isFocused: $isFocused2 ) {_ in } } @@ -103,8 +103,8 @@ extension TypeaheadCatalog { title: "Users", placeholder: "type the name of a user", searchText: $searchTextUsers, + options: $assetsUsers, selection: .multiple(variant: .pill), - options: assetsUsers, dropdownMaxHeight: 300, isFocused: $isFocused ) { options in diff --git a/Sources/Playbook/Resources/Helper Files/Mocks.swift b/Sources/Playbook/Resources/Helper Files/Mocks.swift index d263ab749..d589229d4 100644 --- a/Sources/Playbook/Resources/Helper Files/Mocks.swift +++ b/Sources/Playbook/Resources/Helper Files/Mocks.swift @@ -19,7 +19,7 @@ enum Mocks { static let twoUsers = [andrew, ana] static let threeUsers = [andrew, ana, patric] static let multipleUsers = [andrew, ana, patric, luccile] - static let multipleUsersDictionary: [(String, () -> PBUser?)] = [(andrew.name, { andrew }), (ana.name, { ana }), (patric.name, { patric }), (luccile.name, { luccile })] + static let multipleUsersDictionary: [(String, PBUser?)] = [(andrew.name, andrew), (ana.name, ana), (patric.name, patric), (luccile.name, luccile)] static let avatarXSmall = PBAvatar(image: Image("andrew", bundle: .module), size: .xSmall) static let avatarXSmallStatus = PBAvatar(image: Image("andrew", bundle: .module), size: .xSmall, status: .online) static let userName = "Andrew Black" @@ -28,16 +28,16 @@ enum Mocks { static let picAnna = PBAvatar(image: Image("Anna", bundle: .module), size: .xSmall, status: .online) static let picPatric = PBAvatar(image: Image("Pat", bundle: .module), size: .xSmall) static let picLuccile = PBAvatar(image: Image("Lu", bundle: .module), size: .xSmall) - static let assetsColors: [(String, () -> AnyView?)] = [ - ("Orange", { nil }), - ("Red", { nil }), - ("Green", { nil }), - ("Blue", { nil }), - ("Pink", { nil }), - ("Yellow", { nil }), - ("Violet", { nil }), - ("Indigo", { nil }), - ("Magenta", { nil }) + static let assetsColors: [(String, AnyView?)] = [ + ("Orange", nil), + ("Red", nil), + ("Green", nil), + ("Blue", nil), + ("Pink", nil), + ("Yellow", nil), + ("Violet", nil), + ("Indigo", nil), + ("Magenta", nil) ] static let cities: [String] = [ "Philadelphia", From 73f4521a3060d73950f0d459fb4ec353067ff097 Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Tue, 27 Aug 2024 13:49:22 -0400 Subject: [PATCH 03/13] fix options type --- Sources/Playbook/Components/Typeahead/PBTypeahead.swift | 4 ++-- Sources/Playbook/Resources/Helper Files/Mocks.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift index 8b35d8e28..f96dc92a4 100644 --- a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift +++ b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift @@ -10,7 +10,7 @@ import SwiftUI public struct PBTypeahead: View { - public typealias Option = (String, Content?) + public typealias Option = (String, (() -> Content?)?) private let id: Int private let title: String private let placeholder: String @@ -135,7 +135,7 @@ private extension PBTypeahead { VStack(spacing: 0) { ForEach(Array(zip(searchResults.indices, searchResults)), id: \.0) { index, result in HStack { - if let customView = result.1 { + if let customView = result.1?() { customView } else { Text(result.0) diff --git a/Sources/Playbook/Resources/Helper Files/Mocks.swift b/Sources/Playbook/Resources/Helper Files/Mocks.swift index d589229d4..3c64935b5 100644 --- a/Sources/Playbook/Resources/Helper Files/Mocks.swift +++ b/Sources/Playbook/Resources/Helper Files/Mocks.swift @@ -19,7 +19,7 @@ enum Mocks { static let twoUsers = [andrew, ana] static let threeUsers = [andrew, ana, patric] static let multipleUsers = [andrew, ana, patric, luccile] - static let multipleUsersDictionary: [(String, PBUser?)] = [(andrew.name, andrew), (ana.name, ana), (patric.name, patric), (luccile.name, luccile)] + static let multipleUsersDictionary: [(String, (() -> PBUser?)?)] = [(andrew.name, { andrew }), (ana.name, { ana }), (patric.name, { patric }), (luccile.name, { luccile })] static let avatarXSmall = PBAvatar(image: Image("andrew", bundle: .module), size: .xSmall) static let avatarXSmallStatus = PBAvatar(image: Image("andrew", bundle: .module), size: .xSmall, status: .online) static let userName = "Andrew Black" @@ -28,7 +28,7 @@ enum Mocks { static let picAnna = PBAvatar(image: Image("Anna", bundle: .module), size: .xSmall, status: .online) static let picPatric = PBAvatar(image: Image("Pat", bundle: .module), size: .xSmall) static let picLuccile = PBAvatar(image: Image("Lu", bundle: .module), size: .xSmall) - static let assetsColors: [(String, AnyView?)] = [ + static let assetsColors: [(String, (() -> AnyView?)?)] = [ ("Orange", nil), ("Red", nil), ("Green", nil), From 9aa63c1026d1c1f71e5b697e773b314007c64e5d Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Fri, 30 Aug 2024 11:56:50 -0400 Subject: [PATCH 04/13] changed type --- Sources/Playbook/Components/Typeahead/PBTypeahead.swift | 6 +++--- .../Playbook/Components/Typeahead/TypeaheadCatalog.swift | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift index f96dc92a4..9af279957 100644 --- a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift +++ b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift @@ -10,7 +10,7 @@ import SwiftUI public struct PBTypeahead: View { - public typealias Option = (String, (() -> Content?)?) + public typealias Option = (id: String, value: (String, (() -> Content?)?)?) private let id: Int private let title: String private let placeholder: String @@ -135,10 +135,10 @@ private extension PBTypeahead { VStack(spacing: 0) { ForEach(Array(zip(searchResults.indices, searchResults)), id: \.0) { index, result in HStack { - if let customView = result.1?() { + if let customView = result.1?.1?() { customView } else { - Text(result.0) + Text(result.1?.0 ?? result.0) .pbFont(.body, color: listTextolor(index)) } } diff --git a/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift b/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift index e00e7ad4c..489dfe416 100644 --- a/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift +++ b/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift @@ -10,8 +10,8 @@ import SwiftUI public struct TypeaheadCatalog: View { - @State private var assetsColors = Mocks.assetsColors - @State private var assetsUsers = Mocks.multipleUsersDictionary + @State private var assetsColors = Mocks.assetsColors.map { ($0.0, $0) } + @State private var assetsUsers = Mocks.multipleUsersDictionary.map { ($0.0, $0) } @State private var searchTextUsers: String = "" @State private var searchTextColors: String = "" @State private var searchText: String = "" @@ -20,7 +20,7 @@ public struct TypeaheadCatalog: View { @State private var isPresented1: Bool = false @State private var presentDialog: Bool = false @State private var isLoading: Bool = false - @State private var assetsUser = Mocks.multipleUsersDictionary + @State private var assetsUser = Mocks.multipleUsersDictionary.map { ($0.0, $0) } @FocusState var isFocused1 @FocusState var isFocused2 @@ -89,7 +89,7 @@ extension TypeaheadCatalog { @Binding var isPresented: Bool @State private var isLoading: Bool = false @State private var searchTextUsers: String = "" - @State private var assetsUsers = Mocks.multipleUsersDictionary + @State private var assetsUsers = Mocks.multipleUsersDictionary.map { ($0.0, $0) } @FocusState var isFocused var body: some View { From d1d236e95a2950b857d72fb73c7e00baf1f848d2 Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Fri, 30 Aug 2024 14:53:19 -0400 Subject: [PATCH 05/13] Add id to typeahead options type --- .../Components/Typeahead/PBTypeahead.swift | 11 ++++++-- .../Typeahead/TypeaheadCatalog.swift | 27 ++++++++++++++----- .../Resources/Helper Files/Mocks.swift | 10 +++++-- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift index 9af279957..f3f17368e 100644 --- a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift +++ b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift @@ -10,7 +10,7 @@ import SwiftUI public struct PBTypeahead: View { - public typealias Option = (id: String, value: (String, (() -> Content?)?)?) + public typealias Option = (String, (String, (() -> Content?)?)?) private let id: Int private let title: String private let placeholder: String @@ -178,7 +178,13 @@ private extension PBTypeahead { } var optionsSelected: GridInputField.Selection { - let optionsSelected = selectedOptions.map { $0.0 } + let optionsSelected = selectedOptions.map { value in + if let content = value.1 { + return content.0 + } else { + return value.0 + } + } return selection.selectedOptions(options: optionsSelected, placeholder: placeholder) } @@ -287,6 +293,7 @@ private extension PBTypeahead { func removeSelected(_ index: Int) { if let selectedElementIndex = selectedOptions.indices.first(where: { $0 == index }) { let selectedElement = selectedOptions.remove(at: selectedElementIndex) + onSelection?(selectedOptions) listOptions.append(selectedElement) selectedIndex = nil } diff --git a/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift b/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift index 489dfe416..2e5dc83e5 100644 --- a/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift +++ b/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift @@ -10,8 +10,9 @@ import SwiftUI public struct TypeaheadCatalog: View { - @State private var assetsColors = Mocks.assetsColors.map { ($0.0, $0) } - @State private var assetsUsers = Mocks.multipleUsersDictionary.map { ($0.0, $0) } + @State private var assetsColors = Mocks.assetsColors + @State private var assetsUsers = Mocks.multipleUsersDictionary + @State private var selectedUsers: [(String, (String, (() -> PBUser?)?)?)] = [] @State private var searchTextUsers: String = "" @State private var searchTextColors: String = "" @State private var searchText: String = "" @@ -20,7 +21,7 @@ public struct TypeaheadCatalog: View { @State private var isPresented1: Bool = false @State private var presentDialog: Bool = false @State private var isLoading: Bool = false - @State private var assetsUser = Mocks.multipleUsersDictionary.map { ($0.0, $0) } + @State private var assetsUser = Mocks.multipleUsersDictionary @FocusState var isFocused1 @FocusState var isFocused2 @@ -29,7 +30,17 @@ public struct TypeaheadCatalog: View { public var body: some View { PBDocStack(title: "Typeahead") { PBDoc(title: "Default", spacing: Spacing.small) { colors } - PBDoc(title: "With Pills", spacing: Spacing.small) { users } + PBDoc(title: "With Pills", spacing: Spacing.small) { + VStack { + users + + ForEach(selectedUsers, id: \.0) { user in + Text(user.1?.0 ?? user.0) + + } + + } + } #if os(macOS) PBDoc(title: "Dialog") { dialog } #endif @@ -64,7 +75,11 @@ extension TypeaheadCatalog { options: $assetsUsers, selection: .multiple(variant: .pill), isFocused: $isFocused2 - ) {_ in } + ) { selected in + selectedUsers = selected + print(selected) + } + } func closeToast() { @@ -89,7 +104,7 @@ extension TypeaheadCatalog { @Binding var isPresented: Bool @State private var isLoading: Bool = false @State private var searchTextUsers: String = "" - @State private var assetsUsers = Mocks.multipleUsersDictionary.map { ($0.0, $0) } + @State private var assetsUsers = Mocks.multipleUsersDictionary @FocusState var isFocused var body: some View { diff --git a/Sources/Playbook/Resources/Helper Files/Mocks.swift b/Sources/Playbook/Resources/Helper Files/Mocks.swift index 3c64935b5..c1671bfe0 100644 --- a/Sources/Playbook/Resources/Helper Files/Mocks.swift +++ b/Sources/Playbook/Resources/Helper Files/Mocks.swift @@ -19,7 +19,12 @@ enum Mocks { static let twoUsers = [andrew, ana] static let threeUsers = [andrew, ana, patric] static let multipleUsers = [andrew, ana, patric, luccile] - static let multipleUsersDictionary: [(String, (() -> PBUser?)?)] = [(andrew.name, { andrew }), (ana.name, { ana }), (patric.name, { patric }), (luccile.name, { luccile })] + static let multipleUsersDictionary: [(String, (String, (() -> PBUser?)?)?)] = [ + ("1", (andrew.name, { andrew })), + ("2", (ana.name, { ana })), + ("3", (patric.name, { patric })), + ("4", (luccile.name, { luccile })) + ] static let avatarXSmall = PBAvatar(image: Image("andrew", bundle: .module), size: .xSmall) static let avatarXSmallStatus = PBAvatar(image: Image("andrew", bundle: .module), size: .xSmall, status: .online) static let userName = "Andrew Black" @@ -28,7 +33,7 @@ enum Mocks { static let picAnna = PBAvatar(image: Image("Anna", bundle: .module), size: .xSmall, status: .online) static let picPatric = PBAvatar(image: Image("Pat", bundle: .module), size: .xSmall) static let picLuccile = PBAvatar(image: Image("Lu", bundle: .module), size: .xSmall) - static let assetsColors: [(String, (() -> AnyView?)?)] = [ + static let assetsColors: [(String, (String, (() -> AnyView?)?)?)] = [ ("Orange", nil), ("Red", nil), ("Green", nil), @@ -39,6 +44,7 @@ enum Mocks { ("Indigo", nil), ("Magenta", nil) ] + static let cities: [String] = [ "Philadelphia", "New York", From 16c8cd6560b663faebbb65c65a2a39f5d778209f Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Fri, 30 Aug 2024 16:02:31 -0400 Subject: [PATCH 06/13] no message --- .../Components/Typeahead/TypeaheadCatalog.swift | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift b/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift index 2e5dc83e5..715deb2e7 100644 --- a/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift +++ b/Sources/Playbook/Components/Typeahead/TypeaheadCatalog.swift @@ -30,17 +30,7 @@ public struct TypeaheadCatalog: View { public var body: some View { PBDocStack(title: "Typeahead") { PBDoc(title: "Default", spacing: Spacing.small) { colors } - PBDoc(title: "With Pills", spacing: Spacing.small) { - VStack { - users - - ForEach(selectedUsers, id: \.0) { user in - Text(user.1?.0 ?? user.0) - - } - - } - } + PBDoc(title: "With Pills", spacing: Spacing.small) { users } #if os(macOS) PBDoc(title: "Dialog") { dialog } #endif @@ -63,7 +53,7 @@ extension TypeaheadCatalog { options: $assetsColors, selection: .single, isFocused: $isFocused1 - ) {_ in } + ) { _ in } } var users: some View { From 2b81f85e38c4685599d578f41b800d0b5d932f0b Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Mon, 23 Sep 2024 11:19:53 -0400 Subject: [PATCH 07/13] fix typeahead filter --- .../Components/Typeahead/PBTypeahead.swift | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift index 73b10a4ba..a6925d87b 100644 --- a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift +++ b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift @@ -165,18 +165,26 @@ private extension PBTypeahead { } var searchResults: [Option] { - switch selection{ - case .multiple: - return searchText.isEmpty && debounce.numberOfCharacters == 0 ? listOptions : listOptions.filter { - $0.0.localizedCaseInsensitiveContains(searchText) - } - case .single: - return searchText.isEmpty && debounce.numberOfCharacters == 0 ? options : options.filter { - $0.0.localizedCaseInsensitiveContains(searchText) - } - } + 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 { + if let text = $0.1?.0 { + text.localizedCaseInsensitiveContains(searchText) + } else { + $0.0.localizedCaseInsensitiveContains(searchText) + } + } + } } - + var optionsSelected: GridInputField.Selection { let optionsSelected = selectedOptions.map { value in if let content = value.1 { From 096954fb1ff7795318c3a5f1d4ab795bdf57c1cd Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Mon, 23 Sep 2024 11:40:08 -0400 Subject: [PATCH 08/13] fix filter --- .../Components/Typeahead/PBTypeahead.swift | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift index f3f17368e..2e0676027 100644 --- a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift +++ b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift @@ -165,18 +165,26 @@ private extension PBTypeahead { } var searchResults: [Option] { - switch selection{ - case .multiple: - return searchText.isEmpty && debounce.numberOfCharacters == 0 ? listOptions : listOptions.filter { - $0.0.localizedCaseInsensitiveContains(searchText) - } - case .single: - return searchText.isEmpty && debounce.numberOfCharacters == 0 ? options : options.filter { - $0.0.localizedCaseInsensitiveContains(searchText) - } - } + 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 { + if let text = $0.1?.0 { + text.localizedCaseInsensitiveContains(searchText) + } else { + $0.0.localizedCaseInsensitiveContains(searchText) + } + } + } } - + var optionsSelected: GridInputField.Selection { let optionsSelected = selectedOptions.map { value in if let content = value.1 { From b986f2121e0be0c9ee836da29edd0cbbc6af3f54 Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Mon, 23 Sep 2024 13:46:37 -0400 Subject: [PATCH 09/13] fix keyboard dismiss --- .../Components/Typeahead/PBTypeahead.swift | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift index 2e0676027..7777c7bc9 100644 --- a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift +++ b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift @@ -71,7 +71,7 @@ public struct PBTypeahead: View { searchText: $searchText, selection: optionsSelected, isFocused: $isFocused, - clearAction: { clearText }, + clearAction: { clear }, onItemTap: { removeSelected($0) }, onViewTap: { onViewTap } ) @@ -157,6 +157,7 @@ private extension PBTypeahead { } } } + .scrollDismissesKeyboard(.immediately) .frame(maxHeight: dropdownMaxHeight) .fixedSize(horizontal: false, vertical: true) } @@ -196,18 +197,24 @@ private extension PBTypeahead { return selection.selectedOptions(options: optionsSelected, placeholder: placeholder) } - var clearText: Void { + var clear: Void { if let action = clearAction { action() + clearText } else { - searchText = "" - selectedOptions.removeAll() - listOptions = options - selectedIndex = nil - hoveringIndex = nil - showList = false + clearText } } + + var clearText: Void { + searchText = "" + selectedOptions.removeAll() + onSelection?([]) + listOptions = options + selectedIndex = nil + hoveringIndex = nil + showList = false + } var setKeyboardControls: Void { #if os(macOS) From fdc3c4a3028548fd366fcc1e42a574d05076f6aa Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Wed, 25 Sep 2024 14:09:30 -0400 Subject: [PATCH 10/13] fix grid spacings --- Sources/Playbook/Components/Grid/PBGrid.swift | 10 +- .../Components/Typeahead/GridInputField.swift | 102 +++++++++--------- 2 files changed, 57 insertions(+), 55 deletions(-) diff --git a/Sources/Playbook/Components/Grid/PBGrid.swift b/Sources/Playbook/Components/Grid/PBGrid.swift index 77b280e4c..0cfaa0553 100644 --- a/Sources/Playbook/Components/Grid/PBGrid.swift +++ b/Sources/Playbook/Components/Grid/PBGrid.swift @@ -17,7 +17,7 @@ public struct PBGrid: Layout { public init( alignment: Alignment = .leading, - horizontalSpacing: CGFloat? = 8, + horizontalSpacing: CGFloat? = nil, verticalSpacing: CGFloat? = nil, fitContent: Bool = true ) { @@ -134,14 +134,12 @@ public extension PBGrid { for index in rows.indices { let maxHeightIndex = rows[index].elements - .max { $0.size.height < $1.size.height }! + .max { $0.size.height < $1.size.height }? .index - - let size = sizes[maxHeightIndex] - + let size = sizes[maxHeightIndex ?? 0] var spacing = CGFloat.zero if let previousMaxHeightIndex { - spacing = verticalSpacing(subviews[previousMaxHeightIndex], subviews[maxHeightIndex]) + spacing = verticalSpacing(subviews[previousMaxHeightIndex], subviews[maxHeightIndex ?? 0]) } rows[index].yOffset = currentY + spacing diff --git a/Sources/Playbook/Components/Typeahead/GridInputField.swift b/Sources/Playbook/Components/Typeahead/GridInputField.swift index 63a0f6e38..87a15abc6 100644 --- a/Sources/Playbook/Components/Typeahead/GridInputField.swift +++ b/Sources/Playbook/Components/Typeahead/GridInputField.swift @@ -21,7 +21,7 @@ public struct GridInputField: View { @State private var clearButtonIsHovering: Bool = false @State private var indicatorIsHovering: Bool = false var isFocused: FocusState.Binding - + init( placeholder: String = "Select", searchText: Binding, @@ -39,37 +39,45 @@ public struct GridInputField: View { self.onItemTap = onItemTap self.onViewTap = onViewTap } - + public var body: some View { VStack(alignment: .leading) { HStack { - HStack { - PBGrid(alignment: .leading, horizontalSpacing: 0) { - ForEach(indices, id: \.self) { index in - if indices.last != index { - gridView(index: index) - } - } - } - .layoutPriority(1) - textfieldWithCustomPlaceholder - .overlay { - Color.white - .opacity(isFocused.wrappedValue ? 0.001 : 0) - .onTapGesture { - if isFocused.wrappedValue { - onViewTap?() - } + PBGrid( + alignment: .leading, + horizontalSpacing: Spacing.xSmall, + verticalSpacing: Spacing.xSmall, + fitContent: false + ) { + ForEach(indices, id: \.self) { index in + if indices.last != index { + gridView(index: index) + } else { + textfieldWithCustomPlaceholder + .fixedSize() + .frame(minWidth: 100, alignment: .leading) + .overlay { + Color.white + .opacity(isFocused.wrappedValue ? 0.001 : 0) + .onTapGesture { + if isFocused.wrappedValue { + onViewTap?() + } + } } + .clipped() } + } } + .padding(.horizontal, Spacing.small) + .padding(.vertical, Spacing.xSmall) + .background(Color.white.opacity(0.01)) .onTapGesture { isFocused.wrappedValue = true if isFocused.wrappedValue { onViewTap?() } } - dismissIconView indicatorView } @@ -107,34 +115,30 @@ private extension GridInputField { .textFieldStyle(.plain) .pbFont(.body, color: textColor) } - .frame(maxWidth: .infinity) - .frame(height: Spacing.xLarge) - .padding(.leading, Spacing.small) } - - @ViewBuilder - func gridView(index: Int?) -> some View { + + func gridView(index: Int?) -> AnyView? { switch selection { case .multiple(let variant, let options): if let index = index, let option = options?[index] { - variant.view(text: option) - .onTapGesture { onItemTap?(index) } - .padding(.leading, Spacing.xSmall) - .padding(.vertical, Spacing.xSmall) - .fixedSize() + return AnyView( + variant.view(text: option) + .onTapGesture { onItemTap?(index) } + ) + } else { + return nil } - case .single: - EmptyView() + case .single: return nil } } - + var placeholderText: String { switch selection { case .multiple(_, let elements): return elements?.isEmpty ?? true ? placeholder : "" case .single(let element): return element ?? placeholder } } - + var placeholderTextColor: Color { switch selection { case .multiple(_, _): return .text(.light) @@ -142,15 +146,15 @@ private extension GridInputField { return element == nil ? .text(.light) : .text(.default) } } - + var textColor: Color { return .text(.default) } - + var borderColor: Color { isFocused.wrappedValue ? .pbPrimary : .border } - + @ViewBuilder var dismissIconView: some View { Group { @@ -169,7 +173,7 @@ private extension GridInputField { clearAction?() } } - + var dismissIcon: some View { PBIcon(FontAwesome.times, size: .xSmall) .foregroundStyle(iconColor(on: clearButtonIsHovering)) @@ -180,11 +184,11 @@ private extension GridInputField { isHovering = $0 } } - + var backgroundColor: Color { (isHovering || isFocused.wrappedValue) ? .background(.light) : .card } - + var indicatorView: some View { PBIcon(FontAwesome.chevronDown, size: .xSmall) .padding(Spacing.small) @@ -198,7 +202,7 @@ private extension GridInputField { onViewTap?() } } - + func iconColor(on hover: Bool) -> Color { if isFocused.wrappedValue, !hover { return Color.text(.light) @@ -215,10 +219,10 @@ private extension GridInputField { public extension GridInputField { enum Selection { case single(String?), multiple(Selection.Variant, [String]?) - + public enum Variant { case text, pill, other(AnyView) - + @ViewBuilder func view(text: String) -> some View { switch self { @@ -247,19 +251,19 @@ public struct WrappedInputFieldCatalog: View { selection: .single(nil), isFocused: $isFocused ) - + GridInputField( searchText: $text, - selection: .multiple(.pill, ["title1", "title2"]), + selection: .multiple(.pill, ["title1", "title2", "title2", "title2", "title2"]), isFocused: $isFocused ) - + GridInputField( searchText: $text, - selection: .multiple(.other(AnyView(PBPill("oi", variant: .primary))), ["title1", "title2"]), + selection: .multiple(.other(AnyView(PBPill("oi", variant: .primary))), ["title1", "title2", "title2", "title2", "title2", "title2", "title2", "title2"]), isFocused: $isFocused ) - + GridInputField( searchText: $text, selection: .multiple(.other(AnyView(PBBadge(text: "title", variant: .primary))), ["title1", "title2"]), From 589916456979783381f79a20dcc0eaba5a1815e6 Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Thu, 26 Sep 2024 10:09:28 -0400 Subject: [PATCH 11/13] change text input area min width --- Sources/Playbook/Components/Typeahead/GridInputField.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Playbook/Components/Typeahead/GridInputField.swift b/Sources/Playbook/Components/Typeahead/GridInputField.swift index 87a15abc6..3d1f24d4d 100644 --- a/Sources/Playbook/Components/Typeahead/GridInputField.swift +++ b/Sources/Playbook/Components/Typeahead/GridInputField.swift @@ -55,7 +55,7 @@ public struct GridInputField: View { } else { textfieldWithCustomPlaceholder .fixedSize() - .frame(minWidth: 100, alignment: .leading) + .frame(minWidth: 60, alignment: .leading) .overlay { Color.white .opacity(isFocused.wrappedValue ? 0.001 : 0) From fe3eec9d0a8af1ae25eff1e6c8abe587ed639e05 Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Thu, 26 Sep 2024 10:21:13 -0400 Subject: [PATCH 12/13] turn font public --- .../Playbook/Design Elements/Typography/Font+Playbook.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Playbook/Design Elements/Typography/Font+Playbook.swift b/Sources/Playbook/Design Elements/Typography/Font+Playbook.swift index 9eb48ec2a..dbb891097 100644 --- a/Sources/Playbook/Design Elements/Typography/Font+Playbook.swift +++ b/Sources/Playbook/Design Elements/Typography/Font+Playbook.swift @@ -26,9 +26,9 @@ public enum PBFont: Equatable { case messageTitle case messageBody - static let proximaNovaLight = Font.ProximaNova.light.rawValue + static let proximaNovaLight = Font.ProximaNova.light.rawValue - var font: Font { + public var font: Font { switch self { case .title1: return Font.custom( From 11810608f3933ff89deb9a4c698082a76299e14e Mon Sep 17 00:00:00 2001 From: "isis.silva" Date: Thu, 26 Sep 2024 10:27:04 -0400 Subject: [PATCH 13/13] removed duplicated code --- Sources/Playbook/Components/Typeahead/PBTypeahead.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift index 908548d00..ad10be9e1 100644 --- a/Sources/Playbook/Components/Typeahead/PBTypeahead.swift +++ b/Sources/Playbook/Components/Typeahead/PBTypeahead.swift @@ -201,7 +201,6 @@ private extension PBTypeahead { if let action = clearAction { clearText action() - clearText } else { clearText }