Skip to content

Commit 8f80df8

Browse files
committed
chore: add more inits with new param (#1364)
Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com>
1 parent 831fee5 commit 8f80df8

File tree

10 files changed

+313
-103
lines changed

10 files changed

+313
-103
lines changed

CHANGELOG.md

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

1414
### Changed
1515

16+
- `LocalizedStringKey` and `Bundle` initializers for components using `String` for texts and accessibility labels (Orange-OpenSource/ouds-ios#1364)
17+
- Update illustrations in documentation for `alert message` component (Orange-OpenSource/ouds-ios#1359)
1618
- View modifiers and methods prefixed by `ouds` are replaced by same names without such `ouds` (Orange-OpenSource/ouds-ios#1346)
1719
- Move from Xcode 26.2 to Xcode 26.3 (Orange-OpenSource/ouds-ios#1375)
18-
### Changed
19-
20-
- Update illustrations in documentation for `alert message` component (Orange-OpenSource/ouds-ios#1359)
21-
- `LocalizedStringKey` and `Bundle` initializers for `OUDSButton`, `OUDSLink`, `OUDSSuggestionChip`, `OUDSFilterChip`, `OUDSChipPicker`, `OUDSBulletList.Item`, `OUDSCheckboxItem`, `OUDSSwitchItem`, `OUDSRadioItem`, `OUDSTag`, `OUDSTextInput`, `OUDSPasswordInput`, `OUDSAlertMessage` and `OUDSInlineAlert` components (Orange-OpenSource/ouds-ios#1364)
2220

2321
## [1.3.0](https://github.com/Orange-OpenSource/ouds-ios/compare/1.2.0...1.3.0) - 2026-03-26
2422

OUDS/Core/Components/Sources/Actions/Button/OUDSButton.swift

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -176,117 +176,116 @@ public struct OUDSButton: View {
176176

177177
// MARK: Initializers
178178

179-
/// Creates a button with text and icon.
179+
// swiftlint:disable function_default_parameter_at_end
180+
/// Creates a button with a localized text and icon, looking up the key in the given bundle..
181+
/// A raw string can also be given to be displayed.
182+
///
183+
/// ```swift
184+
/// // Use localizable
185+
/// OUDSButton(LocalizedStringKey("validate_button"), bundle: Bundle.module, icon: Image("ic_checkmark"), appearance: .strong) { }
186+
/// ```
180187
///
181188
/// - Parameters:
182-
/// - text: The text to display in the button
189+
/// - key: A `LocalizedStringKey` used to look up the text in the given bundle, or a raw `String` to display
190+
/// - tableName: The name of the `.strings` file, or `nil` for the default
191+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
183192
/// - icon: An image which shoud contains an icon
184193
/// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
185194
/// - appearance: The button appearance, default set to `.default`
186195
/// - style: The button style, default set to `.default`
187196
/// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
188197
/// - action: The action to perform when the user triggers the button
189-
public init(text: String,
198+
public init(_ key: LocalizedStringKey,
199+
tableName: String? = nil,
200+
bundle: Bundle = .main,
190201
icon: Image,
191202
flipIcon: Bool = false,
192203
appearance: Appearance = .default,
193204
style: Style = .default,
194205
isFullWidth: Bool = false,
195206
action: @escaping () -> Void)
196207
{
197-
type = .textAndIcon(text: text, icon: icon, flipIcon: flipIcon)
198-
self.appearance = appearance
199-
self.style = style
200-
self.isFullWidth = isFullWidth
201-
self.action = action
202-
isHover = false
208+
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
209+
self.init(text: resolvedText, icon: icon, flipIcon: flipIcon, style: style, isFullWidth: isFullWidth, action: action)
203210
}
204211

205-
// swiftlint:disable function_default_parameter_at_end
206-
/// Creates a button with a localized text and icon, looking up the key in the given bundle..
207-
/// A raw string can also be given to be displayed.
208-
///
209-
/// ```swift
210-
/// // Use localizable
211-
/// OUDSButton(LocalizedStringKey("validate_button"), bundle: Bundle.module, icon: Image("ic_checkmark"), appearance: .strong) { }
212-
/// ```
212+
// swiftlint:enable function_default_parameter_at_end
213+
214+
/// Creates a button with text and icon.
213215
///
214216
/// - Parameters:
215-
/// - key: A `LocalizedStringKey` used to look up the text in the given bundle, or a raw `String` to display
216-
/// - tableName: The name of the `.strings` file, or `nil` for the default
217-
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
217+
/// - text: The text to display in the button
218218
/// - icon: An image which shoud contains an icon
219219
/// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
220220
/// - appearance: The button appearance, default set to `.default`
221221
/// - style: The button style, default set to `.default`
222222
/// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
223223
/// - action: The action to perform when the user triggers the button
224-
public init(_ key: LocalizedStringKey,
225-
tableName: String? = nil,
226-
bundle: Bundle = .main,
224+
public init(text: String,
227225
icon: Image,
228226
flipIcon: Bool = false,
229227
appearance: Appearance = .default,
230228
style: Style = .default,
231229
isFullWidth: Bool = false,
232230
action: @escaping () -> Void)
233231
{
234-
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
235-
type = .textAndIcon(text: resolvedText, icon: icon, flipIcon: flipIcon)
232+
type = .textAndIcon(text: text, icon: icon, flipIcon: flipIcon)
236233
self.appearance = appearance
237234
self.style = style
238235
self.isFullWidth = isFullWidth
239236
self.action = action
240237
isHover = false
241238
}
242239

243-
// swiftlint:enable function_default_parameter_at_end
244-
245240
/// Creates a button with an icon only.
246241
///
247242
/// - Parameters:
248243
/// - icon: An image which shoud contains an icon
249-
/// - accessibilityLabel: The text to vocalize with *Voice Over* describing the button action
244+
/// - key: The text to vocalize with *Voice Over* describing the button action, as as `LocalizedStringKey` for the given `Bundle`
245+
/// - tableName: The name of the `.strings` file, or `nil` for the default
246+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
250247
/// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
251248
/// - appearance: The button appearance, default set to `.default`
252249
/// - style: The button style, default set to `.default`
253250
/// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
254251
/// - action: The action to perform when the user triggers the button
255252
public init(icon: Image,
256-
accessibilityLabel: String,
253+
accessibilityLabel key: LocalizedStringKey,
254+
tableName: String? = nil,
255+
bundle: Bundle = .main,
257256
flipIcon: Bool = false,
258257
appearance: Appearance = .default,
259258
style: Style = .default,
260259
isFullWidth: Bool = false,
261260
action: @escaping () -> Void)
262261
{
263-
type = .icon(icon, flipIcon: flipIcon, accessibilityLabel)
264-
self.appearance = appearance
265-
self.style = style
266-
self.isFullWidth = isFullWidth
267-
self.action = action
268-
isHover = false
262+
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
263+
self.init(icon: icon, accessibilityLabel: resolvedText, flipIcon: flipIcon, appearance: appearance, style: style, isFullWidth: isFullWidth, action: action)
269264
}
270265

271-
/// Create a button with a text only.
266+
/// Creates a button with an icon only.
272267
///
273268
/// - Parameters:
274-
/// - text: The text of the button to display
269+
/// - icon: An image which shoud contains an icon
270+
/// - accessibilityLabel: The text to vocalize with *Voice Over* describing the button action
271+
/// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
275272
/// - appearance: The button appearance, default set to `.default`
276273
/// - style: The button style, default set to `.default`
277274
/// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
278275
/// - action: The action to perform when the user triggers the button
279-
public init(text: String,
276+
public init(icon: Image,
277+
accessibilityLabel: String,
278+
flipIcon: Bool = false,
280279
appearance: Appearance = .default,
281280
style: Style = .default,
282281
isFullWidth: Bool = false,
283282
action: @escaping () -> Void)
284283
{
285-
type = .text(text)
284+
type = .icon(icon, flipIcon: flipIcon, accessibilityLabel)
286285
self.appearance = appearance
287286
self.style = style
288-
self.action = action
289287
self.isFullWidth = isFullWidth
288+
self.action = action
290289
isHover = false
291290
}
292291

@@ -313,7 +312,24 @@ public struct OUDSButton: View {
313312
action: @escaping () -> Void)
314313
{
315314
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
316-
type = .text(resolvedText)
315+
self.init(text: resolvedText, appearance: appearance, style: style, isFullWidth: isFullWidth, action: action)
316+
}
317+
318+
/// Create a button with a text only.
319+
///
320+
/// - Parameters:
321+
/// - text: The text of the button to display
322+
/// - appearance: The button appearance, default set to `.default`
323+
/// - style: The button style, default set to `.default`
324+
/// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
325+
/// - action: The action to perform when the user triggers the button
326+
public init(text: String,
327+
appearance: Appearance = .default,
328+
style: Style = .default,
329+
isFullWidth: Bool = false,
330+
action: @escaping () -> Void)
331+
{
332+
type = .text(text)
317333
self.appearance = appearance
318334
self.style = style
319335
self.action = action

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ public struct OUDSCheckbox: View {
105105

106106
// MARK: Initializers
107107

108+
/// Creates a checkbox with only an indicator.
109+
///
110+
/// **The design system does not allow to have both an error or read only situation and a disabled state for the component.**
111+
///
112+
/// - Parameters:
113+
/// - isOn: A binding to a property that determines whether the indicator is ticked (selected) or not (not selected)
114+
/// - key: The text to vocalize with *Voice Over* the component must have, as as `LocalizedStringKey` for the given `Bundle`
115+
/// - tableName: The name of the `.strings` file, or `nil` for the default
116+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
117+
/// - isError: True if the look and feel of the component must reflect an error state, default set to `false`
118+
/// - isReadOnly: True if the look and feel of the component must reflect a read only state, default set to `false`
119+
public init(isOn: Binding<Bool>,
120+
accessibilityLabel key: LocalizedStringKey,
121+
tableName: String? = nil,
122+
bundle: Bundle = .main,
123+
isError: Bool = false,
124+
isReadOnly: Bool = false)
125+
{
126+
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
127+
self.init(isOn: isOn, accessibilityLabel: resolvedText, isError: isError, isReadOnly: isReadOnly)
128+
}
129+
108130
/// Creates a checkbox with only an indicator.
109131
///
110132
/// **The design system does not allow to have both an error or read only situation and a disabled state for the component.**

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ public struct OUDSCheckboxIndeterminate: View {
105105

106106
// MARK: - Initializers
107107

108+
/// Creates a checkbox with only an indicator.
109+
///
110+
/// **The design system does not allow to have both an error situation and a disabled state for the component.**
111+
///
112+
/// - Parameters:
113+
/// - selection: A binding to a property that determines whether the indicator is ticked, unticked or preticked.
114+
/// - key: The text to vocalize with *Voice Over* the component must have, as as `LocalizedStringKey` for the given `Bundle`
115+
/// - tableName: The name of the `.strings` file, or `nil` for the default
116+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
117+
/// - isError: True if the look and feel of the component must reflect an error state, default set to `false`
118+
/// - isReadOnly: True if the look and feel of the component must reflect a read only state, default set to `false`
119+
public init(selection: Binding<OUDSCheckboxIndicatorState>,
120+
accessibilityLabel key: LocalizedStringKey,
121+
tableName: String? = nil,
122+
bundle: Bundle = .main,
123+
isError: Bool = false,
124+
isReadOnly: Bool = false)
125+
{
126+
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
127+
self.init(selection: selection, accessibilityLabel: resolvedText, isError: isError, isReadOnly: isReadOnly)
128+
}
129+
108130
/// Creates a checkbox with only an indicator.
109131
///
110132
/// **The design system does not allow to have both an error situation and a disabled state for the component.**

OUDS/Core/Components/Sources/Controls/Chip/OUDSFilterChip.swift

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ public struct OUDSFilterChip: View {
6969

7070
// MARK: - Initializers
7171

72+
/// Creates a filter chip with a localized text and icon, looking up the key in the given bundle.
73+
///
74+
/// ```swift
75+
/// OUDSFilterChip(icon: Image("ic_heart"), LocalizedStringKey("like_filter"), bundle: Bundle.module, selected: true) { }
76+
/// ```
77+
///
78+
/// - Parameters:
79+
/// - icon: An image which shoud contains an icon
80+
/// - key: A `LocalizedStringKey` used to look up the text in the given bundle
81+
/// - tableName: The name of the `.strings` file, or `nil` for the default
82+
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
83+
/// - selected: Flag to know if chip is selected, by default is unselected
84+
/// - action: The action to perform when the user triggers the chip
85+
public init(icon: Image,
86+
_ key: LocalizedStringKey,
87+
tableName: String? = nil,
88+
bundle: Bundle = .main,
89+
selected: Bool = false,
90+
action: @escaping () -> Void)
91+
{
92+
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
93+
self.init(icon: icon, text: resolvedText, selected: selected, action: action)
94+
}
95+
7296
/// Creates a filter chip with text and icon.
7397
///
7498
/// - Parameters:
@@ -85,33 +109,24 @@ public struct OUDSFilterChip: View {
85109
self.selected = selected
86110
}
87111

88-
/// Creates a filter chip with a localized text and icon, looking up the key in the given bundle.
89-
///
90-
/// ```swift
91-
/// OUDSFilterChip(icon: Image("ic_heart"), LocalizedStringKey("like_filter"), bundle: Bundle.module, selected: true) { }
92-
/// ```
112+
/// Create a chip with an icon only.
93113
///
94114
/// - Parameters:
95115
/// - icon: An image which shoud contains an icon
96-
/// - key: A `LocalizedStringKey` used to look up the text in the given bundle
116+
/// - key: The text to vocalize with *Voice Over* the component must have, as as `LocalizedStringKey` for the given `Bundle`
97117
/// - tableName: The name of the `.strings` file, or `nil` for the default
98118
/// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
99119
/// - selected: Flag to know if chip is selected, by default is unselected
100120
/// - action: The action to perform when the user triggers the chip
101121
public init(icon: Image,
102-
_ key: LocalizedStringKey,
122+
accessibilityLabel key: LocalizedStringKey,
103123
tableName: String? = nil,
104124
bundle: Bundle = .main,
105125
selected: Bool = false,
106126
action: @escaping () -> Void)
107127
{
108128
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
109-
if resolvedText.isEmpty {
110-
OL.warning("The OUDSFilterChip should not have an empty text, prefer instead OUDSFilterChip(icon:accessibilityLabel:selected:action).")
111-
}
112-
layout = .textAndIcon(text: resolvedText, icon: icon, iconPosition: .trailing)
113-
self.action = action
114-
self.selected = selected
129+
self.init(icon: icon, accessibilityLabel: resolvedText, selected: selected, action: action)
115130
}
116131

117132
/// Create a chip with an icon only.
@@ -130,21 +145,6 @@ public struct OUDSFilterChip: View {
130145
self.selected = selected
131146
}
132147

133-
/// Create a chip with a text only.
134-
///
135-
/// - Parameters:
136-
/// - text: The text of the button to display, must not be empty
137-
/// - selected: Flag to know if chip is selected, by default is unselected
138-
/// - action: The action to perform when the user triggers the chip
139-
public init(text: String, selected: Bool = false, action: @escaping () -> Void) {
140-
if text.isEmpty {
141-
OL.fatal("The OUDSFilterChip must not have an empty text!")
142-
}
143-
layout = .text(text)
144-
self.action = action
145-
self.selected = selected
146-
}
147-
148148
/// Creates a filter chip with a localized text only, looking up the key in the given bundle.
149149
///
150150
/// ```swift
@@ -164,10 +164,20 @@ public struct OUDSFilterChip: View {
164164
action: @escaping () -> Void)
165165
{
166166
let resolvedText = key.resolved(tableName: tableName, bundle: bundle)
167-
if resolvedText.isEmpty {
167+
self.init(text: resolvedText, selected: selected, action: action)
168+
}
169+
170+
/// Create a chip with a text only.
171+
///
172+
/// - Parameters:
173+
/// - text: The text of the button to display, must not be empty
174+
/// - selected: Flag to know if chip is selected, by default is unselected
175+
/// - action: The action to perform when the user triggers the chip
176+
public init(text: String, selected: Bool = false, action: @escaping () -> Void) {
177+
if text.isEmpty {
168178
OL.fatal("The OUDSFilterChip must not have an empty text!")
169179
}
170-
layout = .text(resolvedText)
180+
layout = .text(text)
171181
self.action = action
172182
self.selected = selected
173183
}

0 commit comments

Comments
 (0)