From dfa60f03a2dc5e639c3c1a5bc35e14570ae388f1 Mon Sep 17 00:00:00 2001 From: BEEEAM-J Date: Tue, 5 Dec 2023 17:30:09 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20Contained,=20Outlined,=20Color=20ch?= =?UTF-8?q?ip=20Stateless=20Composable=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/chips/SuwikiColorChip.kt | 20 ++++-- .../component/chips/SuwikiContainedChip.kt | 65 +++++++++---------- .../component/chips/SuwikiOutlinedChip.kt | 41 +++++------- 3 files changed, 62 insertions(+), 64 deletions(-) diff --git a/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiColorChip.kt b/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiColorChip.kt index e96da8bc6..b6f89a078 100644 --- a/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiColorChip.kt +++ b/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiColorChip.kt @@ -8,15 +8,16 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.tooling.preview.Preview @Composable -fun SuwikiColorChip() { - var chipState by rememberSaveable { mutableStateOf(false) } - - when (chipState) { +fun SuwikiColorChip( + isChecked: Boolean, + onClick: () -> Unit = {}, +) { + when (isChecked) { true -> { - SuwikiCheckedColorChip { chipState = !chipState } + SuwikiCheckedColorChip(onClick = onClick) } false -> { - SuwikiNonCheckedColorChip { chipState = !chipState } + SuwikiNonCheckedColorChip(onClick = onClick) } } } @@ -24,5 +25,10 @@ fun SuwikiColorChip() { @Preview(showBackground = true, backgroundColor = 0xFFFFFF) @Composable fun SuwikiColorChipPreview() { - SuwikiColorChip() + var isChecked by rememberSaveable { mutableStateOf(false) } + + SuwikiColorChip( + isChecked = isChecked, + onClick = { isChecked = !isChecked } + ) } diff --git a/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiContainedChip.kt b/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiContainedChip.kt index 92df7e80e..df3a10eca 100644 --- a/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiContainedChip.kt +++ b/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiContainedChip.kt @@ -22,50 +22,42 @@ enum class SuwikiChipType { ORANGE, BLUE, GREEN, - DISABLE +// DISABLE } @Composable -fun SuwikiContainedChip(type: SuwikiChipType, text: String) { - var chipState by remember { mutableStateOf(false) } - +fun SuwikiContainedChip( + isChecked: Boolean, + onClick: () -> Unit = {}, + type: SuwikiChipType, + text: String, +) { val backgroundColor: Color val contentColor: Color - when (type) { - SuwikiChipType.ORANGE -> { - backgroundColor = Color(0xFFFFF3EB) - contentColor = Color(0xFFFD873B) + when (isChecked) { + true -> { + when (type) { + SuwikiChipType.ORANGE -> { + backgroundColor = Color(0xFFFFF3EB) + contentColor = Color(0xFFFD873B) + } + SuwikiChipType.BLUE -> { + backgroundColor = Color(0xFFECEDFF) + contentColor = Color(0xFF3D4EFB) + } + SuwikiChipType.GREEN -> { + backgroundColor = Color(0xFFEAF8EC) + contentColor = Color(0xFF2DB942) + } + } } - SuwikiChipType.BLUE -> { - backgroundColor = Color(0xFFECEDFF) - contentColor = Color(0xFF3D4EFB) - } - SuwikiChipType.GREEN -> { - backgroundColor = Color(0xFFEAF8EC) - contentColor = Color(0xFF2DB942) - } - SuwikiChipType.DISABLE -> { + false -> { backgroundColor = Color(0xFFF6F6F6) contentColor = Color(0xFF959595) } } - SuwikiContainedChipItem( - text = text, - backgroundColor = backgroundColor, - contentColor = contentColor, - onClick = { chipState = !chipState }, - ) -} - -@Composable -fun SuwikiContainedChipItem( - text: String, - backgroundColor: Color, - contentColor: Color, - onClick: () -> Unit = {}, -) { Box( modifier = Modifier .clip(RoundedCornerShape(5.dp)) @@ -86,5 +78,12 @@ fun SuwikiContainedChipItem( @Preview(showBackground = true, backgroundColor = 0xFFFFFF) @Composable fun SuwikiContainedChipPreview() { - SuwikiContainedChip(SuwikiChipType.ORANGE, "label") + var isChecked by remember { mutableStateOf(false) } + + SuwikiContainedChip( + isChecked = isChecked, + onClick = { isChecked = !isChecked }, + type = SuwikiChipType.GREEN, + text = "label", + ) } diff --git a/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiOutlinedChip.kt b/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiOutlinedChip.kt index 9ff0202f4..fff43b52e 100644 --- a/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiOutlinedChip.kt +++ b/core/designsystem/src/main/java/com/suwiki/core/designsystem/component/chips/SuwikiOutlinedChip.kt @@ -21,45 +21,32 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @Composable -fun SuwikiOutlinedChip(text: String) { - var labelState by remember { mutableStateOf(false) } - - val backgroundColor: Color +fun SuwikiOutlinedChip( + text: String, + isChecked: Boolean, + onClick: () -> Unit = {}, +) { + val borderLineColor: Color val contentColor: Color - when (labelState) { + when (isChecked) { false -> { - backgroundColor = Color(0xFFDADADA) + borderLineColor = Color(0xFFDADADA) contentColor = Color(0xFF959595) } true -> { - backgroundColor = Color(0xFF346CFD) + borderLineColor = Color(0xFF346CFD) contentColor = Color(0xFF346CFD) } } - SuwikiOutlinedChipItem( - text = text, - backgroundColor = backgroundColor, - contentColor = contentColor, - onClick = { labelState = !labelState }, - ) -} - -@Composable -fun SuwikiOutlinedChipItem( - text: String, - backgroundColor: Color, - contentColor: Color, - onClick: () -> Unit = {}, -) { Box( modifier = Modifier .clip(RoundedCornerShape(5.dp)) .clickable(onClick = onClick) .size(41.dp, 26.dp) .background(color = Color(0xFFFFFFFF)) - .border(width = 1.dp, color = backgroundColor, shape = RoundedCornerShape(5.dp)), + .border(width = 1.dp, color = borderLineColor, shape = RoundedCornerShape(5.dp)), ) { Text( text = text, @@ -74,5 +61,11 @@ fun SuwikiOutlinedChipItem( @Preview(showBackground = true, backgroundColor = 0xFFFFFF) @Composable fun SuwikiOutlinedChipPreview() { - SuwikiOutlinedChip("label") + var isChecked by remember { mutableStateOf(false) } + + SuwikiOutlinedChip( + text = "label", + isChecked = isChecked, + onClick = { isChecked = !isChecked }, + ) }