91 lines
2.8 KiB
Swift
91 lines
2.8 KiB
Swift
import SwiftUI
|
|
|
|
struct SodaV2ActionModalButton {
|
|
let label: String?
|
|
let action: (() -> Void)?
|
|
}
|
|
|
|
struct SodaV2ActionModal: View {
|
|
let title: String
|
|
let message: String
|
|
let button1: SodaV2ActionModalButton?
|
|
let button2: SodaV2ActionModalButton?
|
|
let onDimmedTap: () -> Void
|
|
|
|
private var visibleButtons: [(label: String, action: () -> Void, isPrimary: Bool)] {
|
|
var buttons = [(label: String, action: () -> Void, isPrimary: Bool)]()
|
|
|
|
if let button2,
|
|
let label = button2.label,
|
|
let action = button2.action {
|
|
buttons.append((label, action, false))
|
|
}
|
|
|
|
if let button1,
|
|
let label = button1.label,
|
|
let action = button1.action {
|
|
buttons.append((label, action, true))
|
|
}
|
|
|
|
return buttons
|
|
}
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
Color.black.opacity(0.6)
|
|
.ignoresSafeArea()
|
|
.onTapGesture(perform: onDimmedTap)
|
|
|
|
VStack(spacing: 0) {
|
|
Text(title)
|
|
.appFont(size: 20, weight: .bold)
|
|
.foregroundColor(Color.white)
|
|
.multilineTextAlignment(.center)
|
|
.frame(width: 340, height: 64)
|
|
|
|
Text(message)
|
|
.appFont(size: 16, weight: .regular)
|
|
.foregroundColor(Color.white)
|
|
.multilineTextAlignment(.center)
|
|
.padding(20)
|
|
.frame(width: 340)
|
|
|
|
buttonArea
|
|
.padding(.horizontal, 20)
|
|
.padding(.vertical, 14)
|
|
.frame(width: 340)
|
|
}
|
|
.background(Color.gray900)
|
|
.cornerRadius(14)
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var buttonArea: some View {
|
|
let buttons = visibleButtons
|
|
|
|
if buttons.count == 1, let button = buttons.first {
|
|
actionButton(title: button.label, isPrimary: true, action: button.action)
|
|
} else if buttons.count == 2 {
|
|
HStack(spacing: 8) {
|
|
ForEach(Array(buttons.enumerated()), id: \.offset) { _, button in
|
|
actionButton(title: button.label, isPrimary: button.isPrimary, action: button.action)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func actionButton(title: String, isPrimary: Bool, action: @escaping () -> Void) -> some View {
|
|
Button(action: action) {
|
|
Text(title)
|
|
.appFont(size: 18, weight: .medium)
|
|
.foregroundColor(isPrimary ? Color.soda400 : Color.white)
|
|
.frame(maxWidth: .infinity)
|
|
.padding(14)
|
|
.background(Color.clear)
|
|
.cornerRadius(100)
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
}
|