From 11c1cba6815a41f333f300a2d3bd0220e807039b Mon Sep 17 00:00:00 2001 From: david-swift Date: Fri, 31 Jan 2025 19:14:33 +0100 Subject: [PATCH] Add support for bottom actions --- Sources/Core/View/Alert.swift | 5 +++++ Sources/Core/View/List.swift | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Sources/Core/View/Alert.swift b/Sources/Core/View/Alert.swift index 250ede5..b053c16 100644 --- a/Sources/Core/View/Alert.swift +++ b/Sources/Core/View/Alert.swift @@ -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( _ label: String, text: Meta.Binding diff --git a/Sources/Core/View/List.swift b/Sources/Core/View/List.swift index abc51cc..2dfc679 100644 --- a/Sources/Core/View/List.swift +++ b/Sources/Core/View/List.swift @@ -16,6 +16,8 @@ public struct List: SwiftUIWidget where Element: Identifiable { var selection: Meta.Binding /// The content for an element. var content: (Element) -> Body + /// The action at the bottom. + var bottomAction: ((String, Icon), () -> Void)? /// The wrapped views. public var wrappedViews: [String: any Meta.AnyView] { @@ -46,6 +48,33 @@ public struct List: SwiftUIWidget where Element: Identifiable { SwiftUI.List(properties.elements, selection: properties.selection.swiftUI) { element in 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) } } }