File tree Expand file tree Collapse file tree 2 files changed +33
-21
lines changed
WooCommerce/Classes/ViewRelated
ReusableViews/SwiftUI Components Expand file tree Collapse file tree 2 files changed +33
-21
lines changed Original file line number Diff line number Diff line change @@ -93,9 +93,10 @@ private struct ProductsSection: View {
9393 // TODO: Add a product row for each product added to the order
9494 ProductRow ( )
9595
96- AddButton ( title : NewOrder . Localization. addProduct) {
96+ Button ( NewOrder . Localization. addProduct) {
9797 // TODO: Open Add Product modal view
9898 }
99+ . buttonStyle ( PlusButtonStyle ( ) )
99100 }
100101 . padding ( . horizontal, insets: geometry. safeAreaInsets)
101102 . padding ( )
@@ -196,26 +197,6 @@ private struct ProductsSection: View {
196197 }
197198}
198199
199- // MARK: Custom Views
200- /// Represents a button with a plus icon.
201- /// Used for any button that adds details to the order.
202- ///
203- private struct AddButton : View {
204- let title : String
205- let onButtonTapped : ( ) -> Void
206-
207- var body : some View {
208- Button ( action: { onButtonTapped ( ) } ) {
209- Label {
210- Text ( title)
211- } icon: {
212- Image ( uiImage: . plusImage)
213- }
214- Spacer ( )
215- }
216- }
217- }
218-
219200// MARK: Constants
220201private extension NewOrder {
221202 enum Layout {
Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ struct LinkButtonStyle: ButtonStyle {
2323 }
2424}
2525
26+ struct PlusButtonStyle : ButtonStyle {
27+ func makeBody( configuration: Configuration ) -> some View {
28+ return PlusButton ( configuration: configuration)
29+ }
30+ }
31+
2632/// Adds a primary button style while showing a progress view on top of the button when required.
2733///
2834struct PrimaryLoadingButtonStyle : PrimitiveButtonStyle {
@@ -191,6 +197,28 @@ private struct LinkButton: View {
191197 }
192198}
193199
200+ private struct PlusButton : View {
201+ let configuration : ButtonStyleConfiguration
202+
203+ var body : some View {
204+ HStack {
205+ Label {
206+ configuration. label
207+ } icon: {
208+ Image ( uiImage: . plusImage)
209+ }
210+ Spacer ( )
211+ }
212+ . frame ( maxWidth: . infinity)
213+ . foregroundColor ( Color ( foregroundColor) )
214+ . background ( Color ( . clear) )
215+ }
216+
217+ var foregroundColor : UIColor {
218+ configuration. isPressed ? . accentDark : . accent
219+ }
220+ }
221+
194222private enum Style {
195223 static let defaultCornerRadius = CGFloat ( 8.0 )
196224 static let defaultBorderWidth = CGFloat ( 1.0 )
@@ -216,6 +244,9 @@ struct PrimaryButton_Previews: PreviewProvider {
216244
217245 Button ( " Link button " ) { }
218246 . buttonStyle ( LinkButtonStyle ( ) )
247+
248+ Button ( " Plus button " ) { }
249+ . buttonStyle ( PlusButtonStyle ( ) )
219250 }
220251 . padding ( )
221252 }
You can’t perform that action at this time.
0 commit comments