Files
QueueCube/QueueCube/Views/ContentPlaceholderView.swift
2025-06-20 18:22:31 -07:00

65 lines
1.6 KiB
Swift

//
// ContentPlaceholderView.swift
// QueueCube
//
// Created by James Magahern on 6/10/25.
//
import SwiftUI
struct ContentPlaceholderView<Label, Actions>: View
where Label: View, Actions: View
{
let label: Label
let actions: Actions
init(@ViewBuilder label: () -> Label, @ViewBuilder actions: () -> Actions = { EmptyView() }) {
self.label = label()
self.actions = actions()
}
var body: some View {
Spacer()
ContentUnavailableView {
label
.imageScale(.large)
.tint(.secondary)
} actions: { actions }
Spacer()
}
}
func contentPlaceholderView<Actions>(
title: LocalizedStringKey,
subtitle: (any StringProtocol)? = nil,
systemImage: String, @ViewBuilder actions: () -> Actions = { EmptyView() })
-> ContentPlaceholderView<AnyView, Actions>
{
ContentPlaceholderView(label: {
AnyView(erasing: VStack(spacing: 16.0) {
Image(systemName: systemImage)
.resizable()
.scaledToFit()
.frame(width: 50.0, height: 50.0)
.foregroundStyle(.secondary)
.imageScale(.large)
Text(title)
.foregroundStyle(.tint)
.bold()
if let subtitle {
Text(subtitle)
.foregroundStyle(.tint.opacity(0.5))
}
Spacer()
.frame(height: 14.0)
})
}, actions: actions)
}