mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Add: ActionButton composable
This commit is contained in:
parent
57a90d6df4
commit
57378cd71b
@ -23,11 +23,48 @@ import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.machiav3lli.fdroid.entity.ActionState
|
||||
import com.machiav3lli.fdroid.entity.ComponentState
|
||||
|
||||
@Composable
|
||||
fun ActionButton(
|
||||
modifier: Modifier = Modifier,
|
||||
text: String,
|
||||
positive: Boolean = true,
|
||||
icon: Painter? = null,
|
||||
enabled: Boolean = true,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
ElevatedButton(
|
||||
modifier = modifier,
|
||||
colors = ButtonDefaults.elevatedButtonColors(
|
||||
contentColor = when {
|
||||
positive -> MaterialTheme.colorScheme.onPrimaryContainer
|
||||
else -> MaterialTheme.colorScheme.onTertiaryContainer
|
||||
},
|
||||
containerColor = when {
|
||||
positive -> MaterialTheme.colorScheme.primaryContainer
|
||||
else -> MaterialTheme.colorScheme.tertiaryContainer
|
||||
}
|
||||
),
|
||||
enabled = enabled,
|
||||
onClick = onClick
|
||||
) {
|
||||
Row(
|
||||
Modifier.padding(ButtonDefaults.ContentPadding),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if (icon != null) Icon(painter = icon, contentDescription = null)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(text = text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
@Composable
|
||||
fun MainActionButton(
|
||||
@ -43,12 +80,12 @@ fun MainActionButton(
|
||||
},
|
||||
colors = ButtonDefaults.elevatedButtonColors(
|
||||
containerColor = when (actionState) {
|
||||
is ActionState.Cancel -> MaterialTheme.colorScheme.secondaryContainer
|
||||
is ActionState.Cancel -> MaterialTheme.colorScheme.tertiaryContainer
|
||||
is ActionState.NoAction -> MaterialTheme.colorScheme.inverseSurface
|
||||
else -> MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp)
|
||||
},
|
||||
contentColor = when (actionState) {
|
||||
is ActionState.Cancel -> MaterialTheme.colorScheme.secondary
|
||||
is ActionState.Cancel -> MaterialTheme.colorScheme.onTertiaryContainer
|
||||
is ActionState.NoAction -> MaterialTheme.colorScheme.inverseOnSurface
|
||||
else -> MaterialTheme.colorScheme.primary
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user