feat: Cleaning up shared models.
This commit is contained in:
40
Sources/Styleguide/Pickers/CaseIterablePicker.swift
Normal file
40
Sources/Styleguide/Pickers/CaseIterablePicker.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
import SwiftUI
|
||||
|
||||
public struct CaseIterablePicker<Label, Content>: View
|
||||
where Content: CaseIterable,
|
||||
Content: CustomStringConvertible,
|
||||
Content: Hashable,
|
||||
Content: Identifiable,
|
||||
Content.AllCases: RandomAccessCollection,
|
||||
Label: View
|
||||
{
|
||||
|
||||
let label: () -> Label
|
||||
@Binding<Content> var selection: Content
|
||||
|
||||
public init(
|
||||
selection: Binding<Content>,
|
||||
@ViewBuilder label: @escaping () -> Label
|
||||
) {
|
||||
self.label = label
|
||||
self._selection = selection
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Picker(selection: $selection, label: label()) {
|
||||
ForEach(Content.allCases) {
|
||||
Text($0.description)
|
||||
.tag($0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension CaseIterablePicker where Label == Text {
|
||||
|
||||
public init<S: StringProtocol>(_ title: S, selection: Binding<Content>) {
|
||||
self.init(selection: selection) {
|
||||
Text(title)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user