Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEN-2539 New design/forever feature shared #2288

Merged
merged 13 commits into from
Nov 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import com.hedvig.android.design.system.hedvig.BigCardDefaults.inputTextStyle
Expand All @@ -21,6 +22,30 @@ import com.hedvig.android.design.system.hedvig.tokens.TypographyKeyTokens
* The card which looks like a TextField, but functions as a button which has the text in the positions of a button.
* https://www.figma.com/file/qUhLjrKl98PAzHov9ilaDH/New-Web-UI-Kit?type=design&node-id=114-2605&t=NMbwHBp5OhuKjgZ4-4
*/

@Composable
fun HedvigBigCard(
// todo: rename after complete migration to new DS to ButtonWithLabelTextField
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shape: Shape = HedvigTheme.shapes.cornerLarge,
content: @Composable () -> Unit,
) {
Surface(
shape = shape,
color = bigCardColors.containerColor,
modifier = modifier
.clip(shape)
.clickable(
onClick = onClick,
enabled = enabled,
),
) {
content()
}
}

@Composable
fun HedvigBigCard(
// todo: rename after complete migration to new DS to ButtonWithLabelTextField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -139,6 +140,97 @@ fun HedvigTextField(
)
}

@Composable
fun HedvigTextField(
textValue: TextFieldValue,
onValueChange: (TextFieldValue) -> Unit,
labelText: String,
textFieldSize: HedvigTextFieldDefaults.TextFieldSize,
modifier: Modifier = Modifier,
suffix: @Composable (() -> Unit)? = null,
leadingContent: @Composable (() -> Unit)? = null,
trailingContent: @Composable (() -> Unit)? = null,
errorState: HedvigTextFieldDefaults.ErrorState = HedvigTextFieldDefaults.ErrorState.NoError,
enabled: Boolean = true,
readOnly: Boolean = false,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = true,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
visualTransformation: VisualTransformation = VisualTransformation.None,
onTextLayout: (TextLayoutResult) -> Unit = {},
interactionSource: MutableInteractionSource? = null,
) {
@Suppress("NAME_SHADOWING")
val interactionSource = interactionSource ?: remember { MutableInteractionSource() }
val configuration = HedvigTextFieldDefaults.configuration()
val size = textFieldSize.size
val colors = HedvigTextFieldDefaults.colors()
val trailingIconColor by colors.trailingContentColor(
readOnly = readOnly,
enabled = enabled,
isError = errorState is HedvigTextFieldDefaults.ErrorState.Error,
)
val isFocused by interactionSource.collectIsFocusedAsState()
HedvigTextField(
value = textValue,
onValueChange = onValueChange,
colors = colors,
configuration = configuration,
size = size,
modifier = modifier,
enabled = enabled,
readOnly = readOnly,
label = { HedvigText(text = labelText) },
suffix = suffix,
leadingContent = leadingContent,
trailingContent = when {
trailingContent != null -> {
trailingContent
}
errorState.isError -> {
{ ErrorTrailingIcon(trailingIconColor) }
}

readOnly -> {
{ ReadOnlyTrailingIcon(trailingIconColor) }
}

isFocused && textValue.text.isNotEmpty() -> {
{
IsNotEmptyTrailingIcon(
trailingIconColor,
{
if (enabled && !readOnly) {
onValueChange(TextFieldValue(""))
}
},
)
}
}

else -> {
null
}
},
supportingText = if (errorState is HedvigTextFieldDefaults.ErrorState.Error.WithMessage) {
{ HedvigText(text = errorState.message) }
} else {
null
},
isError = errorState.isError,
visualTransformation = visualTransformation,
onTextLayout = onTextLayout,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
singleLine = singleLine,
maxLines = maxLines,
minLines = minLines,
interactionSource = interactionSource,
)
}

/**
* Similar to above, without an `ErrorState` parameter, and it allows a custom supportingText slot,
*/
Expand Down Expand Up @@ -586,6 +678,71 @@ private fun HedvigTextField(
}
}

@Composable
private fun HedvigTextField(
value: TextFieldValue,
onValueChange: (TextFieldValue) -> Unit,
colors: HedvigTextFieldColors,
configuration: HedvigTextFieldConfiguration,
size: HedvigTextFieldSize,
modifier: Modifier = Modifier,
enabled: Boolean = true,
readOnly: Boolean = false,
label: @Composable (() -> Unit)? = null,
suffix: @Composable (() -> Unit)? = null,
leadingContent: @Composable (() -> Unit)? = null,
trailingContent: @Composable (() -> Unit)? = null,
supportingText: @Composable (() -> Unit)? = null,
isError: Boolean = false,
visualTransformation: VisualTransformation = VisualTransformation.None,
onTextLayout: (TextLayoutResult) -> Unit = {},
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = false,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
) {
CompositionLocalProvider(LocalTextSelectionColors provides colors.selectionColors) {
BasicTextField(
value = value,
onValueChange = onValueChange,
modifier = modifier,
enabled = enabled,
readOnly = readOnly,
textStyle = size.textStyle.merge(color = colors.textColor(value.text, enabled, isError).value),
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
singleLine = singleLine,
maxLines = maxLines,
minLines = minLines,
visualTransformation = visualTransformation,
onTextLayout = onTextLayout,
interactionSource = interactionSource,
cursorBrush = SolidColor(colors.cursorColor),
decorationBox = @Composable { innerTextField ->
HedvigTextFieldDecorationBox(
value = value.text, // todo: not sure here
colors = colors,
configuration = configuration,
size = size,
visualTransformation = visualTransformation,
innerTextField = innerTextField,
label = label,
suffix = suffix,
leadingContent = leadingContent,
trailingContent = trailingContent,
supportingText = supportingText,
enabled = enabled,
isError = isError,
readOnly = readOnly,
interactionSource = interactionSource,
)
},
)
}
}

@Composable
private fun HedvigTextFieldDecorationBox(
value: String,
Expand Down
6 changes: 2 additions & 4 deletions app/shared/forever-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ hedvig {
}

dependencies {
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.lifecycle.compose)
implementation(libs.androidx.other.core)
implementation(libs.apollo.normalizedCache)
Expand All @@ -24,14 +23,13 @@ dependencies {
implementation(projects.coreCommonAndroidPublic)
implementation(projects.coreCommonPublic)
implementation(projects.coreDemoMode)
implementation(projects.coreDesignSystem)
implementation(projects.coreIcons)
implementation(projects.coreResources)
implementation(projects.coreUi)
implementation(projects.coreUiData)
implementation(projects.designSystemHedvig)
implementation(projects.languageCore)
implementation(projects.moleculeAndroid)
implementation(projects.moleculePublic)
implementation(projects.pullrefresh)
implementation(projects.composeUi)
implementation(projects.placeholder)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,25 @@ import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.unit.dp
import com.hedvig.android.core.designsystem.material3.onTypeContainer
import com.hedvig.android.core.designsystem.material3.typeContainer
import com.hedvig.android.core.designsystem.material3.typeElement
import com.hedvig.android.core.designsystem.preview.HedvigPreview
import com.hedvig.android.core.designsystem.theme.HedvigTheme
import com.hedvig.android.design.system.hedvig.HedvigPreview
import com.hedvig.android.design.system.hedvig.HedvigTheme
import com.hedvig.android.design.system.hedvig.Surface

@Composable
fun DiscountPieChart(
totalPrice: Float,
totalExistingDiscount: Float,
incentive: Float,
modifier: Modifier = Modifier,
containerColor: Color = MaterialTheme.colorScheme.typeElement,
discountColor: Color = MaterialTheme.colorScheme.onTypeContainer,
incentiveColor: Color = MaterialTheme.colorScheme.typeContainer,
containerColor: Color = HedvigTheme.colorScheme.signalGreenElement,
discountColor: Color = HedvigTheme.colorScheme.signalGreenText,
incentiveColor: Color = HedvigTheme.colorScheme.signalGreenFill,
) {
val transition = rememberInfiniteTransition(label = "transition")
val targetForeverIncentiveValue = calculateAngleDegrees(totalPrice, incentive)
Expand Down Expand Up @@ -85,7 +81,7 @@ private fun calculateAngleDegrees(totalPrice: Float, totalDiscount: Float): Floa
@HedvigPreview
fun PreviewDiscountPieChart() {
HedvigTheme {
Surface {
Surface(color = HedvigTheme.colorScheme.backgroundPrimary) {
Column {
DiscountPieChart(
totalPrice = 290f,
Expand Down
Loading
Loading