-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change badge component from Badge to Box (#459)
* Change badge component from Badge to Box This allows to customize the shape. I also changed the color of the text to OnTertiary to avoid contrast issues. * Fix formatting * refactor: create TextBadge component * Modify attributes for TextBadge Add default values and add padding values * gradle kotlin formatting * Add section in settings to edit TextBadge corner radius * kotlin formatting * Revert "kotlin formatting" This reverts commit 1425c7d. * Revert "Add section in settings to edit TextBadge corner radius" This reverts commit f9222a2.
- Loading branch information
Showing
2 changed files
with
44 additions
and
11 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/jerboa/ui/components/common/TextBadge.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters