Skip to content

Commit

Permalink
리뷰 반영
Browse files Browse the repository at this point in the history
* modifier 추가
* text 기본값 제거
* 구현 Clickable Surface -> Box
  • Loading branch information
Gael-Android committed Nov 29, 2023
1 parent f62913d commit ea466fb
Showing 1 changed file with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.yourssu.design.system.compose.atom

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -16,18 +18,19 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.yourssu.design.system.compose.YdsTheme
import com.yourssu.design.system.compose.base.Surface
import com.yourssu.design.system.compose.base.YdsText

@Composable
fun Chip(
text: String = "",
modifier: Modifier = Modifier,
text: String,
isSelected: Boolean = false,
isDisabled: Boolean = false,
onSelectedChange: () -> Unit = {},
onSelectedChange: (Boolean) -> Unit,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
) {
val contentColor = if (isSelected) {
Expand All @@ -42,24 +45,25 @@ fun Chip(
YdsTheme.colors.buttonDisabledBG
}

Surface(
onClick = onSelectedChange,
modifier = Modifier.height(24.dp),
enabled = isDisabled.not(),
shape = RoundedCornerShape(12.dp),
color = backgroundColor,
contentColor = contentColor,
interactionSource = interactionSource,
Box(
modifier = modifier
.height(24.dp)
.clip(RoundedCornerShape(12.dp))
.background(backgroundColor)
.clickable(
interactionSource = interactionSource,
indication = null,
enabled = isDisabled.not(),
onClick = { onSelectedChange(!isSelected) }
),
contentAlignment = Alignment.Center,
) {
Column(
verticalArrangement = Arrangement.Center
) {
YdsText(
text = text,
modifier = Modifier.padding(horizontal = 8.dp),
style = YdsTheme.typography.caption1
)
}
YdsText(
text = text,
modifier = Modifier.padding(horizontal = 8.dp),
color = contentColor,
style = YdsTheme.typography.caption1
)
}
}

Expand All @@ -69,7 +73,7 @@ fun Chip(
private fun PreviewChip() {
var checked1 by remember { mutableStateOf(true) }
var checked2 by remember { mutableStateOf(false) }
val onSelectedChange = { checked1 = !checked1 }
val onSelectedChange: (Boolean) -> Unit = { it -> checked1 = it }

Column(
modifier = Modifier
Expand All @@ -80,12 +84,14 @@ private fun PreviewChip() {
) {
Spacer(modifier = Modifier.height(8.dp))
Chip(
text = "IT대학",
isSelected = checked1,
isDisabled = false,
onSelectedChange = onSelectedChange
)
Spacer(modifier = Modifier.height(8.dp))
Chip(
text = "IT대학",
isSelected = checked2,
isDisabled = true,
onSelectedChange = onSelectedChange
Expand Down

0 comments on commit ea466fb

Please sign in to comment.