Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Prezel/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import io.gitlab.arturbosch.detekt.Detekt

plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
Expand Down Expand Up @@ -29,7 +31,9 @@ subprojects {
parallel = true
}

tasks.withType<io.gitlab.arturbosch.detekt.Detekt>().configureEach {
tasks.withType<Detekt>().configureEach {
jvmTarget = "21"

reports {
txt.required.set(true)
html.required.set(false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package com.team.prezel.core.designsystem.component.chip

import androidx.annotation.DrawableRes
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.team.prezel.core.designsystem.component.chip.config.PrezelChipDefault
import com.team.prezel.core.designsystem.component.chip.config.PrezelChipDefaults
import com.team.prezel.core.designsystem.component.chip.config.PrezelChipFeedback
import com.team.prezel.core.designsystem.component.chip.config.PrezelChipInteraction
import com.team.prezel.core.designsystem.component.chip.config.PrezelChipLayout
import com.team.prezel.core.designsystem.component.chip.config.PrezelChipSize
import com.team.prezel.core.designsystem.component.chip.config.PrezelChipType
import com.team.prezel.core.designsystem.icon.PrezelIcons
import com.team.prezel.core.designsystem.preview.BasicPreview
import com.team.prezel.core.designsystem.preview.PreviewRow
Expand All @@ -27,201 +22,146 @@ import com.team.prezel.core.designsystem.theme.PrezelTheme

@Composable
fun PrezelChip(
text: String,
modifier: Modifier = Modifier,
text: String? = null,
@DrawableRes iconResId: Int? = null,
style: PrezelChipStyle = PrezelChipStyle(),
type: PrezelChipType = PrezelChipType.FILLED,
size: PrezelChipSize = PrezelChipSize.REGULAR,
interaction: PrezelChipInteraction = PrezelChipInteraction.DEFAULT,
feedback: PrezelChipFeedback = PrezelChipFeedback.DEFAULT,
config: PrezelChipDefault = PrezelChipDefaults.getDefault(
iconOnly = false,
type = type,
size = size,
interaction = interaction,
feedback = feedback,
),
) {
val hasText = text != null
val hasIcon = iconResId != null
val iconOnly = hasIcon && !hasText
require(hasText || hasIcon) { "Chip은 text 또는 icon 중 하나는 반드시 필요합니다." }

Surface(
PrezelChipLayout(
modifier = modifier,
shape = style.shape(),
color = style.containerColor(iconOnly = iconOnly),
border = style.borderStroke(),
) {
CompositionLocalProvider(
LocalTextStyle provides style.textStyle(),
LocalContentColor provides style.contentColor(),
) {
Row(
modifier = Modifier.padding(style.contentPadding(iconOnly = iconOnly)),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
iconResId?.let { resId ->
PrezelChipIcon(iconResId = resId, style = style)
}

if (hasText) {
if (hasIcon) {
Spacer(modifier = Modifier.width(style.iconTextSpacing()))
}
Text(text = text)
}
}
}
}
text = text,
iconResId = iconResId,
config = config,
)
}

@Composable
fun PrezelChip(
modifier: Modifier = Modifier,
text: String? = null,
@DrawableRes iconResId: Int? = null,
style: PrezelChipStyle = PrezelChipStyle(),
customColors: PrezelChipColors = LocalPrezelChipColors.current,
) {
CompositionLocalProvider(
LocalPrezelChipColors provides customColors,
) {
PrezelChip(
modifier = modifier,
text = text,
iconResId = iconResId,
style = style,
)
}
}

@Composable
private fun PrezelChipIcon(
@DrawableRes iconResId: Int,
style: PrezelChipStyle,
modifier: Modifier = Modifier,
) {
Icon(
painter = painterResource(id = iconResId),
contentDescription = null,
modifier = modifier.size(style.iconSize()),
)
private class PrezelChipTypeProvider : PreviewParameterProvider<PrezelChipType> {
override val values: Sequence<PrezelChipType> = PrezelChipType.entries.asSequence()
}

@BasicPreview
@Composable
private fun PrezelChipSizePreview() {
PreviewSection(
title = "Chip / Size",
description = "Chip의 크기를 조절합니다.",
) {
PrezelChipType.entries.forEach { type ->
PrezelChipSize.entries.forEach { size ->
PreviewValueRow(
name = type.name,
valueLabel = size.name,
) {
PrezelChip(
text = "Label",
iconResId = PrezelIcons.Blank,
style = PrezelChipStyle(type = type, size = size),
)
}
}
private fun PrezelChipPreview(
@PreviewParameter(PrezelChipTypeProvider::class) type: PrezelChipType,
) {
PreviewSection(title = "Chip - $type") {
Text(text = "Size", style = PrezelTheme.typography.title2Medium, color = PrezelTheme.colors.textLarge)
PreviewValueRow(name = "Regular") {
PrezelChip(
text = "Label",
iconResId = PrezelIcons.Blank,
type = type,
size = PrezelChipSize.REGULAR,
)
}
PreviewValueRow(name = "Small") {
PrezelChip(
text = "Label",
iconResId = PrezelIcons.Blank,
type = type,
size = PrezelChipSize.SMALL,
)
}
}
}

@BasicPreview
@Composable
private fun PrezelChipInteractionPreview() {
PreviewSection(
title = "Chip / Interaction",
description = "Chip의 상호작용 상태를 조절합니다.",
) {
PrezelChipType.entries.forEach { type ->
PrezelChipInteraction.entries.forEach { interaction ->
PreviewValueRow(
name = type.name,
valueLabel = interaction.name,
) {
PrezelChip(
text = "Label",
iconResId = PrezelIcons.Blank,
style = PrezelChipStyle(type = type, interaction = interaction),
)
}
}
Text(text = "Interaction", style = PrezelTheme.typography.title2Medium, color = PrezelTheme.colors.textLarge)
PreviewValueRow(name = "Default") {
PrezelChip(
text = "Label",
iconResId = PrezelIcons.Blank,
type = type,
interaction = PrezelChipInteraction.DEFAULT,
)
}
PreviewValueRow(name = "Active") {
PrezelChip(
text = "Label",
iconResId = PrezelIcons.Blank,
type = type,
interaction = PrezelChipInteraction.ACTIVE,
)
}
PreviewValueRow(name = "Disabled") {
PrezelChip(
text = "Label",
iconResId = PrezelIcons.Blank,
type = type,
interaction = PrezelChipInteraction.DISABLED,
)
}
}
}

@BasicPreview
@Composable
private fun PrezelChipFeedbackPreview() {
PreviewSection(
title = "Chip / Feedback",
description = "Chip의 피드백 상태를 조절합니다.",
) {
PrezelChipType.entries.forEach { type ->
PrezelChipFeedback.entries.forEach { feedback ->
PreviewValueRow(
name = type.name,
valueLabel = feedback.name,
) {
PrezelChip(
text = "Label",
iconResId = PrezelIcons.Blank,
style = PrezelChipStyle(type = type, feedback = feedback),
)
}
}
Text(text = "Feedback", style = PrezelTheme.typography.title2Medium, color = PrezelTheme.colors.textLarge)
PreviewValueRow(name = "Default") {
PrezelChip(
text = "Label",
iconResId = PrezelIcons.Blank,
type = type,
feedback = PrezelChipFeedback.DEFAULT,
)
}
PreviewValueRow(name = "Bad") {
PrezelChip(
text = "Label",
iconResId = PrezelIcons.Blank,
type = type,
feedback = PrezelChipFeedback.BAD,
)
}
}
}

@BasicPreview
@Composable
private fun PrezelChipCustomPreview() {
PreviewSection(
title = "Chip / Custom",
description = "사용자 정의된 색 지정이 가능합니다.",
) {
private fun PrezelChipCustomPreview(
@PreviewParameter(PrezelChipTypeProvider::class) type: PrezelChipType,
) {
PreviewSection(title = "Custom Chip - $type") {
PreviewRow {
PrezelChip(
text = "느려요",
text = "Label",
iconResId = PrezelIcons.Blank,
style = PrezelChipStyle(
type = PrezelChipType.FILLED,
size = PrezelChipSize.REGULAR,
interaction = PrezelChipInteraction.DISABLED,
feedback = PrezelChipFeedback.BAD,
),
customColors = PrezelChipColors(
containerColor = PrezelTheme.colors.feedbackWarningSmall,
contentColor = PrezelTheme.colors.feedbackWarningRegular,
config = PrezelChipDefaults.getDefault(
iconOnly = false,
type = type,
containerColor = PrezelTheme.colors.accentPurpleSmall,
iconColor = PrezelTheme.colors.accentPurpleRegular,
textColor = PrezelTheme.colors.accentPurpleRegular,
borderColor = PrezelTheme.colors.accentPurpleRegular,
),
)

PrezelChip(
text = "빨라요",
iconResId = null,
style = PrezelChipStyle(
type = PrezelChipType.OUTLINED,
size = PrezelChipSize.REGULAR,
interaction = PrezelChipInteraction.DEFAULT,
feedback = PrezelChipFeedback.DEFAULT,
),
customColors = PrezelChipColors(
containerColor = PrezelTheme.colors.feedbackBadSmall,
contentColor = PrezelTheme.colors.feedbackBadRegular,
text = "Label",
iconResId = PrezelIcons.Blank,
config = PrezelChipDefaults.getDefault(
iconOnly = false,
type = type,
containerColor = PrezelTheme.colors.accentTealSmall,
iconColor = PrezelTheme.colors.accentTealRegular,
textColor = PrezelTheme.colors.accentTealRegular,
borderColor = PrezelTheme.colors.accentTealRegular,
),
)

PrezelChip(
text = "적당해요",
iconResId = null,
style = PrezelChipStyle(
type = PrezelChipType.FILLED,
size = PrezelChipSize.SMALL,
interaction = PrezelChipInteraction.ACTIVE,
feedback = PrezelChipFeedback.DEFAULT,
),
customColors = PrezelChipColors(
containerColor = Color(0xFFDBFFF6),
contentColor = Color(0xFF00A37A),
text = "Label",
iconResId = PrezelIcons.Blank,
config = PrezelChipDefaults.getDefault(
iconOnly = false,
type = type,
containerColor = PrezelTheme.colors.accentMagentaSmall,
iconColor = PrezelTheme.colors.accentMagentaRegular,
textColor = PrezelTheme.colors.accentMagentaRegular,
borderColor = PrezelTheme.colors.accentMagentaRegular,
),
)
}
Expand Down
Loading