main
swift 59 lines 1.54 KB
Raw
1 import SwiftUI
2
3 struct KleponActionButton: View {
4 enum Tone {
5 case primary
6 case secondary
7 }
8
9 let title: String
10 var systemImage: String? = nil
11 var tone: Tone = .primary
12 var isLoading = false
13 var isDisabled = false
14 let action: () -> Void
15
16 var body: some View {
17 Button(action: action) {
18 HStack(spacing: 10) {
19 if isLoading {
20 ProgressView()
21 .tint(foregroundColor)
22 } else if let systemImage {
23 Image(systemName: systemImage)
24 }
25
26 Text(title)
27 .font(KleponTypography.bodySecondary.weight(.semibold))
28 }
29 .frame(maxWidth: .infinity)
30 .padding(.vertical, 13)
31 .background(
32 RoundedRectangle(cornerRadius: 18, style: .continuous)
33 .fill(backgroundColor)
34 )
35 .foregroundStyle(foregroundColor)
36 }
37 .kleponInteractiveButtonStyle()
38 .disabled(isDisabled || isLoading)
39 .opacity((isDisabled || isLoading) && tone == .primary ? 0.85 : 1)
40 }
41
42 private var backgroundColor: Color {
43 switch tone {
44 case .primary:
45 return KleponColor.accent
46 case .secondary:
47 return KleponColor.surface
48 }
49 }
50
51 private var foregroundColor: Color {
52 switch tone {
53 case .primary:
54 return .white
55 case .secondary:
56 return KleponColor.textPrimary
57 }
58 }
59 }