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

UI: Update TransportModeBadge and TransportModeIcon text styles and background #93

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package xyz.ksharma.krail.design.system.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.RoundedCornerShape
Expand All @@ -24,19 +23,19 @@ fun TransportModeBadge(
backgroundColor: Color,
modifier: Modifier = Modifier,
) {
Row(
Box(
modifier = modifier
.clip(shape = RoundedCornerShape(percent = 20))
.background(color = backgroundColor),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
contentAlignment = Alignment.Center,
) {
Text(
text = badgeText,
color = Color.White,
style = KrailTheme.typography.labelMedium.copy(fontWeight = FontWeight.Bold), // todo - need concrete token for this
// todo - need concrete token for style, meanwhile keep same as TransportModeIcon.
style = KrailTheme.typography.labelMedium.copy(fontWeight = FontWeight.Medium),
modifier = Modifier
.padding(2.dp)
.padding(start = 2.dp, end = 1.dp)
.wrapContentWidth(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import xyz.ksharma.krail.design.system.hexToComposeColor
import xyz.ksharma.krail.design.system.model.TransportModeType
import xyz.ksharma.krail.design.system.preview.ComponentPreviews
import xyz.ksharma.krail.design.system.theme.KrailTheme
import xyz.ksharma.krail.design.system.hexToComposeColor
import xyz.ksharma.krail.design.system.toAdaptiveSize

@Composable
Expand All @@ -30,33 +27,25 @@ fun TransportModeIcon(
) {
Box(
modifier = modifier
.clip(shape = CircleShape)
.borderIfEnabled(
width = 1.dp.toAdaptiveSize(),
color = Color.White,
shape = CircleShape,
enabled = borderEnabled,
)
.clip(shape = CircleShape)
.requiredSize(width = 18.dp.toAdaptiveSize(), height = 18.dp.toAdaptiveSize())
.aspectRatio(1f)
.background(color = transportModeType.hexColorCode.hexToComposeColor()),
.background(color = transportModeType.hexColorCode.hexToComposeColor())
.borderIfEnabled(enabled = borderEnabled),
contentAlignment = Alignment.Center,
) {
Text(
text = "${transportModeType.modeName.first()}",
color = Color.White,
style = KrailTheme.typography.labelMedium.copy(fontWeight = FontWeight.Bold),
// todo - need concrete token for style, meanwhile keep same as TransportModeBadge,
style = KrailTheme.typography.labelMedium.copy(fontWeight = FontWeight.Medium),
)
}
}

private fun Modifier.borderIfEnabled(
width: Dp,
color: Color,
shape: RoundedCornerShape,
enabled: Boolean,
): Modifier = if (enabled) border(width = width, color = color, shape = shape) else this
private fun Modifier.borderIfEnabled(enabled: Boolean): Modifier = if (enabled) {
this.then(Modifier.border(width = 1.dp, color = Color.White, shape = CircleShape))
} else this

// region Previews

Expand Down