Skip to content

Instantly share code, notes, and snippets.

View ehsunshine's full-sized avatar
🧙‍♂️

Ehsan Mehranvari ehsunshine

🧙‍♂️
View GitHub Profile
@Composable
fun MyVeryCustomButton(
modifier: Modifier = Modifier,
enabled: Boolean = true,
colors: MyVeryCustomButtonColors = MyVeryCustomButtonDefaults.colors(),
onClick: (() -> Unit)?,
) {
val color by colors.backgroundColor(enabled)
val selectableModifier =
if (onClick != null) {
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<xyz.ehsun.tiaraelmcompose.components.TiaraElmButtonCompat
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
@Composable
fun TiaraElmButton(
modifier: Modifier = Modifier,
text: String,
buttonType: ButtonType = ButtonType.Primary,
buttonStyle: ButtonStyle = ButtonStyle.Brand,
enabled: Boolean = true,
onClick: () -> Unit,
) {
Button(
@Composable
private fun ButtonContent(
text: String,
buttonType: ButtonType
) {
Text(
modifier = Modifier.padding(8.dp),
text = text,
style = TiaraElmTheme.typography.mare.let {
if (buttonType == ButtonType.Secondary) it.emphasise else it
@Composable
private fun buttonColors(
buttonType: ButtonType,
buttonStyle: ButtonStyle
) = when (buttonType) {
ButtonType.Primary -> ButtonDefaults.buttonColors(
backgroundColor = styleColor(buttonStyle),
contentColor = TiaraElmTheme.colors.foreground.primary,
disabledBackgroundColor = styleColor(buttonStyle).copy(alpha = .5f),
disabledContentColor = TiaraElmTheme.colors.foreground.secondary,
@Composable
fun TiaraElmButton(
modifier: Modifier = Modifier,
text: String,
buttonType: ButtonType = ButtonType.Primary,
buttonStyle: ButtonStyle = ButtonStyle.Brand,
enabled: Boolean = true,
onClick: () -> Unit,
) {
// ....
@Composable
fun TiaraElmTheme(
colors: TiaraElmColors = TiaraElmTheme.colors,
typography: TiaraElmTypography = TiaraElmTheme.typography,
content: @Composable () -> Unit
) {
CompositionLocalProvider(
LocalColors provides colors,
LocalTypography provides typography,
) {
object TiaraElmTheme {
// Retrieves the current colors
val colors: TiaraElmColors
@Composable
@ReadOnlyComposable
get() = LocalColors.current
// Retrieves the current typography
val typography: TiaraElmTypography
val LocalTypography = staticCompositionLocalOf { tiaraElmTypography }
val LocalColors = staticCompositionLocalOf { tiaraElmDefaultLightColors }
val robotoFontFamily = FontFamily(
Font(R.font.roboto_light, FontWeight.W100),
Font(R.font.roboto_medium, FontWeight.W400),
)
val tiaraElmTypography =
TiaraElmTypography(
maria = TextStyle(
fontFamily = robotoFontFamily,
fontWeight = FontWeight.W400,