-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathWarningBanner.swift
More file actions
72 lines (65 loc) · 2.06 KB
/
Copy pathWarningBanner.swift
File metadata and controls
72 lines (65 loc) · 2.06 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
import AppKit
import GitHubCopilotService
import SharedUIComponents
import SwiftUI
struct WarningBanner: View {
let message: String
let severity: String // "warning" or "info"
let actions: [WarningAction]
let onDismiss: () -> Void
@State private var hoveredActionIndex: Int? = nil
private var bannerStyle: BannerStyle {
severity == "warning" ? .warning : .info
}
var body: some View {
NotificationBanner(style: bannerStyle, isDismissable: true, onDismiss: onDismiss) {
VStack(alignment: .leading, spacing: 8) {
Text(message)
.foregroundColor(.primary)
.frame(maxWidth: .infinity, alignment: .leading)
if !actions.isEmpty {
HStack(spacing: 12) {
ForEach(Array(actions.enumerated()), id: \.offset) { index, action in
ActionLink(
title: action.title,
url: action.url,
isHovered: hoveredActionIndex == index
) { isHovered in
hoveredActionIndex = isHovered ? index : nil
}
}
}
}
}
}
}
}
private struct ActionLink: View {
let title: String
let url: URL
let isHovered: Bool
let onHoverChange: (Bool) -> Void
var body: some View {
Button(action: {
NSWorkspace.shared.open(url)
}) {
Text(title)
.underline(isHovered)
.foregroundColor(.accentColor)
}
.buttonStyle(.plain)
.onHover { isHovered in
onHoverChange(isHovered)
DispatchQueue.main.async {
if isHovered {
NSCursor.pointingHand.push()
} else {
NSCursor.pop()
}
}
}
.onDisappear {
NSCursor.pop()
}
}
}