Skip to content

Commit

Permalink
Merge pull request #295 from Spendesk/release/1.18.0
Browse files Browse the repository at this point in the history
Release/1.18.0
  • Loading branch information
RomainGF authored Nov 8, 2023
2 parents fd2d6c0 + 0508435 commit e7cdbb1
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 90 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
grapes-version = '1.17.0'
grapes-version = '1.18.0'
androidMinSdk = "21"
androidTargetSdk = "34"
androidCompileSdk = "34"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal fun ErrorGrapesCalloutColors(
containerColor: Color = GrapesTheme.colors.mainAlertLightest,
titleColor: Color = GrapesTheme.colors.mainAlertNormal,
contentColor: Color = LocalContentColor.current,
borderStoreColor: Color = GrapesTheme.colors.mainAlertNormal,
borderStoreColor: Color = GrapesTheme.colors.mainAlertLighter,
) : GrapesCalloutColors = DefaultGrapesCalloutColors(
containerColor = containerColor,
titleColor = titleColor,
Expand All @@ -41,7 +41,7 @@ internal fun WarningGrapesCalloutColors(
containerColor: Color = GrapesTheme.colors.mainWarningLightest,
titleColor: Color = GrapesTheme.colors.mainWarningNormal,
contentColor: Color = LocalContentColor.current,
borderStoreColor: Color = GrapesTheme.colors.mainWarningNormal,
borderStoreColor: Color = GrapesTheme.colors.mainWarningLighter,
) : GrapesCalloutColors = DefaultGrapesCalloutColors(
containerColor = containerColor,
titleColor = titleColor,
Expand All @@ -54,7 +54,7 @@ internal fun InfoGrapesCalloutColors(
containerColor: Color = GrapesTheme.colors.mainInfoLightest,
titleColor: Color = GrapesTheme.colors.mainInfoNormal,
contentColor: Color = LocalContentColor.current,
borderStoreColor: Color = GrapesTheme.colors.mainInfoNormal,
borderStoreColor: Color = GrapesTheme.colors.mainInfoLighter,
) : GrapesCalloutColors = DefaultGrapesCalloutColors(
containerColor = containerColor,
titleColor = titleColor,
Expand All @@ -67,7 +67,7 @@ internal fun SuccessGrapesCalloutColors(
containerColor: Color = GrapesTheme.colors.mainSuccessLightest,
titleColor: Color = GrapesTheme.colors.mainSuccessNormal,
contentColor: Color = LocalContentColor.current,
borderStoreColor: Color = GrapesTheme.colors.mainSuccessNormal,
borderStoreColor: Color = GrapesTheme.colors.mainSuccessLighter,
) : GrapesCalloutColors = DefaultGrapesCalloutColors(
containerColor = containerColor,
titleColor = titleColor,
Expand All @@ -80,7 +80,7 @@ internal fun NeutralGrapesCalloutColors(
containerColor: Color = GrapesTheme.colors.mainNeutralLighter,
titleColor: Color = GrapesTheme.colors.mainNeutralDarker,
contentColor: Color = LocalContentColor.current,
borderStoreColor: Color = GrapesTheme.colors.mainNeutralNormal,
borderStoreColor: Color = GrapesTheme.colors.mainNeutralLighter,
) : GrapesCalloutColors = DefaultGrapesCalloutColors(
containerColor = containerColor,
titleColor = titleColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
Expand All @@ -41,8 +44,9 @@ import com.spendesk.grapes.compose.theme.GrapesTheme
* @since 06/01/2023, Fri
**/

@ExperimentalMaterial3Api
@Composable
@ExperimentalMaterial3Api
@Suppress("LongParameterList")
internal fun GrapesBaseTextField(
value: String,
placeholderValue: String,
Expand All @@ -52,6 +56,7 @@ internal fun GrapesBaseTextField(
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = GrapesTheme.typography.bodyRegular,
textPadding: PaddingValues = GrapesTextFieldDefaults.textFieldPadding(),
isError: Boolean = false,
onClick: (() -> Unit)? = null,
keyboardActions: KeyboardActions = KeyboardActions.Default,
Expand Down Expand Up @@ -112,6 +117,7 @@ internal fun GrapesBaseTextField(
enabled = enabled,
readOnly = readOnly,
textStyle = textStyle,
textPadding = textPadding,
isError = isError,
onClick = onClick,
keyboardActions = keyboardActions,
Expand All @@ -125,8 +131,9 @@ internal fun GrapesBaseTextField(
)
}

@ExperimentalMaterial3Api
@Composable
@ExperimentalMaterial3Api
@Suppress("LongParameterList")
internal fun GrapesBaseTextField(
value: TextFieldValue,
placeholderValue: String,
Expand All @@ -136,6 +143,7 @@ internal fun GrapesBaseTextField(
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = GrapesTheme.typography.bodyRegular,
textPadding: PaddingValues = GrapesTextFieldDefaults.textFieldPadding(),
isError: Boolean = false,
onClick: (() -> Unit)? = null,
keyboardActions: KeyboardActions = KeyboardActions.Default,
Expand Down Expand Up @@ -164,26 +172,51 @@ internal fun GrapesBaseTextField(
Column(
modifier = modifier.width(IntrinsicSize.Min)
) {
GrapesCoreTextField(
value = value,
placeholderValue = placeholderValue,
modifier = Modifier,
onValueChange = onValueChange,
BasicTextField(
enabled = enabled,
readOnly = readOnly,
value = value,
onValueChange = onValueChange,
textStyle = mergedTextStyle,
isError = isError,
keyboardActions = keyboardActions,
keyboardOptions = keyboardOptions,
singleLine = singleLine,
colors = colors,
cursorBrush = SolidColor(colors.cursorColor(isError).value),
visualTransformation = visualTransformation,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
interactionSource = interactionSource,
leadingIcon = leadingIcon,
trailingIcon = trailingIcon
singleLine = singleLine,
decorationBox = @Composable { innerTextField ->
GrapesBasicTextFieldDecorationBox(
value = value,
innerTextField = innerTextField,
enabled = enabled,
singleLine = singleLine,
visualTransformation = visualTransformation,
interactionSource = interactionSource,
placeholderValue = placeholderValue,
leadingIcon = leadingIcon,
trailingIcon = trailingIcon,
isError = isError,
colors = colors,
contentPadding = textPadding,
)
},
modifier = Modifier
.fillMaxWidth()
.defaultMinSize(
minWidth = GrapesTextFieldDefaults.MinWidth,
minHeight = GrapesTextFieldDefaults.MinHeight,
)
.shadow(
elevation = GrapesTextFieldDefaults.Elevation,
shape = GrapesTextFieldDefaults.TextFieldShape,
)
.background(
color = colors.backgroundColor(enabled).value,
shape = GrapesTextFieldDefaults.TextFieldShape
),
)

if (helperText != null && helperText.isNotEmpty()) {
if (!helperText.isNullOrEmpty()) {
GrapesHelperText(
text = helperText,
modifier = Modifier.fillMaxWidth(),
Expand All @@ -195,6 +228,7 @@ internal fun GrapesBaseTextField(
}

@Composable
@Suppress("LongParameterList")
internal fun GrapesHelperText(
text: String,
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -227,79 +261,73 @@ internal fun GrapesHelperText(
}
}

@ExperimentalMaterial3Api
@Composable
private fun GrapesCoreTextField(
@OptIn(ExperimentalMaterial3Api::class)
@Suppress("LongParameterList")
private fun GrapesBasicTextFieldDecorationBox(
value: TextFieldValue,
placeholderValue: String,
onValueChange: (TextFieldValue) -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = TextStyle.Default,
isError: Boolean = false,
keyboardActions: KeyboardActions = KeyboardActions.Default,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
singleLine: Boolean = false,
colors: GrapesTextFieldColors = GrapesTextFieldDefaults.textFieldColors(),
visualTransformation: VisualTransformation = VisualTransformation.None,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
contentPadding: PaddingValues,
enabled: Boolean,
isError: Boolean,
singleLine: Boolean,
colors: GrapesTextFieldColors,
visualTransformation: VisualTransformation,
interactionSource: MutableInteractionSource,
innerTextField: @Composable () -> Unit,
leadingIcon: @Composable (() -> Unit)?,
trailingIcon: @Composable (() -> Unit)?,
) {
BasicTextField(
modifier = modifier
.fillMaxWidth()
.defaultMinSize(
minWidth = GrapesTextFieldDefaults.MinWidth,
minHeight = GrapesTextFieldDefaults.MinHeight,
val styledLeadingIcon: (@Composable () -> Unit)? = leadingIcon?.let {
@Composable {
val contentColor by colors.leadingIconColor(
enabled = enabled,
isError = isError,
)
.shadow(
elevation = GrapesTextFieldDefaults.Elevation,
shape = GrapesTextFieldDefaults.TextFieldShape,
CompositionLocalProvider(
LocalContentColor provides contentColor,
content = leadingIcon,
)
.background(
color = colors.backgroundColor(enabled).value,
shape = GrapesTextFieldDefaults.TextFieldShape
),
}
}

val styledTrailingIcon: (@Composable () -> Unit)? = trailingIcon?.let {
@Composable {
val contentColor by colors.trailingIconColor(
enabled = enabled,
isError = isError,
)
CompositionLocalProvider(
LocalContentColor provides contentColor,
content = trailingIcon,
)
}
}

OutlinedTextFieldDefaults.DecorationBox(
value = value.text,
innerTextField = innerTextField,
enabled = enabled,
readOnly = readOnly,
value = value,
onValueChange = onValueChange,
textStyle = textStyle,
cursorBrush = SolidColor(colors.cursorColor(isError).value),
singleLine = singleLine,
visualTransformation = visualTransformation,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
interactionSource = interactionSource,
singleLine = singleLine,
decorationBox = @Composable { innerTextField ->
TextFieldDefaults.OutlinedTextFieldDecorationBox(
value = value.text,
innerTextField = innerTextField,
contentPadding = contentPadding,
placeholder = {
Text(
text = placeholderValue,
style = GrapesTheme.typography.bodyRegular,
color = colors.placeholderColor(enabled = enabled).value,
)
},
leadingIcon = styledLeadingIcon,
trailingIcon = styledTrailingIcon,
container = {
GrapesTextFieldDefaults.BorderBox(
enabled = enabled,
singleLine = singleLine,
visualTransformation = visualTransformation,
isError = isError,
interactionSource = interactionSource,
contentPadding = GrapesTextFieldDefaults.textFieldPadding(),
placeholder = {
Text(
text = placeholderValue,
style = GrapesTheme.typography.bodyRegular,
color = colors.placeholderColor(enabled = enabled).value,
)
},
leadingIcon = leadingIcon,
trailingIcon = trailingIcon,
container = {
GrapesTextFieldDefaults.BorderBox(
enabled = enabled,
isError = isError,
interactionSource = interactionSource,
colors = colors
)
}
colors = colors
)
}
},
)
}
Loading

0 comments on commit e7cdbb1

Please sign in to comment.