forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsLink.swift
More file actions
85 lines (78 loc) · 2.2 KB
/
SettingsLink.swift
File metadata and controls
85 lines (78 loc) · 2.2 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
import SwiftUI
struct SettingsLink: View {
let action: ()->Void
let title: String
let subtitle: AnyView?
let badge: BadgeItem?
init<Subtitle: View>(
action: @escaping ()->Void,
title: String,
subtitle: Subtitle?,
badge: BadgeItem? = nil
) {
self.action = action
self.title = title
self.subtitle = subtitle.map { AnyView($0) }
self.badge = badge
}
init(
_ url: URL,
title: String,
subtitle: String? = nil,
badge: BadgeItem? = nil
) {
self.init(
action: { NSWorkspace.shared.open(url) },
title: title,
subtitle: subtitle.map { Text($0) },
badge: badge
)
}
init(url: String, title: String, subtitle: String? = nil, badge: BadgeItem? = nil) {
self.init(
URL(string: url)!,
title: title,
subtitle: subtitle,
badge: badge
)
}
init<Subtitle: View>(url: String, title: String, subtitle: Subtitle?, badge: BadgeItem? = nil) {
self.init(
action: { NSWorkspace.shared.open(URL(string: url)!) },
title: title,
subtitle: subtitle,
badge: badge
)
}
var body: some View {
Button(action: action) {
HStack{
VStack(alignment: .leading) {
HStack{
Text(title).font(.body)
if let badge = self.badge {
Badge(badgeItem: badge)
}
}
if let subtitle = subtitle {
subtitle.font(.footnote)
}
}
Spacer()
Image(systemName: "chevron.right")
}
.contentShape(Rectangle()) // This makes the entire HStack clickable
}
.buttonStyle(.plain)
.foregroundStyle(.primary)
.padding(10)
}
}
#Preview {
SettingsLink(
url: "https://example.com",
title: "Example",
subtitle: "This is an example",
badge: .init(text: "Not Granted", level: .danger)
)
}