-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelectionGroup.kt
46 lines (43 loc) · 1.61 KB
/
SelectionGroup.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.todoapp.component
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.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.unit.dp
import androidx.compose.ui.unit.sp
import br.com.zup.nimbus.annotation.AutoDeserialize
private val unselectedColor = Color(red = 95, green = 114, blue = 192)
private val selectedColor = Color(red = 76, green = 91, blue = 145)
@Composable
@AutoDeserialize
fun SelectionGroup(
options: List<String>,
value: String,
onChange: (String) -> Unit,
) {
Row(Modifier
.border(width = 1.dp, color = selectedColor, shape = RoundedCornerShape(8.dp))
.clip(RoundedCornerShape(8.dp))
.background(selectedColor)
) {
options.forEachIndexed { index, option ->
val isLastItem = index == options.size - 1
Box(Modifier
.clickable { onChange(option) }
.padding(end = (if (isLastItem) 0 else 1).dp)
.background(if (value == option) Color.Transparent else unselectedColor)
.padding(horizontal = 10.dp, vertical = 8.dp)
) {
Text(option, color = Color.White, fontSize = 13.sp)
}
}
}
}