Change buttons to allow custom color

This commit is contained in:
Wolf-Martell Montwé 2023-06-08 18:38:16 +02:00
parent 64727067c0
commit d0407ffb20
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
4 changed files with 60 additions and 6 deletions

View file

@ -1,9 +1,11 @@
package app.k9mail.ui.catalog.ui.atom.items
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import app.k9mail.core.ui.compose.designsystem.atom.button.Button
import app.k9mail.core.ui.compose.designsystem.atom.button.ButtonOutlined
import app.k9mail.core.ui.compose.designsystem.atom.button.ButtonText
@ -11,34 +13,38 @@ import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.ui.catalog.ui.common.list.itemDefaultPadding
import app.k9mail.ui.catalog.ui.common.list.sectionHeaderItem
@OptIn(ExperimentalLayoutApi::class)
fun LazyGridScope.buttonItems() {
sectionHeaderItem(text = "Buttons - Filled")
item {
Row(
FlowRow(
horizontalArrangement = Arrangement.spacedBy(MainTheme.spacings.default),
modifier = Modifier.itemDefaultPadding(),
) {
Button(text = "Enabled", onClick = { })
Button(text = "Colored", onClick = { }, color = Color.Magenta)
Button(text = "Disabled", onClick = { }, enabled = false)
}
}
sectionHeaderItem(text = "Buttons - Outlined")
item {
Row(
FlowRow(
horizontalArrangement = Arrangement.spacedBy(MainTheme.spacings.default),
modifier = Modifier.itemDefaultPadding(),
) {
ButtonOutlined(text = "Enabled", onClick = { })
ButtonOutlined(text = "Colored", onClick = { }, color = Color.Magenta)
ButtonOutlined(text = "Disabled", onClick = { }, enabled = false)
}
}
sectionHeaderItem(text = "Buttons - Text only")
item {
Row(
FlowRow(
horizontalArrangement = Arrangement.spacedBy(MainTheme.spacings.default),
modifier = Modifier.itemDefaultPadding(),
) {
ButtonText(text = "Enabled", onClick = { })
ButtonText(text = "Colored", onClick = { }, color = Color.Magenta)
ButtonText(text = "Disabled", onClick = { }, enabled = false)
}
}

View file

@ -4,8 +4,10 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material.ButtonDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.designsystem.atom.text.TextButton
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
import androidx.compose.material.Button as MaterialButton
@ -15,13 +17,16 @@ fun Button(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
color: Color? = null,
contentPadding: PaddingValues = buttonContentPadding(),
) {
MaterialButton(
onClick = onClick,
modifier = modifier,
enabled = enabled,
colors = ButtonDefaults.buttonColors(),
colors = ButtonDefaults.buttonColors(
backgroundColor = color ?: MainTheme.colors.primary,
),
contentPadding = contentPadding,
) {
TextButton(text = text)
@ -39,6 +44,18 @@ internal fun ButtonPreview() {
}
}
@Preview(showBackground = true)
@Composable
internal fun ButtonColoredPreview() {
PreviewWithThemes {
Button(
text = "ButtonColored",
onClick = {},
color = Color.Magenta,
)
}
}
@Preview(showBackground = true)
@Composable
internal fun ButtonDisabledPreview() {

View file

@ -19,6 +19,7 @@ fun ButtonOutlined(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
color: Color? = null,
contentPadding: PaddingValues = buttonContentPadding(),
) {
MaterialOutlinedButton(
@ -26,6 +27,7 @@ fun ButtonOutlined(
modifier = modifier,
enabled = enabled,
colors = ButtonDefaults.outlinedButtonColors(
contentColor = color ?: MainTheme.colors.primary,
backgroundColor = Color.Transparent,
),
border = BorderStroke(
@ -55,6 +57,18 @@ internal fun ButtonOutlinedPreview() {
}
}
@Preview(showBackground = true)
@Composable
internal fun ButtonOutlinedColoredPreview() {
PreviewWithThemes {
ButtonOutlined(
text = "ButtonOutlinedColored",
onClick = {},
color = Color.Magenta,
)
}
}
@Preview(showBackground = true)
@Composable
internal fun ButtonOutlinedDisabledPreview() {

View file

@ -4,8 +4,10 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material.ButtonDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import app.k9mail.core.ui.compose.designsystem.atom.text.TextButton
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.core.ui.compose.theme.PreviewWithThemes
import androidx.compose.material.TextButton as MaterialTextButton
@ -15,13 +17,16 @@ fun ButtonText(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
color: Color? = null,
contentPadding: PaddingValues = buttonContentPadding(),
) {
MaterialTextButton(
onClick = onClick,
modifier = modifier,
enabled = enabled,
colors = ButtonDefaults.textButtonColors(),
colors = ButtonDefaults.textButtonColors(
contentColor = color ?: MainTheme.colors.primary,
),
contentPadding = contentPadding,
) {
TextButton(text = text)
@ -39,6 +44,18 @@ internal fun ButtonTextPreview() {
}
}
@Preview(showBackground = true)
@Composable
internal fun ButtonTextColoredPreview() {
PreviewWithThemes {
ButtonText(
text = "ButtonTextColored",
onClick = {},
color = Color.Magenta,
)
}
}
@Preview(showBackground = true)
@Composable
internal fun ButtonTextDisabledPreview() {