@@ -4,6 +4,7 @@ import SwiftUI
4
4
5
5
public final class PickerProps : ObservableObject , Decodable {
6
6
@Published var options : [ PickerOption ] = [ ]
7
+ @Published var config : PickerConfig ?
7
8
@Published var selection : String = " "
8
9
@Published var label : String = " "
9
10
@Published var pickerStyle : PickerStyle = . default
@@ -20,6 +21,36 @@ public final class PickerProps: ObservableObject, Decodable {
20
21
var id : String { value } // Use value as the unique identifier
21
22
}
22
23
24
+ struct PickerConfig : Decodable , Hashable {
25
+ let min : Int
26
+ let max : Int
27
+ let step : Int
28
+ let prefix : String
29
+ let suffix : String
30
+
31
+ // Generate options based on numeric configuration
32
+ func generateOptions( ) -> [ PickerOption ] {
33
+ var options : [ PickerOption ] = [ ]
34
+ var current = min
35
+
36
+ while current <= max {
37
+ let valueString = " \( current) "
38
+ let labelString = " \( prefix) \( current) \( suffix) "
39
+ options. append ( PickerOption ( label: labelString, value: valueString) )
40
+ current += step
41
+ }
42
+
43
+ return options
44
+ }
45
+ }
46
+
47
+ var computedOptions : [ PickerOption ] {
48
+ if config != nil {
49
+ return config!. generateOptions ( )
50
+ }
51
+ return options
52
+ }
53
+
23
54
enum PickerStyle : String , CaseIterable {
24
55
case `default`
25
56
case menu
@@ -46,7 +77,7 @@ public final class PickerProps: ObservableObject, Decodable {
46
77
47
78
// Coding keys for decoding
48
79
enum CodingKeys : String , CodingKey , CaseIterable {
49
- case label, selection, options, pickerStyle, disabled, style
80
+ case label, selection, options, config , pickerStyle, disabled, style
50
81
}
51
82
52
83
// Decodable initializer
@@ -55,6 +86,7 @@ public final class PickerProps: ObservableObject, Decodable {
55
86
label = try container. decodeIfPresent ( String . self, forKey: . label) ?? " "
56
87
selection = try container. decodeIfPresent ( String . self, forKey: . selection) ?? " "
57
88
options = try container. decodeIfPresent ( [ PickerOption ] . self, forKey: . options) ?? [ ]
89
+ config = try container. decodeIfPresent ( PickerConfig . self, forKey: . config)
58
90
if let styleString = try container. decodeIfPresent ( String . self, forKey: . pickerStyle) ,
59
91
let style = PickerStyle ( rawValue: styleString)
60
92
{
@@ -71,6 +103,7 @@ public final class PickerProps: ObservableObject, Decodable {
71
103
public func merge( from other: PickerProps ) {
72
104
options = other. options
73
105
selection = other. selection
106
+ config = other. config
74
107
label = other. label
75
108
pickerStyle = other. pickerStyle
76
109
disabled = other. disabled
0 commit comments