Skip to content

Commit 0232da9

Browse files
committed
chore(ui/badge): move away from forced Pill to a sized measure
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 6ee4901 commit 0232da9

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

  • ui/components/src/main/kotlin/com/getcode/ui/components

ui/components/src/main/kotlin/com/getcode/ui/components/Badge.kt

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,34 @@ import androidx.compose.animation.fadeIn
88
import androidx.compose.animation.fadeOut
99
import androidx.compose.animation.scaleIn
1010
import androidx.compose.animation.scaleOut
11-
import androidx.compose.foundation.layout.PaddingValues
11+
import androidx.compose.foundation.background
12+
import androidx.compose.foundation.layout.Box
1213
import androidx.compose.foundation.layout.padding
13-
import androidx.compose.material.Text
14+
import androidx.compose.foundation.shape.CircleShape
15+
import androidx.compose.material3.Text
1416
import androidx.compose.runtime.Composable
17+
import androidx.compose.ui.Alignment
1518
import androidx.compose.ui.Modifier
16-
import androidx.compose.ui.draw.drawBehind
19+
import androidx.compose.ui.draw.clip
1720
import androidx.compose.ui.graphics.Color
21+
import androidx.compose.ui.layout.layout
1822
import androidx.compose.ui.text.TextStyle
1923
import androidx.compose.ui.text.font.FontWeight
2024
import androidx.compose.ui.unit.dp
2125
import com.getcode.theme.CodeTheme
2226

2327

28+
private fun Modifier.squareMinSize(): Modifier = layout { measurable, constraints ->
29+
val intrinsicHeight = measurable.minIntrinsicHeight(constraints.maxWidth)
30+
val squaredConstraints = constraints.copy(
31+
minWidth = maxOf(constraints.minWidth, intrinsicHeight).coerceAtMost(constraints.maxWidth)
32+
)
33+
val placeable = measurable.measure(squaredConstraints)
34+
layout(placeable.width, placeable.height) {
35+
placeable.placeRelative(0, 0)
36+
}
37+
}
38+
2439
@Composable
2540
fun Badge(
2641
count: Int,
@@ -44,17 +59,18 @@ fun Badge(
4459
else -> "$count"
4560
}
4661

47-
Pill(
48-
backgroundColor = color,
49-
contentColor = contentColor,
50-
contentPadding = PaddingValues(
51-
horizontal = CodeTheme.dimens.grid.x1,
52-
vertical = 3.dp
53-
)
62+
Box(
63+
modifier = Modifier
64+
.squareMinSize()
65+
.clip(CircleShape)
66+
.background(color)
67+
.padding(horizontal = CodeTheme.dimens.grid.x1, vertical = 3.dp),
68+
contentAlignment = Alignment.Center
5469
) {
5570
Text(
5671
text = text,
5772
style = textStyle,
73+
color = contentColor,
5874
)
5975
}
6076
}

0 commit comments

Comments
 (0)