Skip to content

Commit

Permalink
ADD disabled state to TemplateButton
Browse files Browse the repository at this point in the history
  • Loading branch information
ninovanhooff committed Dec 13, 2024
1 parent b708aa7 commit 17c00cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import nl.q42.template.ui.theme.AppTheme
import nl.q42.template.ui.theme.PreviewLightDark

@Composable
fun TemplateButton(text: String, onClick: () -> Unit) {
fun TemplateButton(text: String, enabled: Boolean = true, onClick: () -> Unit) {
Button(
onClick = onClick,
enabled = enabled,
colors = ButtonDefaults.buttonColors(
containerColor = AppTheme.colors.accent,
contentColor = AppTheme.colors.buttonText
contentColor = AppTheme.colors.buttonText,
disabledContentColor = AppTheme.colors.buttonText.copy(alpha = 0.5f),
disabledContainerColor = AppTheme.colors.accent.copy(alpha = 0.5f)
)
) {
Text(
Expand All @@ -28,6 +31,6 @@ fun TemplateButton(text: String, onClick: () -> Unit) {
@PreviewLightDark
private fun TemplateButtonPreview() {
AppTheme {
TemplateButton("Button", {})
TemplateButton("Button",) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ internal fun HomeContent(
horizontalAlignment = CenterHorizontally,
verticalArrangement = spacedBy(Dimens.buttonSpacingVertical)
) {
TemplateButton("Refresh", onLoadClicked)
TemplateButton("Refresh", onClick = onLoadClicked)

TemplateButton("Open second screen", onOpenSecondScreenClicked)
TemplateButton("Open second screen", onClick = onOpenSecondScreenClicked)

TemplateButton("Open Onboarding", onOpenOnboardingClicked)
TemplateButton("Open Onboarding", onClick = onOpenOnboardingClicked)

TemplateButton("Disabled button", enabled = false) {}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package nl.q42.template.home.second.ui
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -44,6 +42,6 @@ fun HomeSecondScreen(

Text(viewState.title, style = AppTheme.typography.h1, color = AppTheme.colors.textPrimary)

TemplateButton("Close", viewModel::onBackClicked)
TemplateButton("Close", onClick = viewModel::onBackClicked)
}
}

0 comments on commit 17c00cf

Please sign in to comment.