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 fab26cf commit 2778b76
Showing 1 changed file with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.terning.core.designsystem.component.item

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Check
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.terning.core.designsystem.theme.CalBlue1
import com.terning.core.designsystem.theme.CalBlue2
import com.terning.core.designsystem.theme.CalGreen1
import com.terning.core.designsystem.theme.CalGreen2
import com.terning.core.designsystem.theme.CalOrange1
import com.terning.core.designsystem.theme.CalOrange2
import com.terning.core.designsystem.theme.CalPink
import com.terning.core.designsystem.theme.CalPurple
import com.terning.core.designsystem.theme.CalRed
import com.terning.core.designsystem.theme.CalYellow
import com.terning.core.extension.noRippleClickable

@Composable
fun ColorPalette(
modifier: Modifier = Modifier,
onColorSelected:() -> Unit = {}
) {
val colorList = listOf(
CalRed,
CalOrange2,
CalGreen1,
CalBlue1,
CalPurple,
CalOrange1,
CalYellow,
CalGreen2,
CalBlue2,
CalPink
)

val colorButton: @Composable (Color, Boolean, (Color) -> Unit) -> Unit = {
color: Color, isSelected: Boolean, onOptionSelected:(Color)-> Unit ->
ColorButton(color = color, isSelected = isSelected, onColorSelected = onOptionSelected)
}

RadioButtonGroups(
modifier = modifier.size(251.dp, 84.dp),
options = colorList,
gridCellCount = 5,
onOptionSelected = { color ->
Log.d("CalendarScreen","color: ${colorList.indexOf(color)}")
},
buttonComposable = colorButton,
verticalArrangementSpace = 6.dp,
horizontalArrangementSpace = 14.dp,
)
}

@Composable
internal fun ColorButton(
modifier: Modifier = Modifier,
color: Color,
isSelected: Boolean,
onColorSelected: (Color) -> Unit
) {
Box(modifier = modifier.size(39.dp)) {
Box(
modifier = Modifier
.size(39.dp)
.background(shape = CircleShape, color = color)
.noRippleClickable {
onColorSelected(color)
},
contentAlignment = Alignment.Center
) {
if (isSelected) {
Icon(
imageVector = Icons.Outlined.Check,
tint = Color.White,
contentDescription = ""
)
}
}
}
}


@Preview(showBackground = true)
@Composable
fun ColorPalettePreview() {
ColorPalette()
}

0 comments on commit 2778b76

Please sign in to comment.