Skip to content

Commit

Permalink
[UI/#57] 라디오버튼 그룹 컴포넌트 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
boiledEgg-s committed Jul 12, 2024
1 parent 3b3a723 commit fab26cf
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.terning.core.designsystem.component.item

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp

@Composable
fun <T> RadioButtonGroups(
options: List<T>,
buttonComposable: @Composable (T, Boolean, (T) -> Unit) -> Unit,
gridCellCount: Int,
verticalArrangementSpace: Dp,
horizontalArrangementSpace: Dp,
modifier: Modifier = Modifier,
onOptionSelected: (T) -> Unit = {},

) {
var selectedOption by remember { mutableStateOf(options[0]) }

LazyVerticalGrid(
columns = GridCells.Fixed(gridCellCount),
verticalArrangement = Arrangement.spacedBy(verticalArrangementSpace),
horizontalArrangement = Arrangement.spacedBy(horizontalArrangementSpace),
modifier = modifier
//.padding(horizontal = 42.dp)
) {
items(options) { option ->
buttonComposable(
option,
(selectedOption == option),
) {
selectedOption = option
onOptionSelected(option)
}
}
}
}

0 comments on commit fab26cf

Please sign in to comment.