@@ -30,6 +30,8 @@ import com.orange.ouds.app.ui.utilities.composable.CustomizationSwitchItem
3030import com.orange.ouds.app.ui.utilities.composable.CustomizationTextInput
3131import com.orange.ouds.app.ui.utilities.rememberUntintedIconPainter
3232import com.orange.ouds.core.component.OudsControlItemIcon
33+ import com.orange.ouds.core.component.common.OudsError
34+ import com.orange.ouds.core.component.common.text.OudsAnnotatedErrorMessage
3335
3436data class ControlItemCustomization (val index : Int , val content : @Composable () -> Unit )
3537
@@ -48,7 +50,8 @@ fun ControlItemCustomizations(state: ControlItemDemoState, extraCustomizations:
4850 { ControlItemErrorMessageCustomization (state = state) },
4951 { ControlItemLabelCustomization (state = state) },
5052 { ControlItemDescriptionCustomization (state = state) },
51- { ControlItemConstrainedMaxWidthCustomization (state = state) }
53+ { ControlItemConstrainedMaxWidthCustomization (state = state) },
54+ { ControlItemAnnotatedTextCustomization (state = state) }
5255 )
5356 extraCustomizations.forEach { (index, content) ->
5457 customizations.add(minOf(index, customizations.count()), content)
@@ -61,8 +64,8 @@ private fun ControlItemIconCustomization(state: ControlItemDemoState) {
6164 with (state) {
6265 CustomizationFilterChips (
6366 applyTopPadding = false ,
64- label = stringResource(R .string.app_components_common_icon_tech),
65- chipLabels = ControlItemDemoState .Icon .entries.map { stringResource(it.labelRes) },
67+ label = stringResource(id = R .string.app_components_common_icon_tech),
68+ chipLabels = ControlItemDemoState .Icon .entries.map { stringResource(id = it.labelRes) },
6669 selectedChipIndex = ControlItemDemoState .Icon .entries.indexOf(icon),
6770 onSelectionChange = { index -> icon = ControlItemDemoState .Icon .entries[index] }
6871 )
@@ -73,7 +76,7 @@ private fun ControlItemIconCustomization(state: ControlItemDemoState) {
7376private fun ControlItemEdgeToEdgeCustomization (state : ControlItemDemoState ) {
7477 with (state) {
7578 CustomizationSwitchItem (
76- label = stringResource(R .string.app_components_controlItem_edgeToEdge_tech),
79+ label = stringResource(id = R .string.app_components_controlItem_edgeToEdge_tech),
7780 checked = edgeToEdge,
7881 onCheckedChange = { edgeToEdge = it },
7982 )
@@ -85,7 +88,7 @@ private fun ControlItemEdgeToEdgeCustomization(state: ControlItemDemoState) {
8588private fun ControlItemDividerCustomization (state : ControlItemDemoState ) {
8689 with (state) {
8790 CustomizationSwitchItem (
88- label = stringResource(R .string.app_components_controlItem_divider_tech),
91+ label = stringResource(id = R .string.app_components_controlItem_divider_tech),
8992 checked = divider,
9093 onCheckedChange = { divider = it },
9194 )
@@ -96,7 +99,7 @@ private fun ControlItemDividerCustomization(state: ControlItemDemoState) {
9699private fun ControlItemReversedCustomization (state : ControlItemDemoState ) {
97100 with (state) {
98101 CustomizationSwitchItem (
99- label = stringResource(R .string.app_components_controlItem_reversed_tech),
102+ label = stringResource(id = R .string.app_components_controlItem_reversed_tech),
100103 checked = reversed,
101104 onCheckedChange = { reversed = it },
102105 )
@@ -107,7 +110,7 @@ private fun ControlItemReversedCustomization(state: ControlItemDemoState) {
107110private fun ControlItemEnabledCustomization (state : ControlItemDemoState ) {
108111 with (state) {
109112 CustomizationSwitchItem (
110- label = stringResource(R .string.app_common_enabled_tech),
113+ label = stringResource(id = R .string.app_common_enabled_tech),
111114 checked = enabled,
112115 onCheckedChange = { enabled = it },
113116 enabled = enabledSwitchEnabled
@@ -119,7 +122,7 @@ private fun ControlItemEnabledCustomization(state: ControlItemDemoState) {
119122private fun ControlItemReadOnlyCustomization (state : ControlItemDemoState ) {
120123 with (state) {
121124 CustomizationSwitchItem (
122- label = stringResource(R .string.app_components_common_readOnly_tech),
125+ label = stringResource(id = R .string.app_components_common_readOnly_tech),
123126 checked = readOnly,
124127 onCheckedChange = { readOnly = it },
125128 enabled = readOnlySwitchEnabled
@@ -131,7 +134,7 @@ private fun ControlItemReadOnlyCustomization(state: ControlItemDemoState) {
131134private fun ControlItemErrorCustomization (state : ControlItemDemoState ) {
132135 with (state) {
133136 CustomizationSwitchItem (
134- label = stringResource(R .string.app_components_common_error_tech),
137+ label = stringResource(id = R .string.app_components_common_error_tech),
135138 checked = error,
136139 onCheckedChange = { error = it },
137140 enabled = errorSwitchEnabled
@@ -144,10 +147,22 @@ private fun ControlItemErrorMessageCustomization(state: ControlItemDemoState) {
144147 with (state) {
145148 CustomizationTextInput (
146149 applyTopPadding = true ,
147- label = stringResource(R .string.app_components_common_errorMessage_tech),
150+ label = stringResource(id = R .string.app_components_common_errorMessage_tech),
148151 value = errorMessage,
149152 onValueChange = { value -> errorMessage = value },
150- enabled = errorMessageTextInputEnabled
153+ enabled = errorMessageTextInputEnabled,
154+ helperText = stringResource(id = R .string.app_components_common_annotatedTextHelperText_tech)
155+ )
156+ }
157+ }
158+
159+ @Composable
160+ fun ControlItemAnnotatedTextCustomization (state : ControlItemDemoState ) {
161+ with (state) {
162+ CustomizationSwitchItem (
163+ label = stringResource(id = R .string.app_components_common_annotatedText_tech),
164+ checked = annotatedText,
165+ onCheckedChange = { annotatedText = it }
151166 )
152167 }
153168}
@@ -157,7 +172,7 @@ private fun ControlItemLabelCustomization(state: ControlItemDemoState) {
157172 with (state) {
158173 CustomizationTextInput (
159174 applyTopPadding = true ,
160- label = stringResource(R .string.app_components_common_label_tech),
175+ label = stringResource(id = R .string.app_components_common_label_tech),
161176 value = label,
162177 onValueChange = { value -> label = value }
163178 )
@@ -169,7 +184,7 @@ private fun ControlItemDescriptionCustomization(state: ControlItemDemoState) {
169184 with (state) {
170185 CustomizationTextInput (
171186 applyTopPadding = true ,
172- label = stringResource(R .string.app_components_common_description_tech),
187+ label = stringResource(id = R .string.app_components_common_description_tech),
173188 value = description.orEmpty(),
174189 onValueChange = { value -> description = value }
175190 )
@@ -180,22 +195,34 @@ private fun ControlItemDescriptionCustomization(state: ControlItemDemoState) {
180195private fun ControlItemConstrainedMaxWidthCustomization (state : ControlItemDemoState ) {
181196 with (state) {
182197 CustomizationSwitchItem (
183- label = stringResource(R .string.app_components_common_constrainedMaxWidth_tech),
198+ label = stringResource(id = R .string.app_components_common_constrainedMaxWidth_tech),
184199 checked = constrainedMaxWidth,
185200 onCheckedChange = { constrainedMaxWidth = it },
186201 )
187202 }
188203}
189204
190205@Composable
191- fun getControlItemIcon (state : ControlItemDemoState ): OudsControlItemIcon ? {
206+ fun controlItemIcon (state : ControlItemDemoState ): OudsControlItemIcon ? {
192207 return when (state.icon) {
193208 ControlItemDemoState .Icon .None -> null
194209 ControlItemDemoState .Icon .Tinted -> OudsControlItemIcon (painter = painterResource(id = LocalThemeDrawableResources .current.tipsAndTricks))
195210 ControlItemDemoState .Icon .Untinted -> OudsControlItemIcon (painter = rememberUntintedIconPainter(), tinted = false )
196211 }
197212}
198213
214+ @Composable
215+ fun controlItemError (state : ControlItemDemoState , isLastItem : Boolean , annotatedMessage : OudsAnnotatedErrorMessage ): OudsError ? {
216+ return with (state) {
217+ when {
218+ error && ! isLastItem -> OudsError (" " )
219+ error && ! annotatedText -> OudsError (errorMessage)
220+ error && annotatedText -> OudsError (annotatedMessage)
221+ else -> null
222+ }
223+ }
224+ }
225+
199226fun FunctionCall.Builder.controlItemArguments (state : ControlItemDemoState , themeDrawableResources : ThemeDrawableResources , hasErrorMessage : Boolean = false) =
200227 with (state) {
201228 labelArgument(label)
@@ -208,6 +235,6 @@ fun FunctionCall.Builder.controlItemArguments(state: ControlItemDemoState, theme
208235 if (reversed) typedArgument(" reversed" , reversed)
209236 if (! enabled) enabledArgument(enabled)
210237 if (readOnly) readOnlyArgument(readOnly)
211- if (error) errorArgument(if (hasErrorMessage) errorMessage else " " )
238+ if (error) errorArgument(if (hasErrorMessage) errorMessage else " " , hasErrorMessage && annotatedText )
212239 if (constrainedMaxWidth) constrainedMaxWidthArgument(constrainedMaxWidth)
213240 }
0 commit comments