diff --git a/Backpack-SwiftUI/AppSearchModal/Classes/BPKAppSearchModal.swift b/Backpack-SwiftUI/AppSearchModal/Classes/BPKAppSearchModal.swift index 7e4328ec7..2354cfc78 100644 --- a/Backpack-SwiftUI/AppSearchModal/Classes/BPKAppSearchModal.swift +++ b/Backpack-SwiftUI/AppSearchModal/Classes/BPKAppSearchModal.swift @@ -22,13 +22,13 @@ public struct BPKAppSearchModal: View { let title: String @Binding var inputText: String let inputPrefix: BPKSearchInputSummary.InputPrefix + let clearAction: BPKSearchInputSummary.ClearAction let inputHint: String let results: BPKAppSearchModalResults let closeAccessibilityLabel: String let onClose: () -> Void - private var textFieldState: TextFieldState = .default @FocusState private var inputFieldIsFocussed: Bool - + public init( title: String, inputText: Binding, @@ -36,6 +36,7 @@ public struct BPKAppSearchModal: View { results: BPKAppSearchModalResults, closeAccessibilityLabel: String, inputPrefix: BPKSearchInputSummary.InputPrefix = .icon(.search), + clearAction: BPKSearchInputSummary.ClearAction, onClose: @escaping () -> Void ) { self.title = title @@ -44,6 +45,7 @@ public struct BPKAppSearchModal: View { self.results = results self.closeAccessibilityLabel = closeAccessibilityLabel self.inputPrefix = inputPrefix + self.clearAction = clearAction self.onClose = onClose } @@ -52,11 +54,7 @@ public struct BPKAppSearchModal: View { makeNavigationBar(title: title, closeAccessibilityLabel: closeAccessibilityLabel, onClose: onClose) .padding(.horizontal, .base) if results.showTextField { - BPKSearchInputSummary(placeholder: inputHint, inputPrefix: inputPrefix, $inputText) - .inputState(textFieldState.inputState) - .focused($inputFieldIsFocussed) - .autocorrectionDisabled(true) - .padding(.horizontal, .base) + searchInputSummary } switch results { case .loading(let loading): @@ -76,6 +74,18 @@ public struct BPKAppSearchModal: View { .background(.surfaceDefaultColor) } + private var searchInputSummary: some View { + BPKSearchInputSummary( + placeholder: inputHint, + inputPrefix: inputPrefix, + clearAction: clearAction, + $inputText + ) + .focused($inputFieldIsFocussed) + .autocorrectionDisabled(true) + .padding(.horizontal, .base) + } + func makeNavigationBar( title: String, closeAccessibilityLabel: String, @@ -93,12 +103,6 @@ public struct BPKAppSearchModal: View { .padding(.vertical, .md) } - public func inputState(_ state: TextFieldState) -> BPKAppSearchModal { - var result = self - result.textFieldState = state - return result - } - private func onScroll(_ offset: CGPoint) { inputFieldIsFocussed = false } @@ -125,6 +129,7 @@ struct BPKAppSearchModal_Previews: PreviewProvider { )), closeAccessibilityLabel: "Close", inputPrefix: .icon(.search), + clearAction: .init(accessibilityLabel: "clear", action: {}), onClose: { } ) .previewDisplayName("Content") @@ -136,6 +141,7 @@ struct BPKAppSearchModal_Previews: PreviewProvider { results: .loading(.init(accessibilityLabel: "Loading")), closeAccessibilityLabel: "Close", inputPrefix: .text("From"), + clearAction: .init(accessibilityLabel: "clear", action: {}), onClose: { } ) .previewDisplayName("Loading") @@ -152,6 +158,7 @@ struct BPKAppSearchModal_Previews: PreviewProvider { )), closeAccessibilityLabel: "Close", + clearAction: .init(accessibilityLabel: "clear", action: {}), onClose: { } ) .previewDisplayName("Error") diff --git a/Backpack-SwiftUI/AppSearchModal/README.md b/Backpack-SwiftUI/AppSearchModal/README.md index 02dbdd65d..12a25a334 100644 --- a/Backpack-SwiftUI/AppSearchModal/README.md +++ b/Backpack-SwiftUI/AppSearchModal/README.md @@ -32,12 +32,15 @@ Example of a AppSearchModal in Content state: import Backpack_SwiftUI BPKAppSearchModal( title: "Search Modal", - inputText: $myText, + inputPrefix: BPKSearchInputSummary.InputPrefix.text("Prefix") + clearAction: BPKSearchInputSummary.ClearAction(accessibilityLabel: "Clear", action: {}), inputHint: "Search", results: .content(.init( sections: [ /* sections */ ], shortcuts: [ /* shortcuts */ ] )), + inputPrefix: BPKSearchInputSummary.InputPrefix.text("Prefix"), + clearAction: BPKSearchInputSummary.ClearAction(accessibilityLabel: "Clear", action: {}), closeAccessibilityLabel: "Close", onClose: { } ) @@ -53,6 +56,8 @@ BPKAppSearchModal( inputText: $myText, inputHint: "Search", results: .loading(.init(accessibilityLabel: "Loading")), + inputPrefix: BPKSearchInputSummary.InputPrefix.text("Prefix"), + clearAction: BPKSearchInputSummary.ClearAction(accessibilityLabel: "Clear", action: {}), closeAccessibilityLabel: "Close", onClose: { /* close modal*/ } ) @@ -75,6 +80,8 @@ BPKAppSearchModal( )), closeAccessibilityLabel: "Close", + inputPrefix: BPKSearchInputSummary.InputPrefix.text("Prefix"), + clearAction: BPKSearchInputSummary.ClearAction(accessibilityLabel: "Clear", action: {}), onClose: { /* close modal*/ } ) ``` diff --git a/Backpack-SwiftUI/SearchInputSummary/Classes/BPKSearchInputSummary.swift b/Backpack-SwiftUI/SearchInputSummary/Classes/BPKSearchInputSummary.swift index 75b4e454c..1996ced57 100644 --- a/Backpack-SwiftUI/SearchInputSummary/Classes/BPKSearchInputSummary.swift +++ b/Backpack-SwiftUI/SearchInputSummary/Classes/BPKSearchInputSummary.swift @@ -22,6 +22,7 @@ import SwiftUI /// /// Use `inputState(_ state: State)` to change the state of the text field. public struct BPKSearchInputSummary: View { + public enum InputPrefix { case text(String) case icon(BPKIcon) @@ -35,22 +36,33 @@ public struct BPKSearchInputSummary: View { @Binding private var text: String @FocusState private var focused: Bool private let placeholder: String - private let inputPrefix: InputPrefix - private var state: State = .default + private let inputPrefix: InputPrefix? + private var style: Style = .default + + private let readOnly: Bool + private let clearAction: ClearAction + + public struct ClearAction { + public let accessibilityLabel: String + public let action: () -> Void + + public init(accessibilityLabel: String, action: @escaping () -> Void) { + self.accessibilityLabel = accessibilityLabel + self.action = action + } + } - /// Creates a `BPKSearchInputSummary`. - /// - /// - Parameters: - /// - placeholder: The placeholder text to display when the text field is empty. - /// - inputPrefix: The prefix which would be displayed on the left of text input - /// - text: The text to display in the text field. public init( placeholder: String = "", - inputPrefix: InputPrefix = .icon(.search), + inputPrefix: InputPrefix? = nil, + clearAction: ClearAction, + readOnly: Bool = false, _ text: Binding ) { self.placeholder = placeholder self.inputPrefix = inputPrefix + self.clearAction = clearAction + self.readOnly = readOnly self._text = text } @@ -60,19 +72,25 @@ public struct BPKSearchInputSummary: View { .accessibilityHidden(true) TextField(placeholder, text: $text, prompt: placeholderView) .font(style: .bodyDefault) - .foregroundColor(state.textColor) - .disabled(state.isDisabled) + .foregroundColor(.textPrimaryColor) + .disabled(readOnly) + .accessibilityElement() + .accessibilityValue(text.isEmpty ? placeholder : text) + .accessibilityAddTraits(readOnly ? [] : .isSearchField) + .accessibilityAddTraits(style == .focused ? .isSelected : []) .focused($focused) - .accessibilityAddTraits(.isSearchField) - .accessibilityLabel(placeholder) - .accessibilityIdentifier("search_field") accessory } .frame(maxWidth: .infinity, minHeight: 48.0) .padding(.horizontal, BPKSpacing.base) .background(.surfaceDefaultColor) - .clipShape(RoundedRectangle(cornerRadius: .sm)) - .outline(focused ? .textLinkColor : state.borderColor, cornerRadius: .sm, lineWidth: focused ? 2.0 : 1.0) + .clipShape(RoundedRectangle(cornerRadius: .md)) + .outline( + isBorderHighlighted ? .textLinkColor : .lineColor, + cornerRadius: .md, + lineWidth: isBorderHighlighted ? 2.0 : 1.0 + ) + .if(!BPKFont.enableDynamicType, transform: { $0.sizeCategory(.large) }) @@ -80,22 +98,14 @@ public struct BPKSearchInputSummary: View { @ViewBuilder private var accessory: some View { - if let icon = state.icon { - if case let .clear(accessibilityLabel, action) = state { - Button(action: action) { - BPKIconView(icon.icon) - .foregroundColor(icon.color) - } - .accessibilityElement(children: .ignore) - .accessibilityLabel(accessibilityLabel) - .accessibilityAddTraits(.isButton) - .opacity(text.isEmpty ? 0.0 : 1.0) - } else { - BPKIconView(icon.icon) - .foregroundColor(icon.color) - .accessibilityHidden(true) - } + Button(action: clearAction.action) { + BPKIconView(.closeCircle) + .foregroundColor(.textSecondaryColor) } + .accessibilityElement(children: .ignore) + .accessibilityLabel(clearAction.accessibilityLabel) + .accessibilityAddTraits(.isButton) + .opacity(text.isEmpty ? 0.0 : 1.0) } @ViewBuilder @@ -106,21 +116,27 @@ public struct BPKSearchInputSummary: View { @ViewBuilder private var prefixView: some View { - switch inputPrefix { - case .text(let prefixText): - BPKText(prefixText, style: .bodyDefault) - .foregroundColor(.textSecondaryColor) - case .icon(let icon): - BPKIconView(icon) - .foregroundColor(.textPrimaryColor) + if let inputPrefix { + switch inputPrefix { + case .text(let prefixText): + BPKText(prefixText, style: .bodyDefault) + .foregroundColor(.textSecondaryColor) + case .icon(let icon): + BPKIconView(icon) + .foregroundColor(.textPrimaryColor) + } } } - public func inputState(_ state: State) -> BPKSearchInputSummary { + public func customStyle(_ style: Style) -> BPKSearchInputSummary { var result = self - result.state = state + result.style = style return result } + + private var isBorderHighlighted: Bool { + focused || style == .focused + } } fileprivate extension TextField { @@ -131,19 +147,17 @@ fileprivate extension TextField { struct BPKSearchInputSummary_Previews: PreviewProvider { static var previews: some View { + // swiftlint:disable line_length VStack { - BPKSearchInputSummary(.constant("")) - BPKSearchInputSummary(placeholder: "Enter", .constant("")) - BPKSearchInputSummary(.constant("Value")) - BPKSearchInputSummary(inputPrefix: .text("From"), .constant("Value")) - BPKSearchInputSummary(.constant("Disabled")) - .inputState(.disabled) - BPKSearchInputSummary(.constant("Value")) - .inputState(.error) - BPKSearchInputSummary(.constant("Value")) - .inputState(.clear(accessibilityLabel: "clear", action: {})) - BPKSearchInputSummary(.constant("Value")) - .inputState(.valid) + BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: {}), .constant("")) + BPKSearchInputSummary(placeholder: "Enter", clearAction: .init(accessibilityLabel: "Clear", action: {}), .constant("")) + BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: {}), .constant("Value")) + BPKSearchInputSummary(inputPrefix: .text("From"), clearAction: .init(accessibilityLabel: "Clear", action: {}), .constant("Value")) + BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: {}), readOnly: true, .constant("Read Only")) + BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: {}), .constant("Manually highlighted")) + .customStyle(.focused) + BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: {}), .constant("Value")) + BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "clear", action: {}), .constant("Value")) } .padding() .background(.coreEcoColor) diff --git a/Backpack-SwiftUI/SearchInputSummary/Classes/BPKSearchInputSummaryState.swift b/Backpack-SwiftUI/SearchInputSummary/Classes/BPKSearchInputSummaryState.swift deleted file mode 100644 index 47ec289dc..000000000 --- a/Backpack-SwiftUI/SearchInputSummary/Classes/BPKSearchInputSummaryState.swift +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Backpack - Skyscanner's Design System - * - * Copyright 2018-2022 Skyscanner Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import SwiftUI - -extension BPKSearchInputSummary { - /// The state of the text field. - public enum State { - /// The default state. - case `default` - /// Disables the text field. - case disabled - /// Adds a clear button to the text field. The action is called when the button is tapped. - case clear(accessibilityLabel: String, action: () -> Void) - /// Adds a valid icon to the text field. - case valid - /// Adds an error icon to the text field and changes the border color to error. - case error - - var borderColor: BPKColor { - switch self { - case .disabled: return .surfaceHighlightColor - case .error: return .statusDangerSpotColor - default: return .lineColor - } - } - - var isDisabled: Bool { - switch self { - case .disabled: return true - default: return false - } - } - - var textColor: BPKColor { - switch self { - case .disabled: return .textDisabledColor - default: return .textPrimaryColor - } - } - - var icon: BPKSearchInputSummary.Icon? { - switch self { - case .clear: return BPKSearchInputSummary.Icon(icon: .closeCircle, color: .textSecondaryColor) - case .valid: return BPKSearchInputSummary.Icon(icon: .tickCircle, color: .statusSuccessSpotColor) - case .error: return BPKSearchInputSummary.Icon(icon: .exclamationCircle, color: .statusDangerSpotColor) - default: return nil - } - } - } -} diff --git a/Backpack-SwiftUI/AppSearchModal/Classes/BPKAppSearchModalState.swift b/Backpack-SwiftUI/SearchInputSummary/Classes/BPKSearchInputSummaryStyle.swift similarity index 50% rename from Backpack-SwiftUI/AppSearchModal/Classes/BPKAppSearchModalState.swift rename to Backpack-SwiftUI/SearchInputSummary/Classes/BPKSearchInputSummaryStyle.swift index eb493b663..473dc41c2 100644 --- a/Backpack-SwiftUI/AppSearchModal/Classes/BPKAppSearchModalState.swift +++ b/Backpack-SwiftUI/SearchInputSummary/Classes/BPKSearchInputSummaryStyle.swift @@ -1,7 +1,7 @@ /* * Backpack - Skyscanner's Design System * - * Copyright 2018-2023 Skyscanner Ltd + * Copyright 2018-2022 Skyscanner Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,21 +18,12 @@ import SwiftUI -extension BPKAppSearchModal { - /// The state of the text field. - public enum TextFieldState { +extension BPKSearchInputSummary { + /// The style of the text field. + public enum Style { /// The default state. case `default` - /// Adds a clear button to the text field. The action is called when the button is tapped. - case clear(accessibilityLabel: String, action: () -> Void) - - var inputState: BPKSearchInputSummary.State { - switch self { - case .default: - return BPKSearchInputSummary.State.default - case .clear(let accessibilityLabel, let action): - return BPKSearchInputSummary.State.clear(accessibilityLabel: accessibilityLabel, action: action) - } - } + /// Highlight borders as it's in a focus state + case focused } } diff --git a/Backpack-SwiftUI/SearchInputSummary/README.md b/Backpack-SwiftUI/SearchInputSummary/README.md index 110b60b61..9389e3f45 100644 --- a/Backpack-SwiftUI/SearchInputSummary/README.md +++ b/Backpack-SwiftUI/SearchInputSummary/README.md @@ -8,65 +8,56 @@ | --- | --- | | | | -# Usage +# Basic Usage -Create a `BPKSearchInputSummary` and bind the `text` property to a `Binding`. +Create a `BPKSearchInputSummary` and bind the `text` property to a `Binding`. Another mandatory property is `clearAction` which is a struct with an accessibility label for the action, where you can explain what happens when a user clicks on the button, also you need provide an action as a closure. ```swift @State var text: String = "" -BPKSearchInputSummary(text: $text) +BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: { $text = "" }), text: $text) ``` ### Setting a placeholder ```swift -BPKSearchInputSummary("Placeholder", text: $text) +BPKSearchInputSummary(placeholder: "Enter", clearAction: .init(accessibilityLabel: "Clear", action: {}), .constant("")) ``` ### Setting an inputPrefix Default value is `icon`. ```swift -BPKSearchInputSummary(inputPrefix: .icon, text: $text) +BPKSearchInputSummary(inputPrefix: .icon, clearAction: .init(accessibilityLabel: "Clear", action: {}), text: $text) ``` ```swift -BPKSearchInputSummary(inputPrefix: .customText("From"), text: $text) +BPKSearchInputSummary(inputPrefix: .customText("From"), clearAction: .init(accessibilityLabel: "Clear", action: {}), text: $text) ``` -### Changing the State +### Making the field in focused style +In case you need to make a field in focus visually (make borders look selected) you can set a `focused` style. This style is not affecting the keboard appearance or editing state in a field, it's only about the field appearance. ```swift -BPKSearchInputSummary(text: $text) - .inputState(.error) - .inputState(.valid) +BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: {}), text: $text) + .customStyle(.focused) // or .customStyle(.default) ``` -### Adding a clear button +### Read only mode +In case you need a field would be uneditable you can pass `readonly` property into an inialiser. It prevents any actions on the text field, but the clear button would be still clickable. ```swift -@State var text: String = "some text" - -BPKSearchInputSummary(text: $text) - .inputState( - .clear( - accessibilityLabel: "Clear", - action: { text = "" } - ) - ) +BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: { $text = "" }), readonly: true, text: $text) ``` -### Passing input focused value -Default value is `icon`. +### UI Testing +To use the component in UI or smoke tests it's possible to access this element using the accessibility identifier: `search_field` -```swift -BPKSearchInputSummary(inputPrefix: .icon, text: $text) -``` +### Accessibility -```swift -BPKSearchInputSummary(inputPrefix: .customText("From"), text: $text) -``` +By default, BPKSearchInputSummary provides an accessibility value and traits. However, it's a good practice to set an accessibility label as well. -### UI Testing -To use the component in UI or smoke tests it's possible to access this element using the accessibility identifier: `search_field` \ No newline at end of file +```swift +BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: { $text = "" }), text: $text) + .accessibilityLabel("Custom input field") +``` \ No newline at end of file diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/BPKAppSearchModalTests.swift b/Backpack-SwiftUI/Tests/AppSearchModal/BPKAppSearchModalTests.swift index b43691616..0ac8383b5 100644 --- a/Backpack-SwiftUI/Tests/AppSearchModal/BPKAppSearchModalTests.swift +++ b/Backpack-SwiftUI/Tests/AppSearchModal/BPKAppSearchModalTests.swift @@ -55,10 +55,7 @@ class BPKAppSearchModalTests: XCTestCase { assertSnapshot( givenSut( with: .content(givenContentState()), - inputState: .clear( - accessibilityLabel: "clear", - action: { } - ) + clearAction: .init(accessibilityLabel: "clear", action: {}) ) ) } @@ -66,7 +63,7 @@ class BPKAppSearchModalTests: XCTestCase { // MARK: - Helpers private func givenSut( with results: BPKAppSearchModalResults, - inputState: BPKAppSearchModal.TextFieldState = .default, + clearAction: BPKSearchInputSummary.ClearAction = .init(accessibilityLabel: "Clear", action: {}), inputPrefix: BPKSearchInputSummary.InputPrefix = .icon(.search) ) -> some View { BPKAppSearchModal( @@ -76,9 +73,9 @@ class BPKAppSearchModalTests: XCTestCase { results: results, closeAccessibilityLabel: "Close", inputPrefix: inputPrefix, + clearAction: clearAction, onClose: { } ) - .inputState(inputState) .frame(width: 375, height: 667) } diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.dark-mode.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.dark-mode.png index 54385702f..8e18bc52d 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.dark-mode.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.light-mode.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.light-mode.png index b16bad5de..5eea80a86 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.light-mode.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.rtl.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.rtl.png index 61654afb4..386657bde 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.rtl.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContent.rtl.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.dark-mode.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.dark-mode.png index 54385702f..8e18bc52d 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.dark-mode.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.light-mode.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.light-mode.png index b16bad5de..5eea80a86 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.light-mode.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.rtl.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.rtl.png index 61654afb4..386657bde 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.rtl.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentInputStateClear.rtl.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.dark-mode.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.dark-mode.png index 06402915c..02ba9300b 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.dark-mode.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.light-mode.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.light-mode.png index 228fde1db..115229547 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.light-mode.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.rtl.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.rtl.png index c7e29e9b4..3a64afd14 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.rtl.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsCustomText.rtl.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.dark-mode.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.dark-mode.png index 54385702f..8e18bc52d 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.dark-mode.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.light-mode.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.light-mode.png index b16bad5de..5eea80a86 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.light-mode.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.rtl.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.rtl.png index 61654afb4..386657bde 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.rtl.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withContentWhenPrefixIsIcon.rtl.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.dark-mode.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.dark-mode.png index 6c91d8789..901879e13 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.dark-mode.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.light-mode.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.light-mode.png index 4e5889270..2bd49d6c6 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.light-mode.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.rtl.png b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.rtl.png index 04f719104..78c4334a7 100644 Binary files a/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.rtl.png and b/Backpack-SwiftUI/Tests/AppSearchModal/__Snapshots__/BPKAppSearchModalTests/test_withLoading.rtl.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/BPKSearchInputSummaryTests.swift b/Backpack-SwiftUI/Tests/SearchInputSummary/BPKSearchInputSummaryTests.swift index 8f5dd2dec..21cc5b4d7 100644 --- a/Backpack-SwiftUI/Tests/SearchInputSummary/BPKSearchInputSummaryTests.swift +++ b/Backpack-SwiftUI/Tests/SearchInputSummary/BPKSearchInputSummaryTests.swift @@ -23,87 +23,78 @@ import SwiftUI class BPKSearchInputSummaryTests: XCTestCase { func test_defaultSettings_withPrefixIcon() { assertSnapshot( - BPKSearchInputSummary(inputPrefix: .icon(.search), .constant("Value")) - .frame(width: 300)) - } - - func test_emptyField_withPrefixIcon() { - assertSnapshot( - BPKSearchInputSummary(inputPrefix: .icon(.search), .constant("")) - .frame(width: 300)) - } - - func test_disabledField_withPrefixIcon() { - assertSnapshot( - BPKSearchInputSummary(inputPrefix: .icon(.search), .constant("Value")) - .inputState(.disabled) - .frame(width: 300)) - } - - func test_clearableField_withPrefixIcon() { - assertSnapshot( - BPKSearchInputSummary(inputPrefix: .icon(.search), .constant("Value")) - .inputState(.clear(accessibilityLabel: "Clear") { }) - .frame(width: 300)) + BPKSearchInputSummary( + inputPrefix: .icon(.search), + clearAction: .init(accessibilityLabel: "Clear", action: {}), + .constant("Value") + ) + .frame(width: 300) + ) } - - func test_validField_withPrefixIcon() { + + func test_defaultSettings_withHighlightedState() { assertSnapshot( - BPKSearchInputSummary(inputPrefix: .icon(.search), .constant("Value")) - .inputState(.valid) - .frame(width: 300)) + BPKSearchInputSummary( + inputPrefix: .icon(.search), + clearAction: .init(accessibilityLabel: "Clear", action: {}), + .constant("Value") + ) + .customStyle(.focused) + .frame(width: 300) + ) } - func test_errorField_withPrefixIcon() { + func test_emptyField_withPrefixIcon() { assertSnapshot( - BPKSearchInputSummary(inputPrefix: .icon(.search), .constant("Value")) - .inputState(.error) - .frame(width: 300)) + BPKSearchInputSummary( + inputPrefix: .icon(.search), + clearAction: .init(accessibilityLabel: "Clear", action: {}), + .constant("") + ) + .frame(width: 300) + ) } func test_defaultSettings_withCustomPrefixText() { assertSnapshot( - BPKSearchInputSummary(inputPrefix: .text("Prefix"), .constant("Value")) - .frame(width: 300)) + BPKSearchInputSummary( + inputPrefix: .text("Prefix"), + clearAction: .init(accessibilityLabel: "Clear", action: {}), + .constant("Value") + ) + .frame(width: 300) + ) } func test_emptyField_withCustomPrefixText() { assertSnapshot( - BPKSearchInputSummary(inputPrefix: .text("Prefix"), .constant("")) - .frame(width: 300)) - } - - func test_disabledField_withCustomPrefixText() { - assertSnapshot( - BPKSearchInputSummary(inputPrefix: .text("Prefix"), .constant("Value")) - .inputState(.disabled) - .frame(width: 300)) + BPKSearchInputSummary( + inputPrefix: .text("Prefix"), + clearAction: .init(accessibilityLabel: "Clear", action: {}), + .constant("") + ) + .frame(width: 300) + ) } func test_clearableField_withCustomPrefixText() { assertSnapshot( - BPKSearchInputSummary(inputPrefix: .text("Prefix"), .constant("Value")) - .inputState(.clear(accessibilityLabel: "Clear") { }) - .frame(width: 300)) - } - - func test_validField_withCustomPrefixText() { - assertSnapshot( - BPKSearchInputSummary(inputPrefix: .text("Prefix"), .constant("Value")) - .inputState(.valid) - .frame(width: 300)) - } - - func test_errorField_withCustomPrefixText() { - assertSnapshot( - BPKSearchInputSummary(inputPrefix: .text("Prefix"), .constant("Value")) - .inputState(.error) - .frame(width: 300)) + BPKSearchInputSummary( + inputPrefix: .text("Prefix"), + clearAction: .init(accessibilityLabel: "Clear", action: {}), + .constant("Value") + ) + .frame(width: 300) + ) } func test_accessibility() { - let searchInput = BPKSearchInputSummary(inputPrefix: .icon(.search), .constant("Value")) - .frame(width: 300) + let searchInput = BPKSearchInputSummary( + inputPrefix: .icon(.search), + clearAction: .init(accessibilityLabel: "Clear", action: {}), + .constant("Value") + ) + .frame(width: 300) assertA11ySnapshot(searchInput) } } diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_accessibility.a11y.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_accessibility.a11y.png index 7ddd2add5..e9f06db5d 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_accessibility.a11y.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_accessibility.a11y.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.dark-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.dark-mode.png index de29b7f7b..273f354e0 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.dark-mode.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.light-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.light-mode.png index 2f2f46a82..a98d5cb2f 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.light-mode.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.rtl.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.rtl.png index 4631abe36..d6fad5098 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.rtl.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_clearableField_withCustomPrefixText.rtl.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.dark-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.dark-mode.png index 59966f128..273f354e0 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.dark-mode.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.light-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.light-mode.png index 5af6cdcd6..a98d5cb2f 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.light-mode.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.rtl.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.rtl.png index 476b379fb..d6fad5098 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.rtl.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withCustomPrefixText.rtl.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withHighlightedState.dark-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withHighlightedState.dark-mode.png new file mode 100644 index 000000000..08ef1a641 Binary files /dev/null and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withHighlightedState.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withHighlightedState.light-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withHighlightedState.light-mode.png new file mode 100644 index 000000000..38c8a9371 Binary files /dev/null and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withHighlightedState.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withHighlightedState.rtl.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withHighlightedState.rtl.png new file mode 100644 index 000000000..7fc9f5ac7 Binary files /dev/null and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withHighlightedState.rtl.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.dark-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.dark-mode.png index 48152b992..6aa35e8c4 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.dark-mode.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.light-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.light-mode.png index 5f57f7ad7..c6fd005e5 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.light-mode.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.rtl.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.rtl.png index 9c795d723..82de2edab 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.rtl.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_defaultSettings_withPrefixIcon.rtl.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.dark-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.dark-mode.png index 2c16a4091..77d6be146 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.dark-mode.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.light-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.light-mode.png index f960da0e0..488a277ac 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.light-mode.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.rtl.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.rtl.png index c49f69aca..1df9f4fdc 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.rtl.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withCustomPrefixText.rtl.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.dark-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.dark-mode.png index d4ea63e02..040b923c6 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.dark-mode.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.dark-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.light-mode.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.light-mode.png index 58055c5e9..6ba71d2bb 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.light-mode.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.light-mode.png differ diff --git a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.rtl.png b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.rtl.png index d0677280f..ebffd28eb 100644 Binary files a/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.rtl.png and b/Backpack-SwiftUI/Tests/SearchInputSummary/__Snapshots__/BPKSearchInputSummaryTests/test_emptyField_withPrefixIcon.rtl.png differ diff --git a/Example/Backpack/SwiftUI/Components/AppSearchModal/AppSearchModalExampleView.swift b/Example/Backpack/SwiftUI/Components/AppSearchModal/AppSearchModalExampleView.swift index 6a5d4ed4e..f309119db 100644 --- a/Example/Backpack/SwiftUI/Components/AppSearchModal/AppSearchModalExampleView.swift +++ b/Example/Backpack/SwiftUI/Components/AppSearchModal/AppSearchModalExampleView.swift @@ -38,14 +38,13 @@ struct AppSearchModalExampleView: View { results: results(), closeAccessibilityLabel: "Close", inputPrefix: .text("From"), + clearAction: .init(accessibilityLabel: "clear text", action: { inputText = "" }), onClose: { print("Tapped close button") isPresented.toggle() } ) - .inputState(.clear(accessibilityLabel: "clear text", action: { - inputText = "" - })) + .onChange(of: inputText, perform: { _ in self.viewModel.loadContentFrom(inputText) }) diff --git a/Example/Backpack/SwiftUI/Components/SearchInputSummary/SearchInputSummaryExampleView.swift b/Example/Backpack/SwiftUI/Components/SearchInputSummary/SearchInputSummaryExampleView.swift index f69a6ce53..b1bb93381 100644 --- a/Example/Backpack/SwiftUI/Components/SearchInputSummary/SearchInputSummaryExampleView.swift +++ b/Example/Backpack/SwiftUI/Components/SearchInputSummary/SearchInputSummaryExampleView.swift @@ -21,40 +21,42 @@ import SwiftUI import Backpack_SwiftUI struct SearchInputSummaryExampleView: View { - @State var text1 = "" - @State var text2 = "Value" - @State var validationFieldText = "" + @State var text = "Text" + @State var enableHighlihting = false + @State var readOnly = false + // swiftlint:disable closure_body_length line_length var body: some View { ScrollView { - VStack { - BPKSearchInputSummary($text2) - BPKSearchInputSummary(placeholder: "Placeholder", $text2) - BPKSearchInputSummary($text1) - BPKSearchInputSummary(inputPrefix: .text("To"), $text1) - BPKSearchInputSummary(inputPrefix: .text("From"), $text2) - BPKSearchInputSummary($text1) - .inputState(.disabled) - BPKSearchInputSummary($text1) - .inputState(text1.isEmpty ? .default : .clear(accessibilityLabel: "Clear Field") { text1 = "" }) - BPKSearchInputSummary($text1) - .inputState(.valid) - BPKSearchInputSummary($text1) - .inputState(.error) - BPKSearchInputSummary(placeholder: "At least 6 characters", $validationFieldText) - .inputState(validateState()) + VStack(alignment: .leading) { + Text("Text input with text prefix") + .font(.caption) + BPKSearchInputSummary(inputPrefix: .text("To"), clearAction: .init(accessibilityLabel: "Clear", action: { text = "" }), $text) + .padding(.bottom) + Text("Text input with icon prefix") + .font(.caption) + BPKSearchInputSummary(inputPrefix: .icon(.search), clearAction: .init(accessibilityLabel: "Clear", action: { text = "" }), $text) + .padding(.bottom) + Text("Clear action") + .font(.caption) + BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: { text = "" }), $text) + .padding(.bottom) + Text("Placeholder with empty text") + .font(.caption) + BPKSearchInputSummary(placeholder: "Read Only with Placeholder", clearAction: .init(accessibilityLabel: "Clear", action: {}), readOnly: true, .constant("")) + .padding(.bottom) + Text("Highlighting and read only states") + .font(.caption) + BPKSearchInputSummary(clearAction: .init(accessibilityLabel: "Clear", action: { text = "" }), readOnly: readOnly, $text) + .customStyle($enableHighlihting.wrappedValue ? .focused : .default) + HStack { + Toggle("Enable highlighting", isOn: $enableHighlihting) + Toggle("Read only", isOn: $readOnly) + } } .padding() } } - - private func validateState() -> Backpack_SwiftUI.BPKSearchInputSummary.State { - switch validationFieldText.count { - case 0: return .default - case 1...5: return .error - default: return .valid - } - } } struct SearchInputSummaryExampleView_Previews: PreviewProvider {