@@ -88,6 +88,13 @@ extension InputFieldVM {
88
88
return UniversalFont . Component. large
89
89
}
90
90
}
91
+ var height : CGFloat {
92
+ return switch self . size {
93
+ case . small: 40
94
+ case . medium: 60
95
+ case . large: 80
96
+ }
97
+ }
91
98
var horizontalPadding : CGFloat {
92
99
switch self . cornerRadius {
93
100
case . none, . small, . medium, . large, . custom:
@@ -97,7 +104,7 @@ extension InputFieldVM {
97
104
}
98
105
}
99
106
var spacing : CGFloat {
100
- return 12
107
+ return self . title . isNotNilAndEmpty ? 12 : 0
101
108
}
102
109
var backgroundColor : UniversalColor {
103
110
if let color {
@@ -121,60 +128,6 @@ extension InputFieldVM {
121
128
var placeholderColor : UniversalColor {
122
129
return self . foregroundColor. withOpacity ( self . isEnabled ? 0.7 : 0.3 )
123
130
}
124
- func titleColor( for position: InputFieldTitlePosition ) -> UniversalColor {
125
- switch position {
126
- case . top:
127
- return self . foregroundColor
128
- case . center:
129
- return self . foregroundColor. withOpacity ( self . isEnabled ? 0.8 : 0.45 )
130
- }
131
- }
132
- func titleFont( for position: InputFieldTitlePosition ) -> UniversalFont {
133
- switch position {
134
- case . top:
135
- return self . preferredFont. withRelativeSize ( - 1 )
136
- case . center:
137
- let relativePadding : CGFloat = switch self . size {
138
- case . small: 1.5
139
- case . medium: 2
140
- case . large: 3
141
- }
142
- return self . preferredFont. withRelativeSize ( relativePadding)
143
- }
144
- }
145
- }
146
-
147
- // MARK: - Layout Helpers
148
-
149
- extension InputFieldVM {
150
- var inputFieldTopPadding : CGFloat {
151
- switch self . size {
152
- case . small: 30
153
- case . medium: 34
154
- case . large: 38
155
- }
156
- }
157
- var inputFieldHeight : CGFloat {
158
- switch self . size {
159
- case . small: 26
160
- case . medium: 28
161
- case . large: 30
162
- }
163
- }
164
- var verticalPadding : CGFloat {
165
- switch self . size {
166
- case . small: 12
167
- case . medium: 14
168
- case . large: 16
169
- }
170
- }
171
- var height : CGFloat {
172
- return switch self . size {
173
- case . small: 40
174
- case . medium: 60
175
- case . large: 80
176
- }
177
- }
178
131
}
179
132
180
133
// MARK: - UIKit Helpers
@@ -189,17 +142,17 @@ extension InputFieldVM {
189
142
. foregroundColor: self . placeholderColor. uiColor
190
143
] )
191
144
}
192
- func nsAttributedTitle( for position : InputFieldTitlePosition ) -> NSAttributedString {
145
+ var nsAttributedTitle : NSAttributedString ? {
193
146
guard let title else {
194
- return NSAttributedString ( )
147
+ return nil
195
148
}
196
149
197
150
let attributedString = NSMutableAttributedString ( )
198
151
attributedString. append ( NSAttributedString (
199
152
string: title,
200
153
attributes: [
201
- . font: self . titleFont ( for : position ) . uiFont,
202
- . foregroundColor: self . titleColor ( for : position ) . uiColor
154
+ . font: self . preferredFont . uiFont,
155
+ . foregroundColor: self . foregroundColor . uiColor
203
156
]
204
157
) )
205
158
if self . isRequired {
@@ -212,7 +165,7 @@ extension InputFieldVM {
212
165
attributedString. append ( NSAttributedString (
213
166
string: " * " ,
214
167
attributes: [
215
- . font: self . titleFont ( for : position ) . uiFont,
168
+ . font: self . preferredFont . uiFont,
216
169
. foregroundColor: UniversalColor . danger. uiColor
217
170
]
218
171
) )
@@ -222,40 +175,22 @@ extension InputFieldVM {
222
175
func shouldUpdateLayout( _ oldModel: Self ) -> Bool {
223
176
return self . size != oldModel. size
224
177
|| self . horizontalPadding != oldModel. horizontalPadding
178
+ || self . spacing != oldModel. spacing
179
+ || self . cornerRadius != oldModel. cornerRadius
225
180
}
226
181
}
227
182
228
- // MARK: - UIKit Helpers
183
+ // MARK: - SwiftUI Helpers
229
184
230
185
extension InputFieldVM {
231
186
var autocorrectionType : UITextAutocorrectionType {
232
187
return self . isAutocorrectionEnabled ? . yes : . no
233
188
}
234
- func attributedTitle(
235
- for position: InputFieldTitlePosition
236
- ) -> AttributedString {
237
- guard let title else {
238
- return AttributedString ( )
239
- }
240
-
241
- var attributedString = AttributedString ( )
242
-
243
- var attributedTitle = AttributedString ( title)
244
- attributedTitle. font = self . titleFont ( for: position) . font
245
- attributedTitle. foregroundColor = self . titleColor ( for: position) . uiColor
246
- attributedString. append ( attributedTitle)
247
-
248
- if self . isRequired {
249
- var space = AttributedString ( " " )
250
- space. font = . systemFont( ofSize: 5 )
251
- attributedString. append ( space)
252
-
253
- var requiredSign = AttributedString ( " * " )
254
- requiredSign. font = self . titleFont ( for: position) . font
255
- requiredSign. foregroundColor = UniversalColor . danger. uiColor
256
- attributedString. append ( requiredSign)
189
+ var attributedTitle : AttributedString ? {
190
+ guard let nsAttributedTitle else {
191
+ return nil
257
192
}
258
193
259
- return attributedString
194
+ return AttributedString ( nsAttributedTitle )
260
195
}
261
196
}
0 commit comments