@@ -12,34 +12,92 @@ struct ToastPanelView: View {
1212 VStack ( spacing: 4 ) {
1313 if !store. alignTopToAnchor {
1414 Spacer ( )
15+ . allowsHitTesting ( false )
1516 }
1617
1718 ForEach ( store. toast. messages) { message in
18- message. content
19- . foregroundColor ( . white)
20- . padding ( 8 )
21- . frame ( maxWidth: . infinity)
22- . background ( {
23- switch message. type {
24- case . info: return Color . accentColor
25- case . error: return Color ( nsColor: . systemRed)
26- case . warning: return Color ( nsColor: . systemOrange)
19+ HStack {
20+ message. content
21+ . foregroundColor ( . white)
22+ . textSelection ( . enabled)
23+
24+
25+ if !message. buttons. isEmpty {
26+ HStack {
27+ ForEach (
28+ Array ( message. buttons. enumerated ( ) ) ,
29+ id: \. offset
30+ ) { _, button in
31+ Button ( action: button. action) {
32+ button. label
33+ . foregroundColor ( . white)
34+ . padding ( . horizontal, 6 )
35+ . padding ( . vertical, 2 )
36+ . background {
37+ RoundedRectangle ( cornerRadius: 4 )
38+ . stroke ( Color . white, lineWidth: 1 )
39+ }
40+ . contentShape ( Rectangle ( ) )
41+ }
42+ . buttonStyle ( . plain)
43+ . allowsHitTesting ( true )
44+ }
2745 }
28- } ( ) as Color , in: RoundedRectangle ( cornerRadius: 8 ) )
29- . overlay {
30- RoundedRectangle ( cornerRadius: 8 )
31- . stroke ( Color . black. opacity ( 0.1 ) , lineWidth: 1 )
3246 }
47+ }
48+ . padding ( 8 )
49+ . frame ( maxWidth: . infinity)
50+ . background ( {
51+ switch message. type {
52+ case . info: return Color . accentColor
53+ case . error: return Color ( nsColor: . systemRed)
54+ case . warning: return Color ( nsColor: . systemOrange)
55+ }
56+ } ( ) as Color , in: RoundedRectangle ( cornerRadius: 8 ) )
57+ . overlay {
58+ RoundedRectangle ( cornerRadius: 8 )
59+ . stroke ( Color . black. opacity ( 0.1 ) , lineWidth: 1 )
60+ }
3361 }
3462
3563 if store. alignTopToAnchor {
3664 Spacer ( )
65+ . allowsHitTesting ( false )
3766 }
3867 }
3968 . colorScheme ( store. colorScheme)
4069 . frame ( maxWidth: . infinity, maxHeight: . infinity)
41- . allowsHitTesting ( false )
4270 }
4371 }
4472}
4573
74+ #Preview {
75+ ToastPanelView ( store: . init( initialState: . init(
76+ toast: . init( messages: [
77+ ToastController . Message (
78+ id: UUID ( ) ,
79+ type: . info,
80+ content: Text ( " Info message " ) ,
81+ buttons: [
82+ . init( label: Text ( " Dismiss " ) , action: { } ) ,
83+ . init( label: Text ( " More info " ) , action: { } ) ,
84+ ]
85+ ) ,
86+ ToastController . Message (
87+ id: UUID ( ) ,
88+ type: . error,
89+ content: Text ( " Error message " ) ,
90+ buttons: [ . init( label: Text ( " Dismiss " ) , action: { } ) ]
91+ ) ,
92+ ToastController . Message (
93+ id: UUID ( ) ,
94+ type: . warning,
95+ content: Text ( " Warning message " ) ,
96+ buttons: [ . init( label: Text ( " Dismiss " ) , action: { } ) ]
97+ ) ,
98+ ] )
99+ ) , reducer: {
100+ ToastPanel ( )
101+ } ) )
102+ }
103+
0 commit comments