@@ -18,6 +18,8 @@ public enum SortFilterItem: Identifiable, Hashable {
1818 return item. id
1919 case . stepper( let item, _) :
2020 return item. id
21+ case . title( let item, _) :
22+ return item. id
2123 }
2224 }
2325
@@ -67,6 +69,13 @@ public enum SortFilterItem: Identifiable, Hashable {
6769 /// 2. A section of view containing a SwiftUI Stepper with Fiori style
6870 case stepper( item: StepperItem , showsOnFilterFeedbackBar: Bool )
6971
72+ /// The type of UI control is used to build:
73+ ///
74+ /// 1. Sort & Filter's menu item associated with a popover containing a SwiftUI TitleFormView with Fiori style
75+ ///
76+ /// 2. A section of view containing a SwiftUI TitleFormView with Fiori style
77+ case title( item: TitleItem , showsOnFilterFeedbackBar: Bool )
78+
7079 public var showsOnFilterFeedbackBar : Bool {
7180 switch self {
7281 case . picker( _, let showsOnFilterFeedbackBar) :
@@ -81,6 +90,8 @@ public enum SortFilterItem: Identifiable, Hashable {
8190 return showsOnFilterFeedbackBar
8291 case . stepper( _, let showsOnFilterFeedbackBar) :
8392 return showsOnFilterFeedbackBar
93+ case . title( _, let showsOnFilterFeedbackBar) :
94+ return showsOnFilterFeedbackBar
8495 }
8596 }
8697
@@ -117,6 +128,11 @@ public enum SortFilterItem: Identifiable, Hashable {
117128 hasher. combine ( item. originalValue)
118129 hasher. combine ( item. workingValue)
119130 hasher. combine ( item. value)
131+ case . title( let item, _) :
132+ hasher. combine ( item. id)
133+ hasher. combine ( item. originalText)
134+ hasher. combine ( item. workingText)
135+ hasher. combine ( item. text)
120136 }
121137 }
122138}
@@ -242,6 +258,26 @@ extension SortFilterItem {
242258 }
243259 }
244260
261+ var title : TitleItem {
262+ get {
263+ switch self {
264+ case . title( let item, _) :
265+ return item
266+ default :
267+ fatalError ( " Unexpected value \( self ) " )
268+ }
269+ }
270+
271+ set {
272+ switch self {
273+ case . title( _, let showsOnFilterFeedbackBar) :
274+ self = . title( item: newValue, showsOnFilterFeedbackBar: showsOnFilterFeedbackBar)
275+ default :
276+ fatalError ( " Unexpected value \( self ) " )
277+ }
278+ }
279+ }
280+
245281 var isChanged : Bool {
246282 switch self {
247283 case . picker( let item, _) :
@@ -256,6 +292,8 @@ extension SortFilterItem {
256292 return item. isChanged
257293 case . stepper( let item, _) :
258294 return item. isChanged
295+ case . title( let item, _) :
296+ return item. isChanged
259297 }
260298 }
261299
@@ -273,6 +311,8 @@ extension SortFilterItem {
273311 return item. isOriginal
274312 case . stepper( let item, _) :
275313 return item. isOriginal
314+ case . title( let item, _) :
315+ return item. isOriginal
276316 }
277317 }
278318
@@ -296,6 +336,9 @@ extension SortFilterItem {
296336 case . stepper( var item, _) :
297337 item. cancel ( )
298338 self . stepper = item
339+ case . title( var item, _) :
340+ item. cancel ( )
341+ self . title = item
299342 }
300343 }
301344
@@ -319,6 +362,9 @@ extension SortFilterItem {
319362 case . stepper( var item, _) :
320363 item. reset ( )
321364 self . stepper = item
365+ case . title( var item, _) :
366+ item. reset ( )
367+ self . title = item
322368 }
323369 }
324370
@@ -342,6 +388,9 @@ extension SortFilterItem {
342388 case . stepper( var item, _) :
343389 item. apply ( )
344390 self . stepper = item
391+ case . title( var item, _) :
392+ item. apply ( )
393+ self . title = item
345394 }
346395 }
347396}
@@ -1039,4 +1088,91 @@ public extension SortFilterItem {
10391088 self . workingValue == self . originalValue
10401089 }
10411090 }
1091+
1092+ /// Data structure for title type
1093+ struct TitleItem : Identifiable , Equatable {
1094+ public var id : String
1095+ public var name : String
1096+ public let icon : String ?
1097+
1098+ public var text : String
1099+ var workingText : String
1100+ let originalText : String
1101+ public var isSecureEnabled : Bool ? = false
1102+ public var placeholder : String ?
1103+ public var controlState : ControlState = . normal
1104+ public var errorMessage : String ?
1105+ public var maxTextLength : Int ?
1106+ public let hintText : String ?
1107+ public let hidesReadOnlyHint : Bool
1108+ public let isCharCountEnabled : Bool
1109+ public let allowsBeyondLimit : Bool
1110+ public let charCountReachLimitMessage : String ?
1111+ public let charCountBeyondLimitMsg : String ?
1112+
1113+ /// Create a textfiled.
1114+ /// - Parameters:
1115+ /// - id: The unique identifier for TitleItem.
1116+ /// - name: Item name.
1117+ /// - text: The text in textfield.
1118+ /// - isSecureEnabled: A boolean value to indicate to whether the textfield is secure textfield.
1119+ /// - placeholder: A text for placeholder of textfield.
1120+ /// - controlState: A state for textfield.
1121+ /// - errorMessage: A text when the text of textfield not satisfy conditions.
1122+ /// - maxTextLength: A maximum value for text length.
1123+ /// - hidesReadOnlyHint: A boolean value to indicate to hide read only hint or not.
1124+ /// - isCharCountEnabled: A boolean value to indicate to display char count or not.
1125+ /// - allowsBeyondLimit: A boolean value to indicate to allows inputting text beyond maximum char count limit or not.
1126+ /// - charCountReachLimitMessage: A text for char count reach maximum limit.
1127+ /// - charCountBeyondLimitMsg: A text for char beyond maximum limit.
1128+ /// - icon: The icon image in the item bar.
1129+ /// - hintText: The hint text of the textfiled.
1130+ public init ( id: String = UUID ( ) . uuidString, name: String , text: String , isSecureEnabled: Bool ? = false , placeholder: String ? = nil , controlState: ControlState = . normal, errorMessage: String ? = nil , maxTextLength: Int ? = nil , hidesReadOnlyHint: Bool = false , isCharCountEnabled: Bool = false , allowsBeyondLimit: Bool = false , charCountReachLimitMessage: String ? = nil , charCountBeyondLimitMsg: String ? = nil , icon: String ? = nil , hintText: String ? = nil ) {
1131+ self . id = id
1132+ self . name = name
1133+ self . text = text
1134+ self . workingText = text
1135+ self . originalText = text
1136+ self . icon = icon
1137+ self . isSecureEnabled = isSecureEnabled
1138+ self . placeholder = placeholder
1139+ self . controlState = controlState
1140+ self . errorMessage = errorMessage
1141+ self . maxTextLength = maxTextLength
1142+ self . hidesReadOnlyHint = hidesReadOnlyHint
1143+ self . isCharCountEnabled = isCharCountEnabled
1144+ self . allowsBeyondLimit = allowsBeyondLimit
1145+ self . charCountReachLimitMessage = charCountReachLimitMessage
1146+ self . charCountBeyondLimitMsg = charCountBeyondLimitMsg
1147+ self . hintText = hintText
1148+ }
1149+
1150+ mutating func reset( ) {
1151+ self . workingText = self . originalText
1152+ }
1153+
1154+ mutating func cancel( ) {
1155+ self . workingText = self . text
1156+ }
1157+
1158+ mutating func apply( ) {
1159+ self . text = self . workingText
1160+ }
1161+
1162+ var isChecked : Bool {
1163+ !self . text. isEmpty
1164+ }
1165+
1166+ var isChanged : Bool {
1167+ self . text != self . workingText
1168+ }
1169+
1170+ var isOriginal : Bool {
1171+ self . workingText == self . originalText
1172+ }
1173+
1174+ var label : String {
1175+ " \( self . name) : \( self . text) "
1176+ }
1177+ }
10421178}
0 commit comments