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

Add custom TextBadge() component #459

Merged
merged 11 commits into from
Jun 9, 2023
42 changes: 42 additions & 0 deletions app/src/main/java/com/jerboa/ui/components/common/TextBadge.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.jerboa.ui.components.common

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp

@Composable
fun TextBadge(
text: String,
verticalTextPadding: Float = 0f,
horizontalTextPadding: Float = 6f,
textColor: Color = MaterialTheme.colorScheme.onTertiary,
textStyle: TextStyle,
containerColor: Color = MaterialTheme.colorScheme.tertiary,
containerRadius: Float = 4f,
) {
Box(
modifier = Modifier
.clip(RoundedCornerShape(containerRadius.dp))
.background(containerColor),
) {
Text(
text = text,
style = textStyle,
overflow = TextOverflow.Clip,
maxLines = 1,
color = textColor,
modifier = Modifier
.padding(horizontalTextPadding.dp, verticalTextPadding.dp),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.*
import androidx.compose.material3.Badge
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
Expand All @@ -22,6 +21,7 @@ import com.jerboa.datatypes.PersonSafe
import com.jerboa.datatypes.samplePersonSafe
import com.jerboa.personNameShown
import com.jerboa.ui.components.common.CircularIcon
import com.jerboa.ui.components.common.TextBadge
import com.jerboa.ui.theme.SMALL_PADDING

@Composable
Expand All @@ -34,16 +34,7 @@ fun PersonName(
val style = MaterialTheme.typography.bodyMedium

if (isPostCreator) {
Badge(
containerColor = MaterialTheme.colorScheme.tertiary,
) {
Text(
text = name,
style = style,
overflow = TextOverflow.Clip,
maxLines = 1,
)
}
TextBadge(text = name, textStyle = style)
} else {
Text(
text = name,
Expand Down