101 lines
3.2 KiB
Swift
101 lines
3.2 KiB
Swift
//
|
|
// SheetWrapper.swift
|
|
// MacBackend
|
|
//
|
|
// Created by david-swift on 31.12.2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
/// A sheet on top of a wrapped view.
|
|
public struct SheetWrapper: SwiftUIWidget {
|
|
|
|
/// Whether the sheet is presented.
|
|
@Meta.Binding var isPresented: Bool
|
|
/// The wrapped view.
|
|
var content: Body
|
|
/// The dialog's content.
|
|
var dialog: Body
|
|
/// The cancellation action.
|
|
var cancellationAction: Body = []
|
|
/// The confirmation action.
|
|
var confirmationAction: Body = []
|
|
/// The toolbar's content.
|
|
var toolbar: Body = []
|
|
|
|
/// The wrapped views.
|
|
public var wrappedViews: [String: Meta.AnyView] {
|
|
[
|
|
.mainContent: content,
|
|
"dialog": dialog,
|
|
"cancellationAction": cancellationAction,
|
|
"confirmationAction": confirmationAction,
|
|
"toolbar": toolbar
|
|
]
|
|
}
|
|
|
|
/// Initialize a sheet wrapper.
|
|
/// - Parameters:
|
|
/// - isPresented: Whether the sheet is presented.
|
|
/// - content: The wrapped view.
|
|
/// - dialog: The dialog's content.
|
|
public init(
|
|
isPresented: Meta.Binding<Bool>,
|
|
@Meta.ViewBuilder content: () -> Body,
|
|
@Meta.ViewBuilder dialog: () -> Body
|
|
) {
|
|
self._isPresented = isPresented
|
|
self.content = content()
|
|
self.dialog = dialog()
|
|
}
|
|
|
|
/// Get the SwiftUI view.
|
|
/// - Parameter properties: The widget data.
|
|
/// - Returns: The SwiftUI view.
|
|
public static func view(properties: Self) -> some SwiftUI.View {
|
|
MacBackendView(.mainContent)
|
|
.sheet(isPresented: properties._isPresented.swiftUI) {
|
|
MacBackendView("dialog")
|
|
.toolbar {
|
|
if !properties.cancellationAction.isEmpty {
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
MacBackendView("cancellationAction")
|
|
}
|
|
}
|
|
if !properties.confirmationAction.isEmpty {
|
|
ToolbarItem(placement: .confirmationAction) {
|
|
MacBackendView("confirmationAction")
|
|
}
|
|
}
|
|
if !properties.toolbar.isEmpty {
|
|
ToolbarItem {
|
|
MacBackendView("toolbar")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Set the cancellation action in the toolbar.
|
|
/// - Parameter action: The action view.
|
|
/// - Returns: The sheet wrapper.
|
|
public func cancellationAction(@Meta.ViewBuilder _ action: () -> Body) -> Self {
|
|
modify { $0.cancellationAction = action() }
|
|
}
|
|
|
|
/// Set the confirmation action in the toolbar.
|
|
/// - Parameter action: The action view.
|
|
/// - Returns: The sheet wrapper.
|
|
public func confirmationAction(@Meta.ViewBuilder _ action: () -> Body) -> Self {
|
|
modify { $0.confirmationAction = action() }
|
|
}
|
|
|
|
/// Set the sheet's toolbar.
|
|
/// - Parameter action: The toolbar view.
|
|
/// - Returns: The sheet wrapper.
|
|
public func sheetToolbar(@Meta.ViewBuilder _ toolbar: () -> Body) -> Self {
|
|
modify { $0.toolbar = toolbar() }
|
|
}
|
|
|
|
}
|