feat: Cleaning up shared models.

This commit is contained in:
2024-06-10 09:03:54 -04:00
parent 68da203164
commit 51f7a30701
19 changed files with 383 additions and 339 deletions

View 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)
}
}
}

View File

@@ -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)
}
}

View File

@@ -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)
}
}

View File

@@ -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)
}
}