Skip to content

Commit

Permalink
Improve Preference & Preference Button customizability
Browse files Browse the repository at this point in the history
  • Loading branch information
yasanglass committed Mar 17, 2024
1 parent f3b35f2 commit 410bd11
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ public fun Preference(
title: @Composable () -> Unit,
modifier: Modifier = Modifier,
description: @Composable (() -> Unit)? = null,
backgroundColor: Color = ConcreteTheme.colors.layer.foreground,
paddingVertical: Dp = 1.grid,
paddingHorizontal: Dp = 2.grid,
start: @Composable (() -> Unit)? = null,
end: @Composable (() -> Unit)? = null,
) {
Row(
modifier = modifier
.background(color = ConcreteTheme.colors.layer.foreground)
.background(color = backgroundColor)
.fillMaxWidth()
.padding(
horizontal = paddingHorizontal,
Expand All @@ -52,6 +53,7 @@ public fun Preference(
title: @Composable () -> Unit,
modifier: Modifier = Modifier,
description: @Composable (() -> Unit)? = null,
backgroundColor: Color = ConcreteTheme.colors.layer.foreground,
applyPaddings: Boolean = true,
start: @Composable (() -> Unit)? = null,
end: @Composable (() -> Unit)? = null,
Expand All @@ -67,6 +69,7 @@ public fun Preference(
paddingHorizontal = paddingHorizontal,
start = start,
end = end,
backgroundColor = backgroundColor,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.sp
import glass.yasan.concrete.component.Icon
import glass.yasan.concrete.component.SpacerHorizontal
import glass.yasan.concrete.component.Text
import glass.yasan.concrete.theme.ConcreteTheme
import glass.yasan.spine.compose.foundation.grid
import glass.yasan.spine.compose.util.adaptiveContentColor

@Composable
public fun PreferenceButton(
Expand Down Expand Up @@ -70,3 +72,55 @@ public fun PreferenceButton(
applyPaddings = false,
)
}

@Composable
public fun PreferenceButton(
title: String,
onClick: () -> Unit,
backgroundColor: Color,
modifier: Modifier = Modifier,
contentColor: Color = adaptiveContentColor(backgroundColor = backgroundColor),
startIcon: ImageVector? = null,
endIcon: ImageVector? = null,
enabled: Boolean = true,
uppercaseTitle: Boolean = false,
) {
Preference(
title = {
Text(
text = if (uppercaseTitle) title.uppercase() else title,
color = contentColor,
fontSize = 16.sp,
)
},
modifier = modifier
.clickable(
enabled = enabled,
onClick = onClick,
),
start = {
if (startIcon != null) {
Icon(
imageVector = startIcon,
contentDescription = null,
modifier = Modifier.padding(2.grid),
)
} else {
SpacerHorizontal(width = 2.grid)
}
},
end = {
if (endIcon != null) {
Icon(
imageVector = endIcon,
contentDescription = null,
modifier = Modifier.padding(2.grid),
)
} else {
SpacerHorizontal(width = 2.grid)
}
},
applyPaddings = false,
backgroundColor = backgroundColor,
)
}

0 comments on commit 410bd11

Please sign in to comment.