Add support for text fields
This commit is contained in:
parent
319797a68d
commit
27c30dfd79
@ -20,6 +20,8 @@ public struct Alert: SwiftUIWidget {
|
|||||||
var actions: [Action] = []
|
var actions: [Action] = []
|
||||||
/// The wrapped view.
|
/// The wrapped view.
|
||||||
var child: Meta.AnyView
|
var child: Meta.AnyView
|
||||||
|
/// An additional view in the alert, for example a text field.
|
||||||
|
var textField: (String, Meta.Binding<String>)?
|
||||||
|
|
||||||
/// The wrapped views.
|
/// The wrapped views.
|
||||||
public var wrappedViews: [String: Meta.AnyView] {
|
public var wrappedViews: [String: Meta.AnyView] {
|
||||||
@ -101,6 +103,9 @@ public struct Alert: SwiftUIWidget {
|
|||||||
public static func view(properties: Self) -> some SwiftUI.View {
|
public static func view(properties: Self) -> some SwiftUI.View {
|
||||||
MacBackendView(.mainContent)
|
MacBackendView(.mainContent)
|
||||||
.alert(properties.title, isPresented: properties.isPresented.swiftUI) {
|
.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
|
SwiftUI.ForEach(Array(properties.actions.enumerated()), id: \.offset) { action in
|
||||||
action.element.button
|
action.element.button
|
||||||
}
|
}
|
||||||
@ -125,6 +130,13 @@ public struct Alert: SwiftUIWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func textField(
|
||||||
|
_ label: String,
|
||||||
|
text: Meta.Binding<String>
|
||||||
|
) -> Self {
|
||||||
|
modify { $0.textField = (label, text) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Add a cancel button to the alert.
|
/// Add a cancel button to the alert.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - label: The button's label.
|
/// - label: The button's label.
|
||||||
|
|||||||
34
Sources/Core/View/TextField.swift
Normal file
34
Sources/Core/View/TextField.swift
Normal file
@ -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<String>) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user