Skip to content

Commit c6b08cb

Browse files
authored
feat(checkbox-item,radio-button-item,switch-item,text-input): add a constrained max width parameter to these components (#985)
1 parent edba5b0 commit c6b08cb

File tree

46 files changed

+378
-38
lines changed

Some content is hidden

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

46 files changed

+378
-38
lines changed

app/src/main/java/com/orange/ouds/app/ui/components/ComponentCode.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ fun FunctionCall.Builder.colorArgument(name: String, color: Color) {
4848

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

51+
fun FunctionCall.Builder.constrainedMaxWidthArgument(value: Boolean) = typedArgument(Argument.ConstrainedMaxWidth, value)
52+
5153
fun FunctionCall.Builder.contentDescriptionArgument(@StringRes id: Int) = stringArgument(Argument.ContentDescription, id)
5254
fun FunctionCall.Builder.contentDescriptionArgument(@StringRes id: Int, vararg formatArgs: Any) =
5355
stringResourceArgument(Argument.ContentDescription, id, *formatArgs)
@@ -70,6 +72,7 @@ fun FunctionCall.Builder.readOnlyArgument(value: Boolean) = typedArgument(Argume
7072
private object Argument {
7173

7274
const val Color = "color"
75+
const val ConstrainedMaxWidth = "constrainedMaxWidth"
7376
const val ContentDescription = "contentDescription"
7477
const val Content = "content"
7578
const val Enabled = "enabled"

app/src/main/java/com/orange/ouds/app/ui/components/checkbox/CheckboxItemDemoScreen.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ private fun CheckboxItemDemoContent(state: CheckboxItemDemoState) {
7878
reversed = reversed,
7979
enabled = enabled,
8080
readOnly = readOnly,
81-
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null
81+
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null,
82+
constrainedMaxWidth = constrainedMaxWidth
8283
)
8384
}
8485
}
@@ -112,7 +113,8 @@ private fun IndeterminateCheckboxItemDemoContent(state: CheckboxItemDemoState) {
112113
reversed = reversed,
113114
enabled = enabled,
114115
readOnly = readOnly,
115-
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null
116+
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null,
117+
constrainedMaxWidth = constrainedMaxWidth
116118
)
117119
}
118120
}

app/src/main/java/com/orange/ouds/app/ui/components/checkbox/CheckboxItemDemoState.kt

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ fun rememberCheckboxItemDemoState(
3939
error: Boolean = false,
4040
errorMessage: String = stringResource(id = R.string.app_components_common_errorMessage_label),
4141
label: String = stringResource(id = R.string.app_components_common_label_label),
42-
description: String? = null
42+
description: String? = null,
43+
constrainedMaxWidth: Boolean = false
4344
) = rememberSaveable(
4445
checkedValues,
4546
toggleableStateValues,
@@ -53,9 +54,24 @@ fun rememberCheckboxItemDemoState(
5354
errorMessage,
5455
label,
5556
description,
57+
constrainedMaxWidth,
5658
saver = CheckboxItemDemoState.Saver
5759
) {
58-
CheckboxItemDemoState(checkedValues, toggleableStateValues, icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, label, description)
60+
CheckboxItemDemoState(
61+
checkedValues,
62+
toggleableStateValues,
63+
icon,
64+
edgeToEdge,
65+
divider,
66+
reversed,
67+
enabled,
68+
readOnly,
69+
error,
70+
errorMessage,
71+
label,
72+
description,
73+
constrainedMaxWidth
74+
)
5975
}
6076

6177
class CheckboxItemDemoState(
@@ -70,8 +86,9 @@ class CheckboxItemDemoState(
7086
error: Boolean,
7187
errorMessage: String,
7288
label: String,
73-
description: String?
74-
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, label, description) {
89+
description: String?,
90+
constrainedMaxWidth: Boolean
91+
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, label, description, constrainedMaxWidth) {
7592

7693
companion object {
7794
val Saver = listSaver(
@@ -98,7 +115,8 @@ class CheckboxItemDemoState(
98115
error,
99116
errorMessage,
100117
label,
101-
description
118+
description,
119+
constrainedMaxWidth
102120
)
103121
}
104122
}

app/src/main/java/com/orange/ouds/app/ui/components/controlitem/ControlItemDemoScreen.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package com.orange.ouds.app.ui.components.controlitem
1515
import androidx.compose.runtime.Composable
1616
import androidx.compose.ui.res.stringResource
1717
import com.orange.ouds.app.R
18+
import com.orange.ouds.app.ui.components.constrainedMaxWidthArgument
1819
import com.orange.ouds.app.ui.components.enabledArgument
1920
import com.orange.ouds.app.ui.components.labelArgument
2021
import com.orange.ouds.app.ui.components.painterArgument
@@ -42,7 +43,8 @@ fun ControlItemCustomizations(state: ControlItemDemoState, extraCustomizations:
4243
{ ControlItemErrorCustomization(state = state) },
4344
{ ControlItemErrorMessageCustomization(state = state) },
4445
{ ControlItemLabelCustomization(state = state) },
45-
{ ControlItemDescriptionCustomization(state = state) }
46+
{ ControlItemDescriptionCustomization(state = state) },
47+
{ ControlItemConstrainedMaxWidthCustomization(state = state) }
4648
)
4749
extraCustomizations.forEach { (index, content) ->
4850
customizations.add(minOf(index, customizations.count()), content)
@@ -168,6 +170,17 @@ private fun ControlItemDescriptionCustomization(state: ControlItemDemoState) {
168170
}
169171
}
170172

173+
@Composable
174+
private fun ControlItemConstrainedMaxWidthCustomization(state: ControlItemDemoState) {
175+
with(state) {
176+
CustomizationSwitchItem(
177+
label = stringResource(R.string.app_components_common_constrainedMaxWidth_label),
178+
checked = constrainedMaxWidth,
179+
onCheckedChange = { constrainedMaxWidth = it },
180+
)
181+
}
182+
}
183+
171184
fun FunctionCall.Builder.controlItemArguments(state: ControlItemDemoState, themeDrawableResources: ThemeDrawableResources, hasErrorMessage: Boolean = false) =
172185
with(state) {
173186
labelArgument(label)
@@ -187,4 +200,5 @@ fun FunctionCall.Builder.controlItemArguments(state: ControlItemDemoState, theme
187200
typedArgument("message", if (hasErrorMessage) errorMessage else "")
188201
}
189202
}
203+
if (constrainedMaxWidth) constrainedMaxWidthArgument(constrainedMaxWidth)
190204
}

app/src/main/java/com/orange/ouds/app/ui/components/controlitem/ControlItemDemoState.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ open class ControlItemDemoState(
2727
error: Boolean,
2828
errorMessage: String,
2929
label: String,
30-
description: String?
30+
description: String?,
31+
constrainedMaxWidth: Boolean
3132
) {
3233

3334
companion object {
@@ -45,7 +46,8 @@ open class ControlItemDemoState(
4546
error,
4647
errorMessage,
4748
label,
48-
description
49+
description,
50+
constrainedMaxWidth
4951
)
5052
}
5153
},
@@ -59,14 +61,16 @@ open class ControlItemDemoState(
5961
list[5] as Boolean,
6062
list[6] as Boolean,
6163
list[7] as String,
62-
list[7] as String,
63-
list[8] as String?
64+
list[8] as String,
65+
list[9] as String?,
66+
list[10] as Boolean
6467
)
6568
}
6669
)
6770
}
6871

6972
var icon: Boolean by mutableStateOf(icon)
73+
var constrainedMaxWidth: Boolean by mutableStateOf(constrainedMaxWidth)
7074
var edgeToEdge: Boolean by mutableStateOf(edgeToEdge)
7175
var divider: Boolean by mutableStateOf(divider)
7276
var reversed: Boolean by mutableStateOf(reversed)

app/src/main/java/com/orange/ouds/app/ui/components/radiobutton/RadioButtonItemDemoScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ private fun RadioButtonItemDemoContent(state: RadioButtonItemDemoState) {
101101
reversed = reversed,
102102
enabled = enabled,
103103
readOnly = readOnly,
104-
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null
104+
error = if (error) OudsError(if (isLastItem) errorMessage else "") else null,
105+
constrainedMaxWidth = constrainedMaxWidth
105106
)
106107
}
107108
}

app/src/main/java/com/orange/ouds/app/ui/components/radiobutton/RadioButtonItemDemoState.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ fun rememberRadioButtonItemDemoState(
3737
errorMessage: String = stringResource(id = R.string.app_components_common_errorMessage_label),
3838
label: String = stringResource(id = R.string.app_components_common_label_label),
3939
extraLabel: String? = null,
40-
description: String? = null
40+
description: String? = null,
41+
constrainedMaxWidth: Boolean = false
4142
) = rememberSaveable(
4243
selectedValue,
4344
icon,
@@ -52,9 +53,25 @@ fun rememberRadioButtonItemDemoState(
5253
label,
5354
extraLabel,
5455
description,
56+
constrainedMaxWidth,
5557
saver = RadioButtonItemDemoState.Saver
5658
) {
57-
RadioButtonItemDemoState(selectedValue, icon, edgeToEdge, divider, outlined, reversed, enabled, readOnly, error, errorMessage, label, extraLabel, description)
59+
RadioButtonItemDemoState(
60+
selectedValue,
61+
icon,
62+
edgeToEdge,
63+
divider,
64+
outlined,
65+
reversed,
66+
enabled,
67+
readOnly,
68+
error,
69+
errorMessage,
70+
label,
71+
extraLabel,
72+
description,
73+
constrainedMaxWidth
74+
)
5875
}
5976

6077
class RadioButtonItemDemoState(
@@ -70,8 +87,9 @@ class RadioButtonItemDemoState(
7087
errorMessage: String,
7188
label: String,
7289
extraLabel: String?,
73-
description: String?
74-
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, label, description) {
90+
description: String?,
91+
constrainedMaxWidth: Boolean,
92+
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, label, description, constrainedMaxWidth) {
7593

7694
companion object {
7795
val values = listOf(1, 2)
@@ -102,7 +120,8 @@ class RadioButtonItemDemoState(
102120
errorMessage,
103121
label,
104122
list[2] as String?,
105-
description
123+
description,
124+
constrainedMaxWidth
106125
)
107126
}
108127
}

app/src/main/java/com/orange/ouds/app/ui/components/switch/SwitchItemDemoScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ private fun SwitchItemDemoContent(state: SwitchItemDemoState) {
5959
reversed = reversed,
6060
enabled = enabled,
6161
readOnly = readOnly,
62-
error = if (error) OudsError(errorMessage) else null
62+
error = if (error) OudsError(errorMessage) else null,
63+
constrainedMaxWidth = constrainedMaxWidth
6364
)
6465
}
6566
}

app/src/main/java/com/orange/ouds/app/ui/components/switch/SwitchItemDemoState.kt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,24 @@ fun rememberSwitchItemDemoState(
3434
error: Boolean = false,
3535
errorMessage: String = stringResource(id = R.string.app_components_common_errorMessage_label),
3636
text: String = stringResource(id = R.string.app_components_common_label_label),
37-
description: String? = null
38-
) = rememberSaveable(checked, icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, text, description, saver = SwitchItemDemoState.Saver) {
39-
SwitchItemDemoState(checked, icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, text, description)
37+
description: String? = null,
38+
constrainedMaxWidth: Boolean = false
39+
) = rememberSaveable(
40+
checked,
41+
icon,
42+
edgeToEdge,
43+
divider,
44+
reversed,
45+
enabled,
46+
readOnly,
47+
error,
48+
errorMessage,
49+
text,
50+
description,
51+
constrainedMaxWidth,
52+
saver = SwitchItemDemoState.Saver
53+
) {
54+
SwitchItemDemoState(checked, icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, text, description, constrainedMaxWidth)
4055
}
4156

4257
class SwitchItemDemoState(
@@ -50,8 +65,9 @@ class SwitchItemDemoState(
5065
error: Boolean,
5166
errorMessage: String,
5267
text: String,
53-
description: String?
54-
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, text, description) {
68+
description: String?,
69+
constrainedMaxWidth: Boolean
70+
) : ControlItemDemoState(icon, edgeToEdge, divider, reversed, enabled, readOnly, error, errorMessage, text, description, constrainedMaxWidth) {
5571

5672
companion object {
5773

@@ -76,7 +92,8 @@ class SwitchItemDemoState(
7692
error,
7793
errorMessage,
7894
label,
79-
description
95+
description,
96+
constrainedMaxWidth
8097
)
8198
}
8299
}

app/src/main/java/com/orange/ouds/app/ui/components/textinput/TextInputDemoScreen.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import androidx.compose.ui.res.stringResource
1818
import androidx.compose.ui.tooling.preview.PreviewLightDark
1919
import com.orange.ouds.app.R
2020
import com.orange.ouds.app.ui.components.Component
21+
import com.orange.ouds.app.ui.components.constrainedMaxWidthArgument
2122
import com.orange.ouds.app.ui.components.contentDescriptionArgument
2223
import com.orange.ouds.app.ui.components.enabledArgument
2324
import com.orange.ouds.app.ui.components.onClickArgument
@@ -136,6 +137,11 @@ private fun TextInputDemoBottomSheetContent(state: TextInputDemoState) {
136137
value = helperLink,
137138
onValueChange = { value -> helperLink = value }
138139
)
140+
CustomizationSwitchItem(
141+
label = stringResource(R.string.app_components_common_constrainedMaxWidth_label),
142+
checked = constrainedMaxWidth,
143+
onCheckedChange = { constrainedMaxWidth = it },
144+
)
139145
}
140146
}
141147

@@ -171,7 +177,8 @@ private fun TextInputDemoContent(state: TextInputDemoState) {
171177
prefix = prefix,
172178
suffix = suffix,
173179
helperText = helperText,
174-
helperLink = if (helperLink.isNotEmpty()) OudsTextInputHelperLink(text = helperLink, onClick = { }) else null
180+
helperLink = if (helperLink.isNotEmpty()) OudsTextInputHelperLink(text = helperLink, onClick = { }) else null,
181+
constrainedMaxWidth = constrainedMaxWidth
175182
)
176183
}
177184
}
@@ -223,6 +230,7 @@ private fun Code.Builder.textInputDemoCodeSnippet(state: TextInputDemoState, the
223230
}
224231
}
225232
}
233+
if (constrainedMaxWidth) constrainedMaxWidthArgument(true)
226234
}
227235
}
228236
}

0 commit comments

Comments
 (0)