forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsSection.swift
More file actions
70 lines (64 loc) · 2.37 KB
/
SettingsSection.swift
File metadata and controls
70 lines (64 loc) · 2.37 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
import SwiftUI
struct SettingsSection<Content: View, Footer: View>: View {
let title: String
let showWarning: Bool
@ViewBuilder let content: () -> Content
@ViewBuilder let footer: () -> Footer
init(title: String, showWarning: Bool = false, @ViewBuilder content: @escaping () -> Content, @ViewBuilder footer: @escaping () -> Footer) {
self.title = title
self.showWarning = showWarning
self.content = content
self.footer = footer
}
var body: some View {
VStack(alignment: .leading, spacing: 10) {
Text(title)
.bold()
.padding(.horizontal, 10)
if showWarning {
HStack{
Text("GitHub Copilot features are disabled. Please [check your subscription](https://github.com/settings/copilot) to access them.")
.foregroundColor(Color("WarningForegroundColor"))
.padding(4)
Spacer()
}
.background(Color("WarningBackgroundColor"))
.overlay(
RoundedRectangle(cornerRadius: 3)
.stroke(Color("WarningStrokeColor"), lineWidth: 1)
)
}
VStack(alignment: .leading, spacing: 0) {
content()
}
.background(Color.gray.opacity(0.1))
.cornerRadius(8)
footer()
}
.frame(maxWidth: .infinity, alignment: .leading)
}
}
extension SettingsSection where Footer == EmptyView {
init(title: String, showWarning: Bool = false, @ViewBuilder content: @escaping () -> Content) {
self.init(title: title, showWarning: showWarning, content: content, footer: { EmptyView() })
}
}
#Preview {
VStack(spacing: 20) {
SettingsSection(title: "General") {
SettingsLink(
url: "https://github.com", title: "GitHub", subtitle: "footnote")
Divider()
SettingsToggle(title: "Example", isOn: .constant(true))
Divider()
SettingsLink(url: "https://example.com", title: "Example")
}
SettingsSection(title: "Advanced", showWarning: true) {
SettingsLink(url: "https://example.com", title: "Example")
} footer: {
Text("Footer")
}
}
.padding()
.frame(width: 300)
}