macbackend/Sources/Core/View/DisabledWrapper.swift
david-swift 82fb4982ec
All checks were successful
Deploy Docs / publish (push) Successful in 4m0s
SwiftLint / SwiftLint (push) Successful in 3s
Add support for disabling controls
2025-01-18 12:09:19 +01:00

41 lines
985 B
Swift

//
// DisabledWrapper.swift
// MacBackend
//
// Created by david-swift on 18.01.2025.
//
import SwiftUI
/// Wrap a view to disable it.
public struct DisabledWrapper: SwiftUIWidget {
/// Whether the view is disabled.
var disabled: Bool
/// The content.
var content: Body
/// The wrapped views.
public var wrappedViews: [String: Meta.AnyView] {
[.mainContent: content]
}
/// Initialize a disabled wrapper.
/// - Parameters:
/// - disabled: Whether the view is disabled.
/// - content: The view content.
public init(disabled: Bool, @Meta.ViewBuilder content: () -> Body) {
self.content = content()
self.disabled = disabled
}
/// Get the SwiftUI view.
/// - Parameter properties: The widget data.
/// - Returns: The SwiftUI view.
public static func view(properties: Self) -> some SwiftUI.View {
MacBackendView(.mainContent)
.disabled(properties.disabled)
}
}