forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToastPanelView.swift
More file actions
103 lines (95 loc) · 3.71 KB
/
Copy pathToastPanelView.swift
File metadata and controls
103 lines (95 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import ComposableArchitecture
import Dependencies
import Foundation
import SwiftUI
import Toast
struct ToastPanelView: View {
let store: StoreOf<ToastPanel>
var body: some View {
WithPerceptionTracking {
VStack(spacing: 4) {
if !store.alignTopToAnchor {
Spacer()
.allowsHitTesting(false)
}
ForEach(store.toast.messages) { message in
HStack {
message.content
.foregroundColor(.white)
.textSelection(.enabled)
if !message.buttons.isEmpty {
HStack {
ForEach(
Array(message.buttons.enumerated()),
id: \.offset
) { _, button in
Button(action: button.action) {
button.label
.foregroundColor(.white)
.padding(.horizontal, 6)
.padding(.vertical, 2)
.background {
RoundedRectangle(cornerRadius: 4)
.stroke(Color.white, lineWidth: 1)
}
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.allowsHitTesting(true)
}
}
}
}
.padding(8)
.frame(maxWidth: .infinity)
.background({
switch message.type {
case .info: return Color.accentColor
case .error: return Color(nsColor: .systemRed)
case .warning: return Color(nsColor: .systemOrange)
}
}() as Color, in: RoundedRectangle(cornerRadius: 8))
.overlay {
RoundedRectangle(cornerRadius: 8)
.stroke(Color.black.opacity(0.1), lineWidth: 1)
}
}
if store.alignTopToAnchor {
Spacer()
.allowsHitTesting(false)
}
}
.colorScheme(store.colorScheme)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
}
#Preview {
ToastPanelView(store: .init(initialState: .init(
toast: .init(messages: [
ToastController.Message(
id: UUID(),
type: .info,
content: Text("Info message"),
buttons: [
.init(label: Text("Dismiss"), action: {}),
.init(label: Text("More info"), action: {}),
]
),
ToastController.Message(
id: UUID(),
type: .error,
content: Text("Error message"),
buttons: [.init(label: Text("Dismiss"), action: {})]
),
ToastController.Message(
id: UUID(),
type: .warning,
content: Text("Warning message"),
buttons: [.init(label: Text("Dismiss"), action: {})]
),
])
), reducer: {
ToastPanel()
}))
}