// // List.swift // MacBackend // // Created by david-swift on 23.11.2024. // import SwiftUI /// A list widget. public struct List: SwiftUIWidget where Element: Identifiable { /// The elements. var elements: [Element] /// The selected element. var selection: Meta.Binding /// The content for an element. var content: (Element) -> Body /// The wrapped views. public var wrappedViews: [String: any Meta.AnyView] { elements.reduce(into: [:]) { partialResult, element in partialResult["\(element.id)"] = content(element) } } /// Initialize a list widget. /// - Parameters: /// - elements: The elements. /// - selection: The selected element. /// - content: The content for an element. public init( _ elements: [Element], selection: Meta.Binding, @Meta.ViewBuilder content: @escaping (Element) -> Body ) { self.elements = elements self.content = content self.selection = selection } /// Get the SwiftUI view. /// - Parameter properties: The widget data. /// - Returns: The SwiftUI view. public static func view(properties: Self) -> some SwiftUI.View { SwiftUI.List(properties.elements, selection: properties.selection.swiftUI) { element in MacBackendView("\(element.id)") } } }