Add support for bottom actions
Some checks failed
SwiftLint / SwiftLint (push) Waiting to run
Deploy Docs / publish (push) Has been cancelled

This commit is contained in:
david-swift 2025-01-31 19:14:33 +01:00
parent 27c30dfd79
commit 11c1cba681
2 changed files with 34 additions and 0 deletions

View File

@ -130,6 +130,11 @@ public struct Alert: SwiftUIWidget {
} }
} }
/// Set the text field's property and present the text field.
/// - Parameters:
/// - label: The text field's label.
/// - text: The content.
/// - Returns: The alert view.
public func textField( public func textField(
_ label: String, _ label: String,
text: Meta.Binding<String> text: Meta.Binding<String>

View File

@ -16,6 +16,8 @@ public struct List<Element>: SwiftUIWidget where Element: Identifiable {
var selection: Meta.Binding<Element.ID?> var selection: Meta.Binding<Element.ID?>
/// The content for an element. /// The content for an element.
var content: (Element) -> Body var content: (Element) -> Body
/// The action at the bottom.
var bottomAction: ((String, Icon), () -> Void)?
/// The wrapped views. /// The wrapped views.
public var wrappedViews: [String: any Meta.AnyView] { public var wrappedViews: [String: any Meta.AnyView] {
@ -46,6 +48,33 @@ public struct List<Element>: SwiftUIWidget where Element: Identifiable {
SwiftUI.List(properties.elements, selection: properties.selection.swiftUI) { element in SwiftUI.List(properties.elements, selection: properties.selection.swiftUI) { element in
MacBackendView("\(element.id)") MacBackendView("\(element.id)")
} }
.safeAreaInset(edge: .bottom, alignment: .leading) {
if let action = properties.bottomAction {
SwiftUI.Button {
action.1()
} label: {
SwiftUI.Label {
SwiftUI.Text(action.0.0)
} icon: {
action.0.1.image
}
}
.buttonStyle(.plain)
.foregroundStyle(.secondary)
.symbolVariant(.circle)
.padding([.bottom, .leading], 7)
}
}
}
/// Add a button to the bottom of the list.
/// - Parameters:
/// - label: The button's label.
/// - icon: The button's icon.
/// - handler: The handler.
/// - Returns: The list.
public func bottomAction(_ label: String, icon: Icon, handler: @escaping () -> Void) -> Self {
modify { $0.bottomAction = ((label, icon), handler) }
} }
} }