Created
October 4, 2022 12:09
-
-
Save SarahAlsharif/72dd57facc001b2a3b714b8cc8629bb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct PurchasingSteps: View { | |
@State var orderStatus : [OrderState] = [.shoppingCart] | |
@State var currentStatus : OrderState = .shoppingCart | |
var body: some View { | |
ZStack { | |
VStack { | |
// MULTI-STEPS View | |
MultiStepsView(steps: $orderStatus, extraContent: OrderState.allValues, extraContentPosition : .above, extraContentSize: CGSize(width: 30, height: 30), action: {_ in }) { | |
RoundedRectangle(cornerRadius: 5).frame(height: 10) | |
} | |
.padding() | |
.font(.title2) | |
Spacer() | |
// STEP VIEW - CONDITIONAL | |
switch currentStatus { | |
case .shoppingCart: | |
Text("SHOPPING CART ITEMS") | |
case .payment: | |
Text("PAYMENT FORM") | |
case .shippingLocation: | |
Text("LOCATION FORM") | |
case .complete: | |
Text("COMPLETE") | |
} | |
Spacer() | |
// BOTTOM BUTTONS | |
HStack { | |
Button("Back") { | |
guard orderStatus.count > 1 else { return } | |
orderStatus.removeAll(where: {$0 == currentStatus}) | |
currentStatus = currentStatus.previous() | |
} | |
.frame(maxWidth: .infinity) | |
.background(RoundedRectangle(cornerRadius: 10).fill(.blue)) | |
Button("Next") { | |
if !orderStatus.contains(currentStatus.next()) { | |
currentStatus = currentStatus.next() | |
orderStatus.append(currentStatus) | |
} | |
} | |
.frame(maxWidth: .infinity) | |
.background(RoundedRectangle(cornerRadius: 10).fill(.blue)) | |
}.buttonStyle(.borderedProminent) | |
.padding(.horizontal) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment