@@ -42,7 +42,7 @@ import com.orange.ouds.core.extensions.InteractionState
42
42
import com.orange.ouds.core.theme.OudsTheme
43
43
import com.orange.ouds.core.theme.outerBorder
44
44
import com.orange.ouds.core.theme.value
45
-
45
+ import com.orange.ouds.core.utilities.CheckedContent
46
46
47
47
@Composable
48
48
internal fun OudsControlItem (
@@ -57,74 +57,87 @@ internal fun OudsControlItem(
57
57
error : Boolean ,
58
58
errorComponentName : String ,
59
59
indicator : @Composable () -> Unit ,
60
+ previewState : OudsControlItem .State ? ,
61
+ previewStatus : String ,
60
62
modifier : Modifier = Modifier ,
61
63
additionalText : String? = null,
62
64
) {
63
- if (error) {
64
- if (readOnly) throw IllegalStateException (" An $errorComponentName set to readOnly with error parameter activated is not allowed." )
65
- if (! enabled) throw IllegalStateException (" An $errorComponentName set to disabled with error parameter activated is not allowed." )
66
- }
65
+ val isReadOnlyPreviewState = previewState == OudsControlItem .State .ReadOnly
66
+ val isDisabledPreviewState = previewState == OudsControlItem .State .Disabled
67
+ val isForbidden = error && (readOnly || ! enabled || isReadOnlyPreviewState || isDisabledPreviewState)
67
68
68
- val controlItemTokens = OudsTheme .componentsTokens.controlItem
69
+ CheckedContent (
70
+ expression = ! isForbidden,
71
+ exceptionMessage = {
72
+ val parameter = if (readOnly) " readOnly" else " disabled"
73
+ " An $errorComponentName set to $parameter with error parameter activated is not allowed."
74
+ },
75
+ previewMessage = {
76
+ val stateDescription = if (isReadOnlyPreviewState) " Read only" else " Disabled"
77
+ " Error $previewStatus status for $stateDescription state is not relevant"
78
+ }
79
+ ) {
80
+ val controlItemTokens = OudsTheme .componentsTokens.controlItem
69
81
70
- val itemIcon: (@Composable () -> Unit )? = icon?.let {
71
- {
72
- icon.Content (
73
- extraParameters = OudsControlItem .Icon .ExtraParameters (
74
- tint = if (state == OudsControlItem .State .Disabled ) OudsTheme .colorScheme.content.disabled else OudsTheme .colorScheme.content.default
82
+ val itemIcon: (@Composable () -> Unit )? = icon?.let {
83
+ {
84
+ icon.Content (
85
+ extraParameters = OudsControlItem .Icon .ExtraParameters (
86
+ tint = if (state == OudsControlItem .State .Disabled ) OudsTheme .colorScheme.content.disabled else OudsTheme .colorScheme.content.default
87
+ )
75
88
)
76
- )
89
+ }
77
90
}
78
- }
79
91
80
- val leadingElement: (@Composable () -> Unit )? = if (inverted) itemIcon else indicator
81
- val trailingElement: (@Composable () -> Unit )? = if (inverted) indicator else itemIcon
82
- val dividerThickness = 1 .dp
92
+ val leadingElement: (@Composable () -> Unit )? = if (inverted) itemIcon else indicator
93
+ val trailingElement: (@Composable () -> Unit )? = if (inverted) indicator else itemIcon
94
+ val dividerThickness = 1 .dp
83
95
84
- Column (
85
- modifier = modifier
86
- .height(IntrinsicSize .Min )
87
- .heightIn(min = controlItemTokens.sizeMinHeight.dp)
88
- .widthIn(min = controlItemTokens.sizeMinWidth.dp)
89
- .background(color = backgroundColor(state = state))
90
- .outerBorder(state = state)
91
- ) {
92
- Row (
93
- modifier = Modifier
94
- .weight(1f )
95
- .padding(all = controlItemTokens.spaceInset.value),
96
- horizontalArrangement = Arrangement .spacedBy(controlItemTokens.spaceColumnGap.value)
96
+ Column (
97
+ modifier = modifier
98
+ .height(IntrinsicSize .Min )
99
+ .heightIn(min = controlItemTokens.sizeMinHeight.dp)
100
+ .widthIn(min = controlItemTokens.sizeMinWidth.dp)
101
+ .background(color = backgroundColor(state = state))
102
+ .outerBorder(state = state)
97
103
) {
98
- leadingElement?.let { LeadingTrailingBox (leadingElement) }
99
- Column (
104
+ Row (
100
105
modifier = Modifier
101
106
.weight(1f )
102
- .align( Alignment . CenterVertically ),
103
- verticalArrangement = Arrangement .spacedBy(controlItemTokens.spaceRowGap .value)
107
+ .padding(all = controlItemTokens.spaceInset.value ),
108
+ horizontalArrangement = Arrangement .spacedBy(controlItemTokens.spaceColumnGap .value)
104
109
) {
105
- Text (text = text, style = OudsTheme .typography.label.default.large, color = textColor(state = state, error = error))
106
- if (! additionalText.isNullOrBlank()) {
107
- Text (
108
- text = additionalText,
109
- style = OudsTheme .typography.label.strong.medium,
110
- color = additionalTextColor(state = state)
111
- )
112
- }
113
- if (! helperText.isNullOrBlank()) {
114
- Text (
115
- text = helperText,
116
- style = OudsTheme .typography.label.default.medium,
117
- color = helperTextColor(state = state)
118
- )
110
+ leadingElement?.let { LeadingTrailingBox (leadingElement) }
111
+ Column (
112
+ modifier = Modifier
113
+ .weight(1f )
114
+ .align(Alignment .CenterVertically ),
115
+ verticalArrangement = Arrangement .spacedBy(controlItemTokens.spaceRowGap.value)
116
+ ) {
117
+ Text (text = text, style = OudsTheme .typography.label.default.large, color = textColor(state = state, error = error))
118
+ if (! additionalText.isNullOrBlank()) {
119
+ Text (
120
+ text = additionalText,
121
+ style = OudsTheme .typography.label.strong.medium,
122
+ color = additionalTextColor(state = state)
123
+ )
124
+ }
125
+ if (! helperText.isNullOrBlank()) {
126
+ Text (
127
+ text = helperText,
128
+ style = OudsTheme .typography.label.default.medium,
129
+ color = helperTextColor(state = state)
130
+ )
131
+ }
119
132
}
133
+ trailingElement?.let { LeadingTrailingBox (trailingElement) }
134
+ }
135
+ if (divider) {
136
+ HorizontalDivider (
137
+ thickness = dividerThickness,
138
+ color = OudsTheme .colorScheme.border.default.copy(alpha = 0.2f )
139
+ ) // TODO Replace with OudsHorizontalDivider when available
120
140
}
121
- trailingElement?.let { LeadingTrailingBox (trailingElement) }
122
- }
123
- if (divider) {
124
- HorizontalDivider (
125
- thickness = dividerThickness,
126
- color = OudsTheme .colorScheme.border.default.copy(alpha = 0.2f )
127
- ) // TODO Replace with OudsHorizontalDivider when available
128
141
}
129
142
}
130
143
}
0 commit comments