diff --git a/catalog/src/main/kotlin/com/adevinta/spark/catalog/configurator/samples/textfields/TextFieldsConfigurator.kt b/catalog/src/main/kotlin/com/adevinta/spark/catalog/configurator/samples/textfields/TextFieldsConfigurator.kt index c40b8afc7..b767b353a 100644 --- a/catalog/src/main/kotlin/com/adevinta/spark/catalog/configurator/samples/textfields/TextFieldsConfigurator.kt +++ b/catalog/src/main/kotlin/com/adevinta/spark/catalog/configurator/samples/textfields/TextFieldsConfigurator.kt @@ -101,8 +101,8 @@ private fun TextFieldSample() { label = labelText, placeholder = placeHolderText, helper = helperText, - leadingContent = addonText?.let { { Text(it) } }, - trailingContent = icon?.let { { Icon(it, contentDescription = null) } }, + leadingContent = addonText?.let { { Text(it) } } ?: {}, + trailingContent = icon?.let { { Icon(it, contentDescription = null) } } ?: {}, state = state, stateMessage = stateMessageText, ) diff --git a/catalog/src/main/kotlin/com/adevinta/spark/catalog/themes/ThemePicker.kt b/catalog/src/main/kotlin/com/adevinta/spark/catalog/themes/ThemePicker.kt index 9d548871c..1ad8da80f 100644 --- a/catalog/src/main/kotlin/com/adevinta/spark/catalog/themes/ThemePicker.kt +++ b/catalog/src/main/kotlin/com/adevinta/spark/catalog/themes/ThemePicker.kt @@ -142,7 +142,11 @@ public fun ThemePicker( text = { Text(text = brand.name) }, - trailingIcon = if (brand == theme.brandMode) selectedIcon else null, + trailingIcon = if (brand == theme.brandMode) { + selectedIcon + } else { + {} + }, onClick = { onThemeChange(theme.copy(brandMode = brand)) expanded = false diff --git a/spark-screenshot-testing/src/test/kotlin/com/adevinta/spark/textfields/TextFieldScreenshot.kt b/spark-screenshot-testing/src/test/kotlin/com/adevinta/spark/textfields/TextFieldScreenshot.kt index a9e34be1f..462b5091b 100644 --- a/spark-screenshot-testing/src/test/kotlin/com/adevinta/spark/textfields/TextFieldScreenshot.kt +++ b/spark-screenshot-testing/src/test/kotlin/com/adevinta/spark/textfields/TextFieldScreenshot.kt @@ -81,16 +81,16 @@ internal class TextFieldScreenshot { "_enabled".takeIf { enabled }.orEmpty() + helper?.let { "_helper.${helper.count()}" }.orEmpty(), ) { - val leadingContent: (@Composable AddonScope.() -> Unit)? = leadingIcon?.let { + val leadingContent: (@Composable AddonScope.() -> Unit) = leadingIcon?.let { @Composable { Icon(it, contentDescription = null) } - } - val trailingContent: (@Composable AddonScope.() -> Unit)? = trailingIcon?.let { + } ?: {} + val trailingContent: (@Composable AddonScope.() -> Unit) = trailingIcon?.let { @Composable { Icon(it, contentDescription = null) } - } + } ?: {} Column( verticalArrangement = Arrangement.spacedBy(8.dp), ) { diff --git a/spark/src/main/kotlin/com/adevinta/spark/components/menu/DropdownMenu.kt b/spark/src/main/kotlin/com/adevinta/spark/components/menu/DropdownMenu.kt index 63f5b0a79..8e7deb455 100644 --- a/spark/src/main/kotlin/com/adevinta/spark/components/menu/DropdownMenu.kt +++ b/spark/src/main/kotlin/com/adevinta/spark/components/menu/DropdownMenu.kt @@ -145,8 +145,8 @@ public fun DropdownMenuItem( text: @Composable () -> Unit, onClick: () -> Unit, modifier: Modifier = Modifier, - leadingIcon: @Composable (() -> Unit)? = null, - trailingIcon: @Composable (() -> Unit)? = null, + leadingIcon: @Composable (() -> Unit) = {}, + trailingIcon: @Composable (() -> Unit) = {}, enabled: Boolean = true, colors: MenuItemColors = MenuDefaults.itemColors(), contentPadding: PaddingValues = MenuDefaults.DropdownMenuItemContentPadding, diff --git a/spark/src/main/kotlin/com/adevinta/spark/components/textfields/MultilineTextField.kt b/spark/src/main/kotlin/com/adevinta/spark/components/textfields/MultilineTextField.kt index a0eeaf8d8..a84fbbe8e 100644 --- a/spark/src/main/kotlin/com/adevinta/spark/components/textfields/MultilineTextField.kt +++ b/spark/src/main/kotlin/com/adevinta/spark/components/textfields/MultilineTextField.kt @@ -123,7 +123,7 @@ public fun MultilineTextField( placeholder: String? = null, helper: String? = null, counter: TextFieldCharacterCounter? = null, - leadingContent: @Composable (AddonScope.() -> Unit)? = null, + leadingContent: @Composable (AddonScope.() -> Unit) = {}, state: TextFieldState? = null, stateMessage: String? = null, visualTransformation: VisualTransformation = VisualTransformation.None, @@ -133,7 +133,7 @@ public fun MultilineTextField( minLines: Int = 1, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, ) { - val trailingIconComposable: (@Composable AddonScope.() -> Unit)? = getTrailingContent( + val trailingIconComposable: (@Composable AddonScope.() -> Unit) = getTrailingContent( state = state, trailingIcon = if (value.text.isNotBlank()) { { @@ -150,7 +150,7 @@ public fun MultilineTextField( ) } } else { - null + {} }, ) @@ -244,7 +244,7 @@ public fun MultilineTextField( placeholder: String? = null, helper: String? = null, counter: TextFieldCharacterCounter? = null, - leadingContent: @Composable (AddonScope.() -> Unit)? = null, + leadingContent: @Composable (AddonScope.() -> Unit) = {}, state: TextFieldState? = null, stateMessage: String? = null, visualTransformation: VisualTransformation = VisualTransformation.None, @@ -254,7 +254,7 @@ public fun MultilineTextField( minLines: Int = 1, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, ) { - val trailingIconComposable: (@Composable AddonScope.() -> Unit)? = getTrailingContent( + val trailingIconComposable: (@Composable AddonScope.() -> Unit) = getTrailingContent( state = state, trailingIcon = if (value.isNotBlank()) { { @@ -271,7 +271,7 @@ public fun MultilineTextField( ) } } else { - null + {} }, ) SparkTextField( diff --git a/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SelectTextField.kt b/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SelectTextField.kt index ff09f2946..af4f2d7c5 100644 --- a/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SelectTextField.kt +++ b/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SelectTextField.kt @@ -126,7 +126,7 @@ public fun SelectTextField( label: String? = null, placeholder: String? = null, helper: String? = null, - leadingContent: @Composable (AddonScope.() -> Unit)? = null, + leadingContent: @Composable (AddonScope.() -> Unit) = {}, state: TextFieldState? = null, stateMessage: String? = null, visualTransformation: VisualTransformation = VisualTransformation.None, @@ -232,7 +232,7 @@ public fun SelectTextField( label: String? = null, placeholder: String? = null, helper: String? = null, - leadingContent: @Composable (AddonScope.() -> Unit)? = null, + leadingContent: @Composable (AddonScope.() -> Unit) = {}, state: TextFieldState? = null, stateMessage: String? = null, visualTransformation: VisualTransformation = VisualTransformation.None, diff --git a/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SparkTextField.kt b/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SparkTextField.kt index f2385e9ef..fd657b11a 100644 --- a/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SparkTextField.kt +++ b/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SparkTextField.kt @@ -94,8 +94,8 @@ internal fun SparkTextField( placeholder: String?, helper: String?, counter: TextFieldCharacterCounter?, - leadingContent: @Composable (AddonScope.() -> Unit)?, - trailingContent: @Composable (AddonScope.() -> Unit)?, + leadingContent: @Composable (AddonScope.() -> Unit), + trailingContent: @Composable (AddonScope.() -> Unit), state: TextFieldState?, stateMessage: String?, visualTransformation: VisualTransformation, @@ -193,8 +193,8 @@ internal fun SparkTextField( placeholder: String?, helper: String?, counter: TextFieldCharacterCounter?, - leadingIcon: @Composable (AddonScope.() -> Unit)?, // Should we rename it to leadingContent? - trailingIcon: @Composable (AddonScope.() -> Unit)?, // Should we rename it to trailingContent? + leadingIcon: @Composable (AddonScope.() -> Unit), // Should we rename it to leadingContent? + trailingIcon: @Composable (AddonScope.() -> Unit), // Should we rename it to trailingContent? state: TextFieldState?, stateMessage: String?, visualTransformation: VisualTransformation, @@ -383,8 +383,8 @@ internal object TextFieldDefault { @Composable internal fun getTrailingContent( state: TextFieldState?, - trailingIcon: (@Composable AddonScope.() -> Unit)?, - ): (@Composable AddonScope.() -> Unit)? = when { + trailingIcon: (@Composable AddonScope.() -> Unit), + ): (@Composable AddonScope.() -> Unit) = when { state != null -> { { val icon = when (state) { diff --git a/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SparkTextFieldImpl.kt b/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SparkTextFieldImpl.kt index bf94bdb01..cffecc4c1 100644 --- a/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SparkTextFieldImpl.kt +++ b/spark/src/main/kotlin/com/adevinta/spark/components/textfields/SparkTextFieldImpl.kt @@ -78,15 +78,15 @@ internal fun SparkDecorationBox( value: String, innerTextField: @Composable () -> Unit, visualTransformation: VisualTransformation, - label: @Composable (() -> Unit)?, + label: @Composable (() -> Unit), interactionSource: InteractionSource, colors: DefaultSparkTextFieldColors, readOnly: Boolean, placeholder: @Composable (() -> Unit)? = null, supportingText: @Composable (() -> Unit)? = null, counter: @Composable (() -> Unit)? = null, - leadingIcon: @Composable (AddonScope.() -> Unit)? = null, - trailingIcon: @Composable (AddonScope.() -> Unit)? = null, + leadingIcon: @Composable (AddonScope.() -> Unit) = {}, + trailingIcon: @Composable (AddonScope.() -> Unit) = {}, singleLine: Boolean = false, enabled: Boolean = true, state: TextFieldState? = null, @@ -99,8 +99,8 @@ internal fun SparkDecorationBox( val contentPadding = OutlinedTextFieldDefaults.contentPadding( top = VerticalContentPadding, bottom = VerticalContentPadding, - start = if (leadingIcon != null) 8.dp else 16.dp, - end = if (trailingIcon != null) 8.dp else 16.dp, + start = 8.dp, + end = 8.dp, ) val isFocused = interactionSource.collectIsFocusedAsState().value @@ -130,10 +130,10 @@ internal fun SparkDecorationBox( if (shouldOverrideTextStyleColor) this.takeOrElse { labelColor(inputState) } else this }, contentColor = labelColor, - showLabel = label != null, + showLabel = true, ) { labelProgress, labelTextStyleColor, labelContentColor, placeholderAlphaProgress -> - val decoratedLabel: @Composable (() -> Unit)? = label?.let { + val decoratedLabel: @Composable (() -> Unit)? = label.let { @Composable { val labelTextStyle = lerp( SparkTheme.typography.body1, diff --git a/spark/src/main/kotlin/com/adevinta/spark/components/textfields/TextField.kt b/spark/src/main/kotlin/com/adevinta/spark/components/textfields/TextField.kt index 688c60ab3..eebbb3499 100644 --- a/spark/src/main/kotlin/com/adevinta/spark/components/textfields/TextField.kt +++ b/spark/src/main/kotlin/com/adevinta/spark/components/textfields/TextField.kt @@ -106,8 +106,8 @@ public fun TextField( label: String? = null, placeholder: String? = null, helper: String? = null, - leadingContent: @Composable (AddonScope.() -> Unit)? = null, - trailingContent: @Composable (AddonScope.() -> Unit)? = null, + leadingContent: @Composable (AddonScope.() -> Unit) = {}, + trailingContent: @Composable (AddonScope.() -> Unit) = {}, state: TextFieldState? = null, stateMessage: String? = null, visualTransformation: VisualTransformation = VisualTransformation.None, @@ -115,7 +115,7 @@ public fun TextField( keyboardActions: KeyboardActions = KeyboardActions.Default, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, ) { - val trailingContentBasedOnState: (@Composable AddonScope.() -> Unit)? = TextFieldDefault.getTrailingContent( + val trailingContentBasedOnState: (@Composable AddonScope.() -> Unit) = TextFieldDefault.getTrailingContent( state = state, trailingIcon = trailingContent, ) @@ -201,8 +201,8 @@ public fun TextField( label: String? = null, placeholder: String? = null, helper: String? = null, - leadingContent: @Composable (AddonScope.() -> Unit)? = null, - trailingContent: @Composable (AddonScope.() -> Unit)? = null, + leadingContent: @Composable (AddonScope.() -> Unit) = {}, + trailingContent: @Composable (AddonScope.() -> Unit) = {}, state: TextFieldState? = null, stateMessage: String? = null, visualTransformation: VisualTransformation = VisualTransformation.None,