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
57 lines (51 loc) · 1.93 KB
/
ToastPanelView.swift
File metadata and controls
57 lines (51 loc) · 1.93 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
import ComposableArchitecture
import Dependencies
import Foundation
import SwiftUI
import Toast
struct ToastPanelView: View {
let store: StoreOf<ToastPanel>
struct ViewState: Equatable {
let colorScheme: ColorScheme
let alignTopToAnchor: Bool
}
var body: some View {
WithViewStore(store, observe: {
ViewState(
colorScheme: $0.colorScheme,
alignTopToAnchor: $0.alignTopToAnchor
)
}) { viewStore in
VStack(spacing: 4) {
if !viewStore.alignTopToAnchor {
Spacer()
}
WithViewStore(store, observe: \.toast.messages) { viewStore in
ForEach(viewStore.state) { message in
message.content
.foregroundColor(.white)
.padding(8)
.frame(maxWidth: .infinity)
.background({
switch message.type {
case .info: return Color(nsColor: .systemIndigo)
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.3), lineWidth: 1)
}
}
}
if viewStore.alignTopToAnchor {
Spacer()
}
}
.colorScheme(viewStore.colorScheme)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.allowsHitTesting(false)
}
}