You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: improve signature of control item components woth better management of labels (#1314) (#1316)
Improve API of checkbox item, checkbox item indeterminate and radio item signatures to use first the label as not-named parameter and then the binding so as to be aligned with switch item signature
Closes#1314
Assisted-by: GitHub Copilot
Reviewed-by: Ludovic Pinel <ludovic.pinel@orange.com>
Reviewed-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Ludovic Pinel <ludovic.pinel@orange.com>
Co-authored-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com>
Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com>
/// If you need to flip your icon depending to the layout direction or not (e.g. if RTL mode lose semantics / meanings):
108
108
/// ```swift
109
109
/// @Environment(\.layoutDirection) var layoutDirection
110
110
///
111
-
/// OUDSCheckboxItem(isOn: $selection,
112
-
/// label: "Cocorico !",
111
+
/// OUDSCheckboxItem("Cocorico !",
112
+
/// isOn: $selection,
113
113
/// icon: Image(systemName: "figure.handball"),
114
114
/// flipIcon: layoutDirection == .rightToLeft,
115
115
/// isInversed: layoutDirection == .rightToLeft)
@@ -173,12 +173,12 @@ public struct OUDSCheckboxItem: View {
173
173
/// provide the localized string if key is stored in another bundle.**
174
174
///
175
175
/// - Parameters:
176
-
/// - isOn: A binding to a property that determines wether the indicator is ticked (selected) or not (unselected)
176
+
/// - isOn: A binding to a property that determines whether the indicator is ticked (selected) or not (unselected)
177
177
/// - label: The main label text of the checkbox, must not be empty
178
-
/// - description: An additonal helper text, a description, which should not be empty, default set to `nil`. Will be repalced by `errorText` in case of error.
179
-
/// - icon: An optional icon, default set to `nil`
180
-
/// - flipIcon: Default set to `false`, set to true` to reverse the image (i.e. flip vertically)
181
-
/// - isReversed: `true` if the checkbox indicator must be in trailing position,` false` otherwise. Default to `false`
178
+
/// - description: An additional helper text, a description, which should not be empty, default set to `nil`. Will be replaced by `errorText` in case of error.
179
+
/// - icon: An optional icon, default set to `nil`
180
+
/// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
181
+
/// - isReversed: `true` if the checkbox indicator must be in trailing position, `false` otherwise. Default to `false`
182
182
/// - isError: `true` if the look and feel of the component must reflect an error state, default set to `false`
183
183
/// - errorText: An optional error message to display at the bottom. This message is ignored if `isError` is `false`.
184
184
/// The `errorText`can be different if switch is selected or not.
@@ -188,6 +188,7 @@ public struct OUDSCheckboxItem: View {
188
188
/// When `false`, no specific width constraint is applied, allowing the component to size itself or follow external
189
189
/// modifier. Defaults to `false`.
190
190
/// - action: An additional action to trigger when the checkbox has been pressed
@@ -200,6 +201,63 @@ public struct OUDSCheckboxItem: View {
200
201
hasDivider:Bool=false,
201
202
constrainedMaxWidth:Bool=false,
202
203
action:(()->Void)?=nil)
204
+
{
205
+
self.init(label,
206
+
isOn: isOn,
207
+
description: description,
208
+
icon: icon,
209
+
flipIcon: flipIcon,
210
+
isReversed: isReversed,
211
+
isError: isError,
212
+
errorText: errorText,
213
+
isReadOnly: isReadOnly,
214
+
hasDivider: hasDivider,
215
+
constrainedMaxWidth: constrainedMaxWidth,
216
+
action: action)
217
+
}
218
+
219
+
/// Creates a checkbox with label and optional helper text, icon, divider.
220
+
///
221
+
/// ```swift
222
+
/// OUDSCheckboxItem("Virgin Holy Lava",
223
+
/// isOn: $isOn,
224
+
/// description: "Very spicy",
225
+
/// icon: Image(systemName: "flame")
226
+
/// ```
227
+
///
228
+
/// **The design system does not allow to have both an error situation and a read only mode for the component.**
229
+
///
230
+
/// **Remark: If `label` and `description` strings are wording keys from strings catalog stored in `Bundle.main`, they are automatically localized. Else, prefer to
231
+
/// provide the localized string if key is stored in another bundle.**
232
+
///
233
+
/// - Parameters:
234
+
/// - label: The main label text of the checkbox, must not be empty
235
+
/// - isOn: A binding to a property that determines whether the indicator is ticked (selected) or not (unselected)
236
+
/// - description: An additional helper text, a description, which should not be empty, default set to `nil`. Will be replaced by `errorText` in case of error.
237
+
/// - icon: An optional icon, default set to `nil`
238
+
/// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
239
+
/// - isReversed: `true` if the checkbox indicator must be in trailing position, `false` otherwise. Default to `false`
240
+
/// - isError: `true` if the look and feel of the component must reflect an error state, default set to `false`
241
+
/// - errorText: An optional error message to display at the bottom. This message is ignored if `isError` is `false`.
242
+
/// The `errorText`can be different if switch is selected or not.
243
+
/// - isReadOnly: True if component is in read only, i.e. not really disabled but user cannot interact with it yet, default set to `false`
244
+
/// - hasDivider: If `true` a divider is added at the bottom of the view, by default set to `false`
245
+
/// - constrainedMaxWidth: When `true`, the item width is constrained to a maximum value defined by the design system.
246
+
/// When `false`, no specific width constraint is applied, allowing the component to size itself or follow external
247
+
/// modifier. Defaults to `false`.
248
+
/// - action: An additional action to trigger when the checkbox has been pressed
249
+
publicinit(_ label:String,
250
+
isOn:Binding<Bool>,
251
+
description:String?=nil,
252
+
icon:Image?=nil,
253
+
flipIcon:Bool=false,
254
+
isReversed:Bool=false,
255
+
isError:Bool=false,
256
+
errorText:String?=nil,
257
+
isReadOnly:Bool=false,
258
+
hasDivider:Bool=false,
259
+
constrainedMaxWidth:Bool=false,
260
+
action:(()->Void)?=nil)
203
261
{
204
262
if isError, isReadOnly {
205
263
OL.fatal("It is forbidden by design to have an OUDSCheckboxItem in an error context and in read only mode")
0 commit comments