Skip to content

Commit e8fa73f

Browse files
committed
Update CheckedContent method to enhance previews
1 parent 1abdbab commit e8fa73f

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

core/src/main/java/com/orange/ouds/core/component/OudsTag.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ private fun OudsTag(
171171
val hasAsset = hasBullet || nullableIcon != null || loading != null
172172
val isForbidden = status == OudsTag.Status.Disabled && loading != null
173173

174+
val tagShape = shape(shape)
174175
CheckedContent(
175176
expression = !isForbidden,
176177
exceptionMessage = { "An OudsTag with OudsTag.Status.Disabled status cannot have a loading spinner. This is not allowed." },
177-
previewMessage = { "" }
178+
previewMessagePaddingValues = contentPadding(size, false),
179+
shape = tagShape
178180
) {
179181
// This outer box is necessary otherwise the user can change the size of the tag through the modifier
180182
Box(
@@ -184,7 +186,7 @@ private fun OudsTag(
184186
Row(
185187
modifier = Modifier
186188
.sizeIn(minWidth = minWidth(size), minHeight = minHeight(size))
187-
.clip(shape = shape(shape))
189+
.clip(shape = tagShape)
188190
.background(status.backgroundColor(hierarchy = hierarchy))
189191
.padding(paddingValues = contentPadding(size = size, hasAsset = hasAsset)),
190192
verticalAlignment = Alignment.CenterVertically,

core/src/main/java/com/orange/ouds/core/utilities/CheckedContent.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ package com.orange.ouds.core.utilities
1414

1515
import androidx.compose.foundation.background
1616
import androidx.compose.foundation.layout.Box
17+
import androidx.compose.foundation.layout.PaddingValues
1718
import androidx.compose.foundation.layout.padding
1819
import androidx.compose.material3.Text
1920
import androidx.compose.runtime.Composable
2021
import androidx.compose.ui.Alignment
2122
import androidx.compose.ui.Modifier
2223
import androidx.compose.ui.draw.alpha
2324
import androidx.compose.ui.graphics.Color
25+
import androidx.compose.ui.graphics.RectangleShape
26+
import androidx.compose.ui.graphics.Shape
2427
import androidx.compose.ui.platform.LocalInspectionMode
2528
import androidx.compose.ui.text.TextStyle
2629
import androidx.compose.ui.text.font.FontFamily
2730
import androidx.compose.ui.text.style.TextAlign
2831
import androidx.compose.ui.unit.dp
32+
import androidx.compose.ui.unit.sp
2933
import com.orange.ouds.core.theme.LocalColorMode
3034
import com.orange.ouds.core.theme.OudsTheme
3135
import com.orange.ouds.core.theme.dashedBorder
@@ -35,6 +39,8 @@ internal fun CheckedContent(
3539
expression: Boolean,
3640
exceptionMessage: () -> String,
3741
previewMessage: () -> String = { "⛔" },
42+
previewMessagePaddingValues: PaddingValues = PaddingValues(all = OudsTheme.spaces.fixed.small),
43+
shape: Shape = RectangleShape,
3844
content: @Composable () -> Unit
3945
) {
4046
// Throw an exception at runtime if expression is false
@@ -50,16 +56,17 @@ internal fun CheckedContent(
5056
val backgroundColor = if (LocalColorMode.current != null) Color.Black.copy(alpha = 0.68f) else Color.Transparent
5157
Box(
5258
modifier = Modifier
53-
.dashedBorder(width = 1.dp, color = color, intervals = listOf(10.dp, 5.dp))
59+
.dashedBorder(width = 1.dp, color = color, shape = shape, intervals = listOf(10.dp, 5.dp))
5460
.background(backgroundColor),
5561
contentAlignment = Alignment.Center
5662
) {
5763
Box(modifier = Modifier.alpha(0f)) { content() } // Add content but hide it in order to make room for the text
5864
Text(
59-
modifier = Modifier.padding(OudsTheme.spaces.fixed.small),
65+
modifier = Modifier.padding(previewMessagePaddingValues),
6066
text = previewMessage(),
6167
color = color,
6268
textAlign = TextAlign.Center,
69+
fontSize = 14.sp,
6370
style = TextStyle(fontFamily = FontFamily.Monospace)
6471
)
6572
}
4.06 KB
Loading
4.07 KB
Loading

0 commit comments

Comments
 (0)