Add support for bottom actions
This commit is contained in:
parent
27c30dfd79
commit
461f9070c9
@ -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<String>
|
||||
|
||||
@ -16,6 +16,8 @@ public struct List<Element>: SwiftUIWidget where Element: Identifiable {
|
||||
var selection: Meta.Binding<Element.ID?>
|
||||
/// 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,34 @@ public struct List<Element>: 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.
|
||||
/// - visible: Whether the button is visible.
|
||||
/// - handler: The handler.
|
||||
/// - Returns: The list.
|
||||
public func bottomAction(_ label: String, icon: Icon, visible: Bool = true, handler: @escaping () -> Void) -> Self {
|
||||
modify { $0.bottomAction = visible ? ((label, icon), handler) : nil }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user