-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathSettingsSection.swift
More file actions
48 lines (44 loc) · 1.4 KB
/
SettingsSection.swift
File metadata and controls
48 lines (44 loc) · 1.4 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
import SwiftUI
struct SettingsSection<Content: View, Footer: View>: View {
let title: String
@ViewBuilder let content: () -> Content
@ViewBuilder let footer: () -> Footer
var body: some View {
VStack(alignment: .leading, spacing: 10) {
Text(title)
.bold()
.padding(.horizontal, 10)
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, @ViewBuilder content: @escaping () -> Content) {
self.init(title: title, 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") {
SettingsLink(url: "https://example.com", title: "Example")
} footer: {
Text("Footer")
}
}
.padding()
.frame(width: 300)
}