Skip to content

Commit dea6fb9

Browse files
authored
feat: add fluent wrapper for UIContentUnavailableConfiguration (#52)
1 parent 9a4ebf1 commit dea6fb9

1 file changed

Lines changed: 252 additions & 0 deletions

File tree

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
//
2+
// flex-ui
3+
// Copyright © 2026 Space Code. All rights reserved.
4+
//
5+
6+
import UIKit
7+
8+
// MARK: - UIContentUnavailableConfiguration + FlexCompatible
9+
10+
@available(iOS 17.0, *)
11+
extension UIContentUnavailableConfiguration: FlexCompatible {}
12+
13+
@available(iOS 17.0, *)
14+
public extension FlexUI where Component == UIContentUnavailableConfiguration {
15+
/// Sets the image for the content unavailable configuration.
16+
///
17+
/// - Parameter image: The image to display.
18+
/// - Returns: The current instance of `FlexUI` for further configuration.
19+
@discardableResult
20+
func image(_ image: UIImage?) -> FlexUI<UIContentUnavailableConfiguration> {
21+
var config = component
22+
config.image = image
23+
return FlexUI(component: config)
24+
}
25+
26+
/// Sets the image properties using a closure.
27+
///
28+
/// - Parameter configure: A closure to configure image properties.
29+
/// - Returns: The current instance of `FlexUI` for further configuration.
30+
@discardableResult
31+
func imageProperties(_ configure: (inout UIContentUnavailableConfiguration.ImageProperties) -> Void)
32+
-> FlexUI<UIContentUnavailableConfiguration>
33+
{
34+
var config = component
35+
configure(&config.imageProperties)
36+
return FlexUI(component: config)
37+
}
38+
39+
/// Sets the primary text for the content unavailable configuration.
40+
///
41+
/// - Parameter text: The primary text to display.
42+
/// - Returns: The current instance of `FlexUI` for further configuration.
43+
@discardableResult
44+
func text(_ text: String?) -> FlexUI<UIContentUnavailableConfiguration> {
45+
var config = component
46+
config.text = text
47+
return FlexUI(component: config)
48+
}
49+
50+
/// Sets the attributed primary text for the content unavailable configuration.
51+
///
52+
/// - Parameter attributedText: The attributed text to display.
53+
/// - Returns: The current instance of `FlexUI` for further configuration.
54+
@discardableResult
55+
func attributedText(_ attributedText: NSAttributedString?) -> FlexUI<UIContentUnavailableConfiguration> {
56+
var config = component
57+
config.attributedText = attributedText
58+
return FlexUI(component: config)
59+
}
60+
61+
/// Sets the text properties using a closure.
62+
///
63+
/// - Parameter configure: A closure to configure text properties.
64+
/// - Returns: The current instance of `FlexUI` for further configuration.
65+
@discardableResult
66+
func textProperties(_ configure: (inout UIContentUnavailableConfiguration.TextProperties) -> Void)
67+
-> FlexUI<UIContentUnavailableConfiguration>
68+
{
69+
var config = component
70+
configure(&config.textProperties)
71+
return FlexUI(component: config)
72+
}
73+
74+
/// Sets the secondary text for the content unavailable configuration.
75+
///
76+
/// - Parameter secondaryText: The secondary text to display.
77+
/// - Returns: The current instance of `FlexUI` for further configuration.
78+
@discardableResult
79+
func secondaryText(_ secondaryText: String?) -> FlexUI<UIContentUnavailableConfiguration> {
80+
var config = component
81+
config.secondaryText = secondaryText
82+
return FlexUI(component: config)
83+
}
84+
85+
/// Sets the attributed secondary text for the content unavailable configuration.
86+
///
87+
/// - Parameter attributedText: The attributed secondary text to display.
88+
/// - Returns: The current instance of `FlexUI` for further configuration.
89+
@discardableResult
90+
func secondaryAttributedText(_ attributedText: NSAttributedString?) -> FlexUI<UIContentUnavailableConfiguration> {
91+
var config = component
92+
config.secondaryAttributedText = attributedText
93+
return FlexUI(component: config)
94+
}
95+
96+
/// Sets the secondary text properties using a closure.
97+
///
98+
/// - Parameter configure: A closure to configure secondary text properties.
99+
/// - Returns: The current instance of `FlexUI` for further configuration.
100+
@discardableResult
101+
func secondaryTextProperties(_ configure: (inout UIContentUnavailableConfiguration.TextProperties) -> Void)
102+
-> FlexUI<UIContentUnavailableConfiguration>
103+
{
104+
var config = component
105+
configure(&config.secondaryTextProperties)
106+
return FlexUI(component: config)
107+
}
108+
109+
/// Sets the button configuration.
110+
///
111+
/// - Parameter buttonConfiguration: The button configuration to use.
112+
/// - Returns: The current instance of `FlexUI` for further configuration.
113+
@discardableResult
114+
func button(_ buttonConfiguration: UIButton.Configuration) -> FlexUI<UIContentUnavailableConfiguration> {
115+
var config = component
116+
config.button = buttonConfiguration
117+
return FlexUI(component: config)
118+
}
119+
120+
/// Sets the button properties using a closure.
121+
///
122+
/// - Parameter configure: A closure to configure button properties.
123+
/// - Returns: The current instance of `FlexUI` for further configuration.
124+
@discardableResult
125+
func buttonProperties(_ configure: (inout UIContentUnavailableConfiguration.ButtonProperties) -> Void)
126+
-> FlexUI<UIContentUnavailableConfiguration>
127+
{
128+
var config = component
129+
configure(&config.buttonProperties)
130+
return FlexUI(component: config)
131+
}
132+
133+
/// Sets the secondary button configuration.
134+
///
135+
/// - Parameter buttonConfiguration: The secondary button configuration to use.
136+
/// - Returns: The current instance of `FlexUI` for further configuration.
137+
@discardableResult
138+
func secondaryButton(_ buttonConfiguration: UIButton.Configuration) -> FlexUI<UIContentUnavailableConfiguration> {
139+
var config = component
140+
config.secondaryButton = buttonConfiguration
141+
return FlexUI(component: config)
142+
}
143+
144+
/// Sets the secondary button properties using a closure.
145+
///
146+
/// - Parameter configure: A closure to configure secondary button properties.
147+
/// - Returns: The current instance of `FlexUI` for further configuration.
148+
@discardableResult
149+
func secondaryButtonProperties(_ configure: (inout UIContentUnavailableConfiguration.ButtonProperties) -> Void)
150+
-> FlexUI<UIContentUnavailableConfiguration>
151+
{
152+
var config = component
153+
configure(&config.secondaryButtonProperties)
154+
return FlexUI(component: config)
155+
}
156+
157+
// MARK: - Alignment Configuration
158+
159+
/// Sets the alignment of the content.
160+
///
161+
/// - Parameter alignment: The alignment to use.
162+
/// - Returns: The current instance of `FlexUI` for further configuration.
163+
@available(iOS 17.0, *)
164+
@discardableResult
165+
func alignment(_ alignment: UIContentUnavailableConfiguration.Alignment) -> FlexUI<UIContentUnavailableConfiguration> {
166+
var config = component
167+
config.alignment = alignment
168+
return FlexUI(component: config)
169+
}
170+
171+
/// Sets the background configuration.
172+
///
173+
/// - Parameter background: The background configuration to use.
174+
/// - Returns: The current instance of `FlexUI` for further configuration.
175+
@discardableResult
176+
func background(_ background: UIBackgroundConfiguration) -> FlexUI<UIContentUnavailableConfiguration> {
177+
var config = component
178+
config.background = background
179+
return FlexUI(component: config)
180+
}
181+
182+
/// Sets the directional layout margins.
183+
///
184+
/// - Parameter margins: The margins to apply.
185+
/// - Returns: The current instance of `FlexUI` for further configuration.
186+
@discardableResult
187+
func directionalLayoutMargins(_ margins: NSDirectionalEdgeInsets) -> FlexUI<UIContentUnavailableConfiguration> {
188+
var config = component
189+
config.directionalLayoutMargins = margins
190+
return FlexUI(component: config)
191+
}
192+
193+
/// Sets uniform margins for all edges.
194+
///
195+
/// - Parameter margin: The margin value to apply to all edges.
196+
/// - Returns: The current instance of `FlexUI` for further configuration.
197+
@discardableResult
198+
func margins(_ margin: CGFloat) -> FlexUI<UIContentUnavailableConfiguration> {
199+
var config = component
200+
config.directionalLayoutMargins = NSDirectionalEdgeInsets(
201+
top: margin,
202+
leading: margin,
203+
bottom: margin,
204+
trailing: margin
205+
)
206+
return FlexUI(component: config)
207+
}
208+
209+
/// Sets the padding between the image and text.
210+
///
211+
/// - Parameter padding: The padding value.
212+
/// - Returns: The current instance of `FlexUI` for further configuration.
213+
@discardableResult
214+
func imageToTextPadding(_ padding: CGFloat) -> FlexUI<UIContentUnavailableConfiguration> {
215+
var config = component
216+
config.imageToTextPadding = padding
217+
return FlexUI(component: config)
218+
}
219+
220+
/// Sets the padding between text and secondary text.
221+
///
222+
/// - Parameter padding: The padding value.
223+
/// - Returns: The current instance of `FlexUI` for further configuration.
224+
@discardableResult
225+
func textToSecondaryTextPadding(_ padding: CGFloat) -> FlexUI<UIContentUnavailableConfiguration> {
226+
var config = component
227+
config.textToSecondaryTextPadding = padding
228+
return FlexUI(component: config)
229+
}
230+
231+
/// Sets the padding between text and button.
232+
///
233+
/// - Parameter padding: The padding value.
234+
/// - Returns: The current instance of `FlexUI` for further configuration.
235+
@discardableResult
236+
func textToButtonPadding(_ padding: CGFloat) -> FlexUI<UIContentUnavailableConfiguration> {
237+
var config = component
238+
config.textToButtonPadding = padding
239+
return FlexUI(component: config)
240+
}
241+
242+
/// Sets the padding between buttons.
243+
///
244+
/// - Parameter padding: The padding value.
245+
/// - Returns: The current instance of `FlexUI` for further configuration.
246+
@discardableResult
247+
func buttonToSecondaryButtonPadding(_ padding: CGFloat) -> FlexUI<UIContentUnavailableConfiguration> {
248+
var config = component
249+
config.buttonToSecondaryButtonPadding = padding
250+
return FlexUI(component: config)
251+
}
252+
}

0 commit comments

Comments
 (0)