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
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ fun PrezelButton(
val hasIcon = icon != null
require(hasText || hasIcon) { "Button은 text 또는 icon 중 하나는 반드시 필요합니다." }
val (buttonType, buttonHierarchy, buttonSize, isRounded) = style
val isIconOnly = !hasText

Surface(
onClick = onClick,
modifier = modifier.semantics { role = Role.Button },
enabled = enabled,
shape = prezelButtonShape(isRounded = isRounded),
shape = prezelButtonShape(isIconOnly = isIconOnly, isRounded = isRounded, buttonSize = buttonSize),
color = prezelButtonContainerColor(type = buttonType, hierarchy = buttonHierarchy, enabled = enabled),
border = prezelButtonBorderStroke(type = buttonType, hierarchy = buttonHierarchy, enabled = enabled),
) {
Expand All @@ -48,11 +49,13 @@ fun PrezelButton(
LocalContentColor provides prezelButtonContentColor(type = buttonType, hierarchy = buttonHierarchy, enabled = enabled),
) {
Row(
modifier = Modifier.padding(prezelButtonContentPadding(size = buttonSize, onlyIcon = hasIcon && !hasText)),
modifier = Modifier.padding(prezelButtonContentPadding(size = buttonSize, isOnlyIcon = isIconOnly)),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
PrezelButtonIcon(icon = icon, size = buttonSize)
icon?.let { source ->
PrezelButtonIcon(icon = source, size = buttonSize)
}

if (!hasText) return@Row
if (hasIcon) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ data class PrezelButtonStyle(

@Composable
internal fun PrezelButtonIcon(
icon: IconSource?,
icon: IconSource,
size: PrezelButtonSize,
modifier: Modifier = Modifier,
) {
if (icon == null) return
Icon(
painter = icon.painter(),
contentDescription = icon.contentDescription(),
Expand All @@ -67,9 +66,21 @@ internal fun PrezelButtonIcon(

@Composable
internal fun prezelButtonShape(
isIconOnly: Boolean,
isRounded: Boolean,
buttonSize: PrezelButtonSize,
shapes: PrezelShapes = PrezelTheme.shapes,
): Shape = if (isRounded) shapes.V1000 else shapes.V4
): Shape =
when (isRounded) {
true -> shapes.V1000
false -> {
when (buttonSize) {
PrezelButtonSize.REGULAR -> shapes.V8
PrezelButtonSize.SMALL -> if (isIconOnly) shapes.V6 else shapes.V4
PrezelButtonSize.XSMALL -> shapes.V4
}
}
}

@Composable
internal fun prezelButtonBorderStroke(
Expand Down Expand Up @@ -138,10 +149,10 @@ internal fun prezelButtonContentColor(
@Composable
internal fun prezelButtonContentPadding(
size: PrezelButtonSize,
onlyIcon: Boolean = false,
isOnlyIcon: Boolean,
spacing: PrezelSpacing = PrezelTheme.spacing,
): PaddingValues {
if (onlyIcon) return prezelIconButtonContentPadding(size)
if (isOnlyIcon) return prezelIconButtonContentPadding(size)

val horizontal = when (size) {
PrezelButtonSize.XSMALL -> spacing.V10
Expand All @@ -163,8 +174,10 @@ private fun prezelIconButtonContentPadding(
size: PrezelButtonSize,
spacing: PrezelSpacing = PrezelTheme.spacing,
): PaddingValues =
when (size) {
PrezelButtonSize.XSMALL -> spacing.V8
PrezelButtonSize.SMALL -> spacing.V10
PrezelButtonSize.REGULAR -> spacing.V14
}.let { spacing -> PaddingValues(all = spacing) }
PaddingValues(
when (size) {
PrezelButtonSize.XSMALL -> spacing.V8
PrezelButtonSize.SMALL -> spacing.V10
PrezelButtonSize.REGULAR -> spacing.V14
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import androidx.compose.ui.tooling.preview.Preview
showBackground = true,
uiMode = Configuration.UI_MODE_NIGHT_NO,
)
@Preview(
name = "DarkTheme",
showBackground = true,
uiMode = Configuration.UI_MODE_NIGHT_YES,
)
// @Preview(
// name = "DarkTheme",
// showBackground = true,
// uiMode = Configuration.UI_MODE_NIGHT_YES,
// )
annotation class ThemePreview