Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ fun FunctionCall.Builder.colorArgument(name: String, color: Color) {

fun FunctionCall.Builder.stringArgument(name: String, @StringRes id: Int) = formattableArgument(name) { "\"${it.getString(id)}\"" }

fun FunctionCall.Builder.constrainedMaxWidthArgument(value: Boolean) = typedArgument(Argument.ConstrainedMaxWidth, value)

fun FunctionCall.Builder.contentDescriptionArgument(@StringRes id: Int) = stringArgument(Argument.ContentDescription, id)
fun FunctionCall.Builder.contentDescriptionArgument(@StringRes id: Int, vararg formatArgs: Any) =
stringResourceArgument(Argument.ContentDescription, id, *formatArgs)
Expand All @@ -70,6 +72,7 @@ fun FunctionCall.Builder.readOnlyArgument(value: Boolean) = typedArgument(Argume
private object Argument {

const val Color = "color"
const val ConstrainedMaxWidth = "constrainedMaxWidth"
const val ContentDescription = "contentDescription"
const val Content = "content"
const val Enabled = "enabled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ private fun CheckboxItemDemoContent(state: CheckboxItemDemoState) {
reversed = reversed,
enabled = enabled,
readOnly = readOnly,
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null,
constrainedMaxWidth = constrainedMaxWidth
)
}
}
Expand Down Expand Up @@ -112,7 +113,8 @@ private fun IndeterminateCheckboxItemDemoContent(state: CheckboxItemDemoState) {
reversed = reversed,
enabled = enabled,
readOnly = readOnly,
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null,
constrainedMaxWidth = constrainedMaxWidth
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ fun rememberCheckboxItemDemoState(
error: Boolean = false,
errorMessage: String = stringResource(id = R.string.app_components_common_errorMessage_label),
label: String = stringResource(id = R.string.app_components_common_label_label),
description: String? = null
description: String? = null,
constrainedMaxWidth: Boolean = false
) = rememberSaveable(
checkedValues,
toggleableStateValues,
Expand All @@ -53,9 +54,24 @@ fun rememberCheckboxItemDemoState(
errorMessage,
label,
description,
constrainedMaxWidth,
saver = CheckboxItemDemoState.Saver
) {
CheckboxItemDemoState(checkedValues, toggleableStateValues, icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, label, description)
CheckboxItemDemoState(
checkedValues,
toggleableStateValues,
icon,
edgeToEdge,
divider,
reversed,
enabled,
readOnly,
error,
errorMessage,
label,
description,
constrainedMaxWidth
)
}

class CheckboxItemDemoState(
Expand All @@ -70,8 +86,9 @@ class CheckboxItemDemoState(
error: Boolean,
errorMessage: String,
label: String,
description: String?
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, label, description) {
description: String?,
constrainedMaxWidth: Boolean
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, label, description, constrainedMaxWidth) {

companion object {
val Saver = listSaver(
Expand All @@ -98,7 +115,8 @@ class CheckboxItemDemoState(
error,
errorMessage,
label,
description
description,
constrainedMaxWidth
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package com.orange.ouds.app.ui.components.controlitem
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.orange.ouds.app.R
import com.orange.ouds.app.ui.components.constrainedMaxWidthArgument
import com.orange.ouds.app.ui.components.enabledArgument
import com.orange.ouds.app.ui.components.labelArgument
import com.orange.ouds.app.ui.components.painterArgument
Expand Down Expand Up @@ -42,7 +43,8 @@ fun ControlItemCustomizations(state: ControlItemDemoState, extraCustomizations:
{ ControlItemErrorCustomization(state = state) },
{ ControlItemErrorMessageCustomization(state = state) },
{ ControlItemLabelCustomization(state = state) },
{ ControlItemDescriptionCustomization(state = state) }
{ ControlItemDescriptionCustomization(state = state) },
{ ControlItemConstrainedMaxWidthCustomization(state = state) }
)
extraCustomizations.forEach { (index, content) ->
customizations.add(minOf(index, customizations.count()), content)
Expand Down Expand Up @@ -168,6 +170,17 @@ private fun ControlItemDescriptionCustomization(state: ControlItemDemoState) {
}
}

@Composable
private fun ControlItemConstrainedMaxWidthCustomization(state: ControlItemDemoState) {
with(state) {
CustomizationSwitchItem(
label = stringResource(R.string.app_components_common_constrainedMaxWidth_label),
checked = constrainedMaxWidth,
onCheckedChange = { constrainedMaxWidth = it },
)
}
}

fun FunctionCall.Builder.controlItemArguments(state: ControlItemDemoState, themeDrawableResources: ThemeDrawableResources, hasErrorMessage: Boolean = false) =
with(state) {
labelArgument(label)
Expand All @@ -187,4 +200,5 @@ fun FunctionCall.Builder.controlItemArguments(state: ControlItemDemoState, theme
typedArgument("message", if (hasErrorMessage) errorMessage else "")
}
}
if (constrainedMaxWidth) constrainedMaxWidthArgument(constrainedMaxWidth)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ open class ControlItemDemoState(
error: Boolean,
errorMessage: String,
label: String,
description: String?
description: String?,
constrainedMaxWidth: Boolean
) {

companion object {
Expand All @@ -45,7 +46,8 @@ open class ControlItemDemoState(
error,
errorMessage,
label,
description
description,
constrainedMaxWidth
)
}
},
Expand All @@ -59,14 +61,16 @@ open class ControlItemDemoState(
list[5] as Boolean,
list[6] as Boolean,
list[7] as String,
list[7] as String,
list[8] as String?
list[8] as String,
list[9] as String?,
list[10] as Boolean
)
}
)
}

var icon: Boolean by mutableStateOf(icon)
var constrainedMaxWidth: Boolean by mutableStateOf(constrainedMaxWidth)
var edgeToEdge: Boolean by mutableStateOf(edgeToEdge)
var divider: Boolean by mutableStateOf(divider)
var reversed: Boolean by mutableStateOf(reversed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ private fun RadioButtonItemDemoContent(state: RadioButtonItemDemoState) {
reversed = reversed,
enabled = enabled,
readOnly = readOnly,
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null,
constrainedMaxWidth = constrainedMaxWidth
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ fun rememberRadioButtonItemDemoState(
errorMessage: String = stringResource(id = R.string.app_components_common_errorMessage_label),
label: String = stringResource(id = R.string.app_components_common_label_label),
extraLabel: String? = null,
description: String? = null
description: String? = null,
constrainedMaxWidth: Boolean = false
) = rememberSaveable(
selectedValue,
icon,
Expand All @@ -52,9 +53,25 @@ fun rememberRadioButtonItemDemoState(
label,
extraLabel,
description,
constrainedMaxWidth,
saver = RadioButtonItemDemoState.Saver
) {
RadioButtonItemDemoState(selectedValue, icon, edgeToEdge, divider, outlined, reversed, enabled, readOnly, error, errorMessage, label, extraLabel, description)
RadioButtonItemDemoState(
selectedValue,
icon,
edgeToEdge,
divider,
outlined,
reversed,
enabled,
readOnly,
error,
errorMessage,
label,
extraLabel,
description,
constrainedMaxWidth
)
}

class RadioButtonItemDemoState(
Expand All @@ -70,8 +87,9 @@ class RadioButtonItemDemoState(
errorMessage: String,
label: String,
extraLabel: String?,
description: String?
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, label, description) {
description: String?,
constrainedMaxWidth: Boolean,
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, label, description, constrainedMaxWidth) {

companion object {
val values = listOf(1, 2)
Expand Down Expand Up @@ -102,7 +120,8 @@ class RadioButtonItemDemoState(
errorMessage,
label,
list[2] as String?,
description
description,
constrainedMaxWidth
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ private fun SwitchItemDemoContent(state: SwitchItemDemoState) {
reversed = reversed,
enabled = enabled,
readOnly = readOnly,
error = if (error) OudsError(errorMessage) else null
error = if (error) OudsError(errorMessage) else null,
constrainedMaxWidth = constrainedMaxWidth
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,24 @@ fun rememberSwitchItemDemoState(
error: Boolean = false,
errorMessage: String = stringResource(id = R.string.app_components_common_errorMessage_label),
text: String = stringResource(id = R.string.app_components_common_label_label),
description: String? = null
) = rememberSaveable(checked, icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, text, description, saver = SwitchItemDemoState.Saver) {
SwitchItemDemoState(checked, icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, text, description)
description: String? = null,
constrainedMaxWidth: Boolean = false
) = rememberSaveable(
checked,
icon,
edgeToEdge,
divider,
reversed,
enabled,
readOnly,
error,
errorMessage,
text,
description,
constrainedMaxWidth,
saver = SwitchItemDemoState.Saver
) {
SwitchItemDemoState(checked, icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, text, description, constrainedMaxWidth)
}

class SwitchItemDemoState(
Expand All @@ -50,8 +65,9 @@ class SwitchItemDemoState(
error: Boolean,
errorMessage: String,
text: String,
description: String?
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, text, description) {
description: String?,
constrainedMaxWidth: Boolean
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, text, description, constrainedMaxWidth) {

companion object {

Expand All @@ -76,7 +92,8 @@ class SwitchItemDemoState(
error,
errorMessage,
label,
description
description,
constrainedMaxWidth
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.PreviewLightDark
import com.orange.ouds.app.R
import com.orange.ouds.app.ui.components.Component
import com.orange.ouds.app.ui.components.constrainedMaxWidthArgument
import com.orange.ouds.app.ui.components.contentDescriptionArgument
import com.orange.ouds.app.ui.components.enabledArgument
import com.orange.ouds.app.ui.components.onClickArgument
Expand Down Expand Up @@ -136,6 +137,11 @@ private fun TextInputDemoBottomSheetContent(state: TextInputDemoState) {
value = helperLink,
onValueChange = { value -> helperLink = value }
)
CustomizationSwitchItem(
label = stringResource(R.string.app_components_common_constrainedMaxWidth_label),
checked = constrainedMaxWidth,
onCheckedChange = { constrainedMaxWidth = it },
)
}
}

Expand Down Expand Up @@ -171,7 +177,8 @@ private fun TextInputDemoContent(state: TextInputDemoState) {
prefix = prefix,
suffix = suffix,
helperText = helperText,
helperLink = if (helperLink.isNotEmpty()) OudsTextInputHelperLink(text = helperLink, onClick = { }) else null
helperLink = if (helperLink.isNotEmpty()) OudsTextInputHelperLink(text = helperLink, onClick = { }) else null,
constrainedMaxWidth = constrainedMaxWidth
)
}
}
Expand Down Expand Up @@ -223,6 +230,7 @@ private fun Code.Builder.textInputDemoCodeSnippet(state: TextInputDemoState, the
}
}
}
if (constrainedMaxWidth) constrainedMaxWidthArgument(true)
}
}
}
Expand Down
Loading