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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,13 @@ import SharedModels
|
||||
import SwiftUI
|
||||
|
||||
public struct CoolingCapacityPicker: View {
|
||||
@Binding var selection: CoolingCapacity
|
||||
|
||||
public init(selection: Binding<CoolingCapacity>) {
|
||||
@Binding var selection: EquipmentMetadata.CoolingCapacity
|
||||
|
||||
public init(selection: Binding<EquipmentMetadata.CoolingCapacity>) {
|
||||
self._selection = selection
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Picker("Cooling Capacity", selection: $selection) {
|
||||
ForEach(CoolingCapacity.allCases) {
|
||||
Text($0.description)
|
||||
.tag($0)
|
||||
}
|
||||
}
|
||||
CaseIterablePicker("Cooling Capacity", selection: $selection)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,13 @@ import SharedModels
|
||||
import SwiftUI
|
||||
|
||||
public struct EquipmentTypePicker: View {
|
||||
@Binding var selection: EquipmentType
|
||||
@Binding var selection: EquipmentMeasurement.EquipmentType
|
||||
|
||||
public init(selection: Binding<EquipmentType>) {
|
||||
public init(selection: Binding<EquipmentMeasurement.EquipmentType>) {
|
||||
self._selection = selection
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Picker("Equipment Type", selection: $selection) {
|
||||
ForEach(EquipmentType.allCases) {
|
||||
Text($0.description)
|
||||
.tag($0)
|
||||
}
|
||||
}
|
||||
CaseIterablePicker("Equipment Type", selection: $selection)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,14 @@ import SwiftUI
|
||||
|
||||
public struct FanTypePicker: View {
|
||||
|
||||
@Binding var selection: FanType
|
||||
@Binding var selection: EquipmentMetadata.FanType
|
||||
|
||||
public init(selection: Binding<FanType>) {
|
||||
public init(selection: Binding<EquipmentMetadata.FanType>) {
|
||||
self._selection = selection
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
Picker("Fan Type", selection: $selection) {
|
||||
ForEach(FanType.allCases) {
|
||||
Text($0.description)
|
||||
.tag($0)
|
||||
}
|
||||
}
|
||||
CaseIterablePicker("Fan Type", selection: $selection)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user