yattee/Shared/Playlists/CoverSectionView.swift

53 lines
1.1 KiB
Swift
Raw Normal View History

2021-07-07 22:39:18 +00:00
import SwiftUI
2021-07-08 15:14:54 +00:00
struct CoverSectionView<Content: View>: View {
2021-07-07 22:39:18 +00:00
let title: String?
2021-07-08 17:18:36 +00:00
let actionsView: Content
2021-07-07 22:39:18 +00:00
let divider: Bool
2021-07-08 17:18:36 +00:00
let inline: Bool
2021-07-07 22:39:18 +00:00
2021-07-08 17:18:36 +00:00
init(_ title: String? = nil, divider: Bool = true, inline: Bool = false, @ViewBuilder actionsView: @escaping () -> Content) {
2021-07-07 22:39:18 +00:00
self.title = title
self.divider = divider
2021-07-08 17:18:36 +00:00
self.inline = inline
self.actionsView = actionsView()
2021-07-07 22:39:18 +00:00
}
var body: some View {
VStack(alignment: .leading) {
2021-07-08 17:18:36 +00:00
if inline {
HStack {
if title != nil {
sectionTitle
}
Spacer()
actionsView
}
} else if title != nil {
2021-07-07 22:39:18 +00:00
sectionTitle
}
2021-07-08 17:18:36 +00:00
if !inline {
actionsView
}
2021-07-07 22:39:18 +00:00
}
if divider {
Divider()
.padding(.vertical)
}
}
var sectionTitle: some View {
Text(title ?? "")
.font(.title2)
#if os(macOS)
.bold()
#endif
.padding(.bottom)
2021-07-07 22:39:18 +00:00
}
}