diff --git a/Sources/Core/View/Alert.swift b/Sources/Core/View/Alert.swift index 48a648b..250ede5 100644 --- a/Sources/Core/View/Alert.swift +++ b/Sources/Core/View/Alert.swift @@ -20,6 +20,8 @@ public struct Alert: SwiftUIWidget { var actions: [Action] = [] /// The wrapped view. var child: Meta.AnyView + /// An additional view in the alert, for example a text field. + var textField: (String, Meta.Binding)? /// The wrapped views. public var wrappedViews: [String: Meta.AnyView] { @@ -101,6 +103,9 @@ public struct Alert: SwiftUIWidget { public static func view(properties: Self) -> some SwiftUI.View { MacBackendView(.mainContent) .alert(properties.title, isPresented: properties.isPresented.swiftUI) { + if let field = properties.textField { + SwiftUI.TextField(field.0, text: field.1.swiftUI) + } SwiftUI.ForEach(Array(properties.actions.enumerated()), id: \.offset) { action in action.element.button } @@ -125,6 +130,13 @@ public struct Alert: SwiftUIWidget { } } + public func textField( + _ label: String, + text: Meta.Binding + ) -> Self { + modify { $0.textField = (label, text) } + } + /// Add a cancel button to the alert. /// - Parameters: /// - label: The button's label. diff --git a/Sources/Core/View/TextField.swift b/Sources/Core/View/TextField.swift new file mode 100644 index 0000000..0ae7872 --- /dev/null +++ b/Sources/Core/View/TextField.swift @@ -0,0 +1,34 @@ +// +// TextField.swift +// MacBackend +// +// Created by david-swift on 31.01.2025. +// + +import SwiftUI + +/// A text field. +public struct TextField: SwiftUIWidget { + + /// The text. + @Meta.Binding var text: String + /// The field's label. + var label: String + + /// Initialize the text field. + /// - Parameters: + /// - label: The picker's label. + /// - text: The current text. + public init(_ label: String, text: Meta.Binding) { + self.label = label + self._text = text + } + + /// Get the SwiftUI view. + /// - Parameter properties: The widget data. + /// - Returns: The SwiftUI view. + public static func view(properties: Self) -> some SwiftUI.View { + SwiftUI.TextField(properties.label, text: properties._text.swiftUI) + } + +}