🛠️ Add secondary action to Dialog

* Added optional secondary action to dialog (e.g. "Edit")
This commit is contained in:
Acclorite 2025-04-07 22:16:38 +03:00
parent 0791223bc6
commit d707aeaa23

View file

@ -61,6 +61,8 @@ fun Dialog(
actionEnabled: Boolean?, actionEnabled: Boolean?,
onDismiss: () -> Unit, onDismiss: () -> Unit,
onAction: () -> Unit, onAction: () -> Unit,
secondaryAction: String? = null,
onSecondaryAction: (() -> Unit)? = null,
withContent: Boolean, withContent: Boolean,
items: (LazyListScope.() -> Unit) = {} items: (LazyListScope.() -> Unit) = {}
) { ) {
@ -150,41 +152,66 @@ fun Dialog(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 24.dp), .padding(horizontal = 24.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp, Alignment.End) verticalAlignment = Alignment.CenterVertically
) { ) {
TextButton( if (secondaryAction != null && onSecondaryAction != null) {
onClick = { TextButton(
if (disableOnClick) { onClick = {
actionClicked = true if (disableOnClick) {
} actionClicked = true
onDismiss() }
}, onSecondaryAction()
enabled = !actionClicked },
) { enabled = !actionClicked
StyledText( ) {
text = stringResource(id = R.string.cancel), StyledText(
style = MaterialTheme.typography.labelLarge.copy( text = secondaryAction,
color = MaterialTheme.colorScheme.primary style = MaterialTheme.typography.labelLarge.copy(
color = MaterialTheme.colorScheme.primary
)
) )
) }
} }
TextButton( Row(
onClick = { modifier = Modifier.weight(1f),
if (disableOnClick) { horizontalArrangement = Arrangement.spacedBy(4.dp, Alignment.End),
actionClicked = true verticalAlignment = Alignment.CenterVertically
}
onAction()
},
enabled = actionEnabled == true && !actionClicked
) { ) {
StyledText( TextButton(
text = stringResource(id = R.string.ok), onClick = {
style = MaterialTheme.typography.labelLarge.copy( if (disableOnClick) {
color = if (actionEnabled == true) MaterialTheme.colorScheme.primary actionClicked = true
else MaterialTheme.colorScheme.primary.copy(0.5f) }
onDismiss()
},
enabled = !actionClicked
) {
StyledText(
text = stringResource(id = R.string.cancel),
style = MaterialTheme.typography.labelLarge.copy(
color = MaterialTheme.colorScheme.primary
)
) )
) }
TextButton(
onClick = {
if (disableOnClick) {
actionClicked = true
}
onAction()
},
enabled = actionEnabled == true && !actionClicked
) {
StyledText(
text = stringResource(id = R.string.ok),
style = MaterialTheme.typography.labelLarge.copy(
color = if (actionEnabled == true) MaterialTheme.colorScheme.primary
else MaterialTheme.colorScheme.primary.copy(0.5f)
)
)
}
} }
} }
} }