Coverage Summary for Class: SelectableBorderKt (com.vsevolodganin.clicktrack.ui.piece)
Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
SelectableBorderKt |
0%
(0/1)
|
0%
(0/2)
|
0%
(0/8)
|
0%
(0/20)
|
0%
(0/158)
|
package com.vsevolodganin.clicktrack.ui.piece
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
import androidx.compose.material.ContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
@Composable
fun Modifier.selectableBorder(
isSelected: Boolean,
isError: Boolean = false,
activeColor: Color = MaterialTheme.colors.primary.copy(alpha = ContentAlpha.high),
inactiveColor: Color = MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled),
activeErrorColor: Color = MaterialTheme.colors.error.copy(alpha = ContentAlpha.high),
inactiveErrorColor: Color = MaterialTheme.colors.error.copy(alpha = ContentAlpha.disabled),
): Modifier {
val borderColor = when {
isSelected -> when {
isError -> activeErrorColor
else -> activeColor
}
else -> when {
isError -> inactiveErrorColor
else -> inactiveColor
}
}
val borderWidth by animateDpAsState(if (isSelected) 2.dp else 1.dp)
val shape = MaterialTheme.shapes.small
return this
.border(
border = BorderStroke(borderWidth, borderColor),
shape = MaterialTheme.shapes.small,
)
.clip(shape)
}