27 lines
640 B
Swift
27 lines
640 B
Swift
import SwiftUI
|
|
|
|
struct SelectableListItem<Content>: View where Content: View {
|
|
|
|
let content: Content
|
|
|
|
let selected: Bool
|
|
|
|
public init(selected: Bool, @ViewBuilder content: () -> Content) {
|
|
self.selected = selected
|
|
self.content = content()
|
|
}
|
|
|
|
var body: some View {
|
|
HStack {
|
|
content
|
|
Spacer()
|
|
}
|
|
.foregroundStyle(selected ? Color.white : Color.primary)
|
|
.listRowBackground(RoundedRectangle(cornerRadius: 5)
|
|
.fill(selected ? Color.blue : Color.clear)
|
|
.padding(.horizontal, 10)
|
|
)
|
|
.contentShape(Rectangle())
|
|
}
|
|
}
|