Skip to content

Commit 58b34e3

Browse files
pylappludovic35
andauthored
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>
1 parent 6c13dd3 commit 58b34e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+291
-110
lines changed

AGENTS.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,16 +564,16 @@ OUDSCheckbox(isOn: $isOn, accessibilityLabel: "Some label to vocalize")
564564
or with texts and image:
565565
```swift
566566
@Published var isOn: Bool = true
567-
OUDSCheckboxItem(isOn: $isOn,
568-
label: "An important text",
567+
OUDSCheckboxItem("An important text",
568+
isOn: $isOn,
569569
description: "A secondary text",
570570
icon: Image(decorative: "image_name"))
571571
```
572572

573573
or only with one text:
574574
```swift
575575
@Published var isOn: Bool = true
576-
OUDSCheckboxItem(isOn: $isOn, label: "Hello world")
576+
OUDSCheckboxItem("Hello world", isOn: $isOn)
577577
```
578578

579579
Checkboxes can be wrapped inside a checkbox picker.
@@ -615,15 +615,15 @@ OUDSRadio(isOn: $selection, accessibilityLabel: "Some label to vocalized")
615615
or with texts and image:
616616
```swift
617617
@Published var isOn: Bool = true
618-
OUDSRadioItem(isOn: $isOn,
619-
label: "Some text",
618+
OUDSRadioItem("Some text",
619+
isOn: $isOn,
620620
icon: Image(decorative: "image_name"))
621621
```
622622

623623
or only with one text:
624624
```swift
625625
@Published var isOn: Bool = true
626-
OUDSRadioItem(isOn: $isOn, label: "Some text")
626+
OUDSRadioItem("Some text", isOn: $isOn)
627627
```
628628

629629
Radio buttons can be wrapped inside a radio picker.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
- `alert message` component (Orange-OpenSource/ouds-ios#1159)
1212

13+
### Changed
14+
15+
- Signatures of control-item-based components (Orange-OpenSource/ouds-ios#1314)
16+
1317
### Fixed
1418

1519
- Size of loader for `button` component (Orange-OpenSource/ouds-ios#1296)

OUDS/Core/Components/Sources/Controls/Checkbox/OUDSCheckbox.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public struct OUDSCheckbox: View {
110110
/// **The design system does not allow to have both an error or read only situation and a disabled state for the component.**
111111
///
112112
/// - Parameters:
113-
/// - isOn: A binding to a property that determines wether the indicator is ticked (selected) or not (not selected)
113+
/// - isOn: A binding to a property that determines whether the indicator is ticked (selected) or not (not selected)
114114
/// - accessibilityLabel: The accessibility label the component must have
115115
/// - isError: True if the look and feel of the component must reflect an error state, default set to `false`
116116
/// - isReadOnly: True if the look and feel of the component must reflect a read only state, default set to `false`

OUDS/Core/Components/Sources/Controls/Checkbox/OUDSCheckboxIndeterminate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public struct OUDSCheckboxIndeterminate: View {
110110
/// **The design system does not allow to have both an error situation and a disabled state for the component.**
111111
///
112112
/// - Parameters:
113-
/// - selection: A binding to a property that determines wether the indicator is ticked, unticked or preticked.
113+
/// - selection: A binding to a property that determines whether the indicator is ticked, unticked or preticked.
114114
/// - accessibilityLabel: The accessibility label the component must have
115115
/// - isError: True if the look and feel of the component must reflect an error state, default set to `false`
116116
/// - isReadOnly: True if the look and feel of the component must reflect a read only state, default set to `false`

OUDS/Core/Components/Sources/Controls/Checkbox/OUDSCheckboxItem.swift

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,48 +68,48 @@ import SwiftUI
6868
///
6969
/// // A leading checkbox with a label.
7070
/// // The default layout will be used here.
71-
/// OUDSCheckboxItem(isOn: $isOn, label: "Hello world")
71+
/// OUDSCheckboxItem("Hello world", isOn: $isOn)
7272
///
7373
/// // A leading checkbox with a label, but in read only mode (user cannot interact yet, but not disabled).
7474
/// // The default layout will be used here.
75-
/// OUDSCheckboxItem(isOn: $isOn, label: "Hello world", isReadOnly: true)
75+
/// OUDSCheckboxItem("Hello world", isOn: $isOn, isReadOnly: true)
7676
///
7777
/// // A leading checkbox with a label and a description as helper text.
7878
/// // The default layout will be used here.
79-
/// OUDSCheckboxItem(isOn: $isOn, label: "Bazinga!", description: "Doll-Dagga Buzz-Buzz Ziggety-Zag")
79+
/// OUDSCheckboxItem("Bazinga!", isOn: $isOn, description: "Doll-Dagga Buzz-Buzz Ziggety-Zag")
8080
///
8181
/// // A trailing checkbox with a label, a description and an icon.
8282
/// // The reversed layout will be used here.
83-
/// OUDSCheckboxItem(isOn: $isOn,
84-
/// label: "We live in a fabled world",
83+
/// OUDSCheckboxItem("We live in a fabled world",
84+
/// isOn: $isOn,
8585
/// description: "Of dreaming boys and wide-eyed girls",
8686
/// isReversed: true,
8787
/// icon: Image(decorative: "ic_heart"))
8888
///
8989
/// // If on error, add an error message can help user to understand error context
90-
/// OUDSCheckboxItem(isOn: $isOn,
91-
/// label: "We live in a fabled world",
90+
/// OUDSCheckboxItem("We live in a fabled world",
91+
/// isOn: $isOn,
9292
/// isError: true,
9393
/// errorText: "Something wrong",
9494
/// hasDivider: true)
9595
///
9696
/// // A leading checkbox with a label, but disabled.
9797
/// // The default layout will be used here.
98-
/// OUDSCheckboxItem(isOn: $isOn, label: "Hello world")
98+
/// OUDSCheckboxItem("Hello world", isOn: $isOn)
9999
/// .disabled(true)
100100
///
101101
/// // Never disable a read only or an error-related checkbox as it will crash
102102
/// // This is forbidden by design!
103-
/// OUDSCheckboxItem(isOn: $isOn, label: "Hello world", isError: true).disabled(true) // fatal error
104-
/// OUDSCheckboxItem(isOn: $isOn, label: "Hello world", isReadyOnly: true).disabled(true) // fatal error
103+
/// OUDSCheckboxItem("Hello world", isOn: $isOn, isError: true).disabled(true) // fatal error
104+
/// OUDSCheckboxItem("Hello world", isOn: $isOn, isReadyOnly: true).disabled(true) // fatal error
105105
/// ```
106106
///
107107
/// If you need to flip your icon depending to the layout direction or not (e.g. if RTL mode lose semantics / meanings):
108108
/// ```swift
109109
/// @Environment(\.layoutDirection) var layoutDirection
110110
///
111-
/// OUDSCheckboxItem(isOn: $selection,
112-
/// label: "Cocorico !",
111+
/// OUDSCheckboxItem("Cocorico !",
112+
/// isOn: $selection,
113113
/// icon: Image(systemName: "figure.handball"),
114114
/// flipIcon: layoutDirection == .rightToLeft,
115115
/// isInversed: layoutDirection == .rightToLeft)
@@ -173,12 +173,12 @@ public struct OUDSCheckboxItem: View {
173173
/// provide the localized string if key is stored in another bundle.**
174174
///
175175
/// - 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)
177177
/// - 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`
182182
/// - isError: `true` if the look and feel of the component must reflect an error state, default set to `false`
183183
/// - errorText: An optional error message to display at the bottom. This message is ignored if `isError` is `false`.
184184
/// The `errorText`can be different if switch is selected or not.
@@ -188,6 +188,7 @@ public struct OUDSCheckboxItem: View {
188188
/// When `false`, no specific width constraint is applied, allowing the component to size itself or follow external
189189
/// modifier. Defaults to `false`.
190190
/// - action: An additional action to trigger when the checkbox has been pressed
191+
@available(*, deprecated, message: "Use instead OUDSCheckboxItem(:isOn:)")
191192
public init(isOn: Binding<Bool>,
192193
label: String,
193194
description: String? = nil,
@@ -200,6 +201,63 @@ public struct OUDSCheckboxItem: View {
200201
hasDivider: Bool = false,
201202
constrainedMaxWidth: Bool = false,
202203
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+
public init(_ 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)
203261
{
204262
if isError, isReadOnly {
205263
OL.fatal("It is forbidden by design to have an OUDSCheckboxItem in an error context and in read only mode")

0 commit comments

Comments
 (0)