Skip to content

Commit

Permalink
Merge pull request #5242 from wikimedia/compose-states
Browse files Browse the repository at this point in the history
Compose state
  • Loading branch information
cooltey authored Jan 17, 2025
2 parents 5e558b8 + 723bb17 commit 68ae1d6
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package org.wikipedia.compose.components

import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.wikipedia.compose.ComposeColors
import org.wikipedia.compose.theme.BaseTheme
import org.wikipedia.compose.theme.WikipediaTheme

@Composable
Expand Down Expand Up @@ -115,27 +123,57 @@ fun ThemeColorCircularButton(
onClick: () -> Unit,
text: String = "Aa",
modifier: Modifier = Modifier,
backgroundColor: Color,
borderColor: Color
size: Dp = 40.dp,
defaultBackgroundColor: Color = WikipediaTheme.colors.paperColor,
selectedBackgroundColor: Color = WikipediaTheme.colors.backgroundColor,
borderColor: Color = WikipediaTheme.colors.progressiveColor,
textColor: Color = WikipediaTheme.colors.primaryColor,
rippleColor: Color = Color.Transparent,
isSelected: Boolean = false
) {
Button(
onClick = onClick,
modifier = modifier.border(
width = 2.dp,
color = borderColor,
shape = CircleShape
).size(40.dp),
modifier = modifier
.border(
width = 2.dp,
color = if (isSelected) borderColor else Color.Transparent,
shape = CircleShape
)
.size(size),
colors = ButtonDefaults.buttonColors(
containerColor = backgroundColor
containerColor = if (isSelected) defaultBackgroundColor else selectedBackgroundColor,
contentColor = rippleColor
),
contentPadding = PaddingValues(0.dp)
) {
Text(
text = text,
style = WikipediaTheme.typography.h3.copy(
color = WikipediaTheme.colors.primaryColor,
color = textColor,
letterSpacing = 0.sp
)
)
}
}

@Preview(showSystemUi = true)
@Composable
private fun SepiaThemeColorButton() {
BaseTheme {
Column(
modifier = Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally
) {
ThemeColorCircularButton(
isSelected = true,
defaultBackgroundColor = ComposeColors.Beige300,
selectedBackgroundColor = ComposeColors.Beige300,
rippleColor = ComposeColors.Beige300,
textColor = ComposeColors.Gray700,
onClick = {}
)
}
}
}

0 comments on commit 68ae1d6

Please sign in to comment.