30 lines
818 B
Swift
30 lines
818 B
Swift
import SwiftUI
|
|
|
|
struct SelectableListItem<Content>: View where Content: View {
|
|
|
|
let content: () -> Content
|
|
|
|
let selected: Bool
|
|
|
|
public init(selected: Bool, @ViewBuilder content: @escaping () -> Content) {
|
|
self.selected = selected
|
|
self.content = content
|
|
}
|
|
|
|
var body: some View {
|
|
HStack {
|
|
content()
|
|
Spacer()
|
|
}
|
|
.padding(.horizontal, 4)
|
|
.padding(.vertical, 7)
|
|
.foregroundStyle(selected ? Color.white : Color.primary)
|
|
.background(selected ? Color.blue : Color.clear)
|
|
.clipShape(RoundedRectangle(cornerRadius: 5))
|
|
.contentShape(Rectangle())
|
|
.listRowInsets(.init(top: 0, leading: -8, bottom: 0, trailing: -8))
|
|
.listRowBackground(Color.clear)
|
|
.listRowSeparator(.hidden)
|
|
}
|
|
}
|