Fixed edit remotes dialog buttons

This commit is contained in:
Abdelilah El Aissaoui 2022-10-23 16:15:30 +02:00
parent a0383b2781
commit 302376a23e
3 changed files with 25 additions and 20 deletions

View File

@ -11,7 +11,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.jetpackduba.gitnuro.extensions.backgroundIf
import com.jetpackduba.gitnuro.extensions.handMouseClickable
import com.jetpackduba.gitnuro.extensions.handOnHover
@Composable
@ -20,16 +22,22 @@ fun PrimaryButton(
text: String,
enabled: Boolean = true,
backgroundColor: Color = MaterialTheme.colors.primary,
backgroundDisabled: Color = MaterialTheme.colors.primary.copy(0.5f),
textColor: Color = MaterialTheme.colors.onPrimary,
disabledTextColor: Color = MaterialTheme.colors.onBackground,
disabledTextColor: Color = MaterialTheme.colors.onPrimary.copy(alpha = 0.5f),
onClick: () -> Unit,
) {
Box(
modifier = modifier
.clip(RoundedCornerShape(4.dp))
.background(backgroundColor)
.handMouseClickable {
.backgroundIf(enabled, backgroundColor, backgroundDisabled)
.run {
if(enabled) {
handMouseClickable {
onClick()
}
} else
handOnHover()
},
) {
Text(

View File

@ -105,7 +105,7 @@ fun AuthorDialog(
text = "Cancel",
modifier = Modifier.padding(end = 8.dp),
onClick = onClose,
backgroundColor = Color.Transparent
backgroundColor = Color.Transparent,
)
PrimaryButton(
onClick = {

View File

@ -10,6 +10,7 @@ import androidx.compose.material.icons.filled.Clear
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.jetpackduba.gitnuro.extensions.handMouseClickable
@ -280,15 +281,15 @@ fun EditRemotesDialog(
Row(
modifier = Modifier
.padding(top = 16.dp)
.align(Alignment.End)
.align(Alignment.End),
verticalAlignment = Alignment.CenterVertically,
) {
Spacer(modifier = Modifier.weight(1f))
if (!selectedRemote.isNew) {
TextButton(
PrimaryButton(
text = "Discard changes",
modifier = Modifier.padding(end = 8.dp),
enabled = remoteChanged,
colors = textButtonColors(),
onClick = {
remotesEditorData = remotesEditorData.copy(
selectedRemote = selectedRemote.copy(
@ -298,18 +299,14 @@ fun EditRemotesDialog(
)
remoteChanged = false
}
) {
Text(
"Discard changes",
style = MaterialTheme.typography.body1,
color = if (remoteChanged)
MaterialTheme.colors.primaryVariant
else
MaterialTheme.colors.onBackground,
},
backgroundColor = Color.Transparent,
backgroundDisabled = Color.Transparent,
enabled = remoteChanged,
textColor = MaterialTheme.colors.onBackground,
disabledTextColor = MaterialTheme.colors.onBackground.copy(alpha = 0.5f),
)
}
}
val text = if (selectedRemote.isNew)
"Add new remote"