Skip to content

Commit 0252eea

Browse files
committed
Create PlusButtonStyle for buttons with a plus icon
1 parent bb33741 commit 0252eea

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Creation/NewOrder.swift

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff 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
220201
private extension NewOrder {
221202
enum Layout {

WooCommerce/Classes/ViewRelated/ReusableViews/SwiftUI Components/ButtonStyles.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff 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
///
2834
struct 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+
194222
private 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
}

0 commit comments

Comments
 (0)